diff options
author | Gonzalo <gonzalo@wyeworks.com> | 2012-10-13 07:35:01 +0400 |
---|---|---|
committer | Gonzalo <gonzalo@wyeworks.com> | 2012-10-15 01:32:53 +0400 |
commit | e1756b5b3f9fa5d22c56fe8bb41a2a677a53bcdd (patch) | |
tree | e6c8ce592ea6dd8332bbeb35e9c34ef63b206845 | |
parent | 78953fe2bf7678409b1c59d051b1f9d354db659e (diff) |
Privatize non-action controller methods
-rw-r--r-- | app/controllers/admins_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/aspects_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/blocks_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/comments_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/contacts_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/invitation_codes_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/likes_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/people_controller.rb | 18 | ||||
-rw-r--r-- | app/controllers/profiles_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/publics_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/registrations_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/services_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/share_visibilities_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/status_messages_controller.rb | 22 | ||||
-rw-r--r-- | app/controllers/tags_controller.rb | 33 | ||||
-rw-r--r-- | spec/controllers/people_controller_spec.rb | 16 | ||||
-rw-r--r-- | spec/controllers/status_messages_controller_spec.rb | 12 | ||||
-rw-r--r-- | spec/controllers/tags_controller_spec.rb | 4 |
19 files changed, 79 insertions, 72 deletions
diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index 6d1340d09..36a5ef2f8 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -83,6 +83,7 @@ class AdminsController < ApplicationController end private + def percent_change(today, yesterday) sprintf( "%0.02f", ((today-yesterday) / yesterday.to_f)*100).to_f end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b6aaf97f8..a772803bb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,6 +22,8 @@ class ApplicationController < ActionController::Base :tags, :open_publisher + private + def ensure_http_referer_is_set request.env['HTTP_REFERER'] ||= '/' end @@ -129,8 +131,6 @@ class ApplicationController < ActionController::Base params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now + 1 end - private - def current_user_redirect_path current_user.getting_started? ? getting_started_path : root_path end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 1ef5cc029..3a988b3e2 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -34,16 +34,6 @@ class AspectsController < ApplicationController end end - #person_id, user, @aspect - def connect_person_to_aspect(aspecting_person_id) - @person = Person.find(aspecting_person_id) - if @contact = current_user.contact_for(@person) - @contact.aspects << @aspect - else - @contact = current_user.share_with(@person, @aspect) - end - end - def new @aspect = Aspect.new @person_id = params[:person_id] @@ -120,4 +110,15 @@ class AspectsController < ApplicationController end @aspect.save end + + private + + def connect_person_to_aspect(aspecting_person_id) + @person = Person.find(aspecting_person_id) + if @contact = current_user.contact_for(@person) + @contact.aspects << @aspect + else + @contact = current_user.share_with(@person, @aspect) + end + end end diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb index 7f7fa5891..237ef4d97 100644 --- a/app/controllers/blocks_controller.rb +++ b/app/controllers/blocks_controller.rb @@ -32,7 +32,7 @@ class BlocksController < ApplicationController end end - protected + private def disconnect_if_contact(person) if contact = current_user.contact_for(person) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index d8f43fc3d..9f4786cf8 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -61,7 +61,7 @@ class CommentsController < ApplicationController end end - protected + private def find_post if user_signed_in? diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index a3cb40f9a..f0fdc1d32 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -33,7 +33,7 @@ class ContactsController < ApplicationController @people = Person.community_spotlight end - protected + private def set_up_contacts @contacts = case params[:set] @@ -51,5 +51,4 @@ class ContactsController < ApplicationController end @contacts = @contacts.for_a_stream.paginate(:page => params[:page], :per_page => 25) end - end diff --git a/app/controllers/invitation_codes_controller.rb b/app/controllers/invitation_codes_controller.rb index e79b4f868..d267db12f 100644 --- a/app/controllers/invitation_codes_controller.rb +++ b/app/controllers/invitation_codes_controller.rb @@ -10,6 +10,8 @@ class InvitationCodesController < ApplicationController redirect_to new_user_registration_path(:invite => {:token => params[:id]}) end + private + def ensure_valid_invite_code InvitationCode.find_by_token!(params[:id]) end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 1d99009f5..7be46c166 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -46,7 +46,7 @@ class LikesController < ApplicationController end end - protected + private def target @target ||= if params[:post_id] diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 750799a14..7bf708867 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -162,14 +162,6 @@ class PeopleController < ApplicationController end end - def diaspora_id?(query) - !query.try(:match, /^(\w)*@([a-zA-Z0-9]|[-]|[.]|[:])*$/).nil? - end - - def search_query - @search_query ||= params[:q] || params[:term] || '' - end - def redirect_if_tag_search if search_query.starts_with?('#') if search_query.length > 1 @@ -181,7 +173,15 @@ class PeopleController < ApplicationController end end - protected + private + + def search_query + @search_query ||= params[:q] || params[:term] || '' + end + + def diaspora_id?(query) + !query.try(:match, /^(\w)*@([a-zA-Z0-9]|[-]|[.]|[:])*$/).nil? + end def remote_profile_with_no_user_session? @person.try(:remote?) && !user_signed_in? diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 3f8211f0c..342158afa 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -64,7 +64,7 @@ class ProfilesController < ApplicationController end end - protected + private def munge_tag_string unless @profile_attrs[:tag_string].nil? || @profile_attrs[:tag_string] == I18n.t('profiles.edit.your_tags_placeholder') diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 4ce1e044f..31942988e 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -74,7 +74,6 @@ class PublicsController < ApplicationController render :nothing => true, :status => 202 end - private def check_for_xml diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 2823b4659..7b62e8ef1 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -30,6 +30,7 @@ class RegistrationsController < Devise::RegistrationsController end private + def check_valid_invite! return true if AppConfig.settings.enable_registrations? #this sucks return true if invite && invite.can_be_used? diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 84c097b12..6257e0455 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -63,6 +63,5 @@ class ServicesController < ApplicationController @service.destroy flash[:notice] = I18n.t 'services.destroy.success' redirect_to services_url - end - + end end diff --git a/app/controllers/share_visibilities_controller.rb b/app/controllers/share_visibilities_controller.rb index 2f4e46729..005b0288a 100644 --- a/app/controllers/share_visibilities_controller.rb +++ b/app/controllers/share_visibilities_controller.rb @@ -15,7 +15,7 @@ class ShareVisibilitiesController < ApplicationController render :nothing => true, :status => 200 end - protected + private def accessible_post @post ||= params[:shareable_type].constantize.where(:id => params[:post_id]).select("id, guid, author_id, created_at").first diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 33ff1a2ce..bef5341e8 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -12,16 +12,6 @@ class StatusMessagesController < ApplicationController :json layout :bookmarklet_layout, :only => :bookmarklet - - # Define bookmarklet layout depending on whether - # user is in mobile or desktop mode - def bookmarklet_layout - if request.format == :mobile - 'application' - else - 'blank' - end - end # Called when a user clicks "Mention" on a profile page # @param person_id [Integer] The id of the person to be mentioned @@ -88,6 +78,8 @@ class StatusMessagesController < ApplicationController end end + private + def destination_aspect_ids if params[:status_message][:public] || params[:status_message][:aspect_ids].first == "all_aspects" current_user.aspect_ids @@ -116,4 +108,14 @@ class StatusMessagesController < ApplicationController def remove_getting_started current_user.disable_getting_started end + + # Define bookmarklet layout depending on whether + # user is in mobile or desktop mode + def bookmarklet_layout + if request.format == :mobile + 'application' + else + 'blank' + end + end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e60974a88..45a8ee954 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -39,23 +39,26 @@ class TagsController < ApplicationController end end - def tag_followed? - TagFollowing.user_is_following?(current_user, params[:name]) - end + private - def prep_tags_for_javascript - @tags.map! do |obj| - { :name => ("#"+obj.name), - :value => ("#"+obj.name), - :url => tag_path(obj.name) - } - end + def tag_followed? + TagFollowing.user_is_following?(current_user, params[:name]) + end - @tags << { - :name => ('#' + params[:q]), - :value => ("#" + params[:q]), - :url => tag_path(params[:q].downcase) + def prep_tags_for_javascript + @tags.map! do |tag| + { + :name => ("#" + tag.name), + :value => ("#" + tag.name), + :url => tag_path(tag.name) } - @tags.uniq! + end + + @tags << { + :name => ('#' + params[:q]), + :value => ("#" + params[:q]), + :url => tag_path(params[:q].downcase) + } + @tags.uniq! end end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 5e85421a3..fb311c9b1 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -413,35 +413,35 @@ describe PeopleController do describe '#diaspora_id?' do it 'returns true for pods on urls' do - @controller.diaspora_id?("ilya_123@pod.geraspora.de").should be_true + @controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de").should be_true end it 'returns true for pods on urls with port' do - @controller.diaspora_id?("ilya_123@pod.geraspora.de:12314").should be_true + @controller.send(:diaspora_id?, "ilya_123@pod.geraspora.de:12314").should be_true end it 'returns true for pods on localhost' do - @controller.diaspora_id?("ilya_123@localhost").should be_true + @controller.send(:diaspora_id?, "ilya_123@localhost").should be_true end it 'returns true for pods on localhost and port' do - @controller.diaspora_id?("ilya_123@localhost:1234").should be_true + @controller.send(:diaspora_id?, "ilya_123@localhost:1234").should be_true end it 'returns true for pods on ip' do - @controller.diaspora_id?("ilya_123@1.1.1.1").should be_true + @controller.send(:diaspora_id?, "ilya_123@1.1.1.1").should be_true end it 'returns true for pods on ip and port' do - @controller.diaspora_id?("ilya_123@1.2.3.4:1234").should be_true + @controller.send(:diaspora_id?, "ilya_123@1.2.3.4:1234").should be_true end it 'returns false for pods on with invalid url characters' do - @controller.diaspora_id?("ilya_123@join_diaspora.com").should be_false + @controller.send(:diaspora_id?, "ilya_123@join_diaspora.com").should be_false end it 'returns false for invalid usernames' do - @controller.diaspora_id?("ilya_2%3@joindiaspora.com").should be_false + @controller.send(:diaspora_id?, "ilya_2%3@joindiaspora.com").should be_false end end end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 0e7614ab3..3ef5e9361 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -224,17 +224,17 @@ describe StatusMessagesController do it 'removes the getting started flag from new users' do alice.getting_started = true alice.save - expect{ - @controller.remove_getting_started - }.to change{ + expect { + @controller.send(:remove_getting_started) + }.to change { alice.reload.getting_started }.from(true).to(false) end it 'does nothing for returning users' do - expect{ - @controller.remove_getting_started - }.to_not change{ + expect { + @controller.send(:remove_getting_started) + }.to_not change { alice.reload.getting_started } end diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index b08a8602d..a0f18c696 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -81,11 +81,11 @@ describe TagsController do it 'returns true if the following already exists and should be case insensitive' do TagFollowing.create!(:tag => @tag, :user => bob ) - @controller.tag_followed?.should be_true + @controller.send(:tag_followed?).should be_true end it 'returns false if the following does not already exist' do - @controller.tag_followed?.should be_false + @controller.send(:tag_followed?).should be_false end end end |