From a32076abd6369b74ac81db5eeffbc40bdf64d597 Mon Sep 17 00:00:00 2001 From: Mikel Maron Date: Fri, 7 Oct 2016 06:32:05 -0400 Subject: [PATCH] fix rubocop warnings --- app/controllers/diary_entry_controller.rb | 8 +++---- app/models/diary_entry.rb | 2 +- app/models/user.rb | 2 +- ...n_table_between_users_and_diary_entries.rb | 2 +- .../diary_entry_controller_test.rb | 22 +++++++++---------- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index bd2e45143..fdc0e9d24 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -26,7 +26,7 @@ class DiaryEntryController < ApplicationController end # Subscribe user to diary comments - @diary_entry.subscriptions.create(user: @user) + @diary_entry.subscriptions.create(:user => @user) redirect_to :controller => "diary_entry", :action => "list", :display_name => @user.display_name else @@ -70,7 +70,7 @@ class DiaryEntryController < ApplicationController end # Add the commenter to the subscribers if necessary - @entry.subscriptions.create(user: @user) unless @entry.subscribers.exists?(@user.id) + @entry.subscriptions.create(:user => @user) unless @entry.subscribers.exists?(@user.id) redirect_to :controller => "diary_entry", :action => "view", :display_name => @entry.user.display_name, :id => @entry.id else @@ -83,7 +83,7 @@ class DiaryEntryController < ApplicationController def subscribe diary_entry = DiaryEntry.find(params[:id]) - diary_entry.subscriptions.create(user: @user) unless diary_entry.subscribers.exists?(@user.id) + diary_entry.subscriptions.create(:user => @user) unless diary_entry.subscribers.exists?(@user.id) redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id rescue ActiveRecord::RecordNotFound @@ -93,7 +93,7 @@ class DiaryEntryController < ApplicationController def unsubscribe diary_entry = DiaryEntry.find(params[:id]) - diary_entry.subscriptions.where(user: @user).delete_all if diary_entry.subscribers.exists?(@user.id) + diary_entry.subscriptions.where(:user => @user).delete_all if diary_entry.subscribers.exists?(@user.id) redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id rescue ActiveRecord::RecordNotFound diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb index 48f3e69bd..e756432fd 100644 --- a/app/models/diary_entry.rb +++ b/app/models/diary_entry.rb @@ -4,7 +4,7 @@ class DiaryEntry < ActiveRecord::Base has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment" has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => %w(active confirmed) }).order(:id) }, :class_name => "DiaryComment" - has_many :subscriptions, :class_name => 'DiaryEntrySubscription' + has_many :subscriptions, :class_name => "DiaryEntrySubscription" has_many :subscribers, :through => :subscriptions, :source => :user scope :visible, -> { where(:visible => true) } diff --git a/app/models/user.rb b/app/models/user.rb index c3e02e0ab..3ff9277f0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < ActiveRecord::Base has_many :traces, -> { where(:visible => true) } has_many :diary_entries, -> { order(:created_at => :desc) } has_many :diary_comments, -> { order(:created_at => :desc) } - has_many :diary_entry_subscriptions, :class_name => 'DiaryEntrySubscription' + has_many :diary_entry_subscriptions, :class_name => "DiaryEntrySubscription" has_many :diary_subscriptions, :through => :diary_entry_subscriptions, :source => :diary_entry has_many :messages, -> { where(:to_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :foreign_key => :to_user_id has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id diff --git a/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb b/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb index b99dbbdb8..ad642f96c 100644 --- a/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb +++ b/db/migrate/20161002153425_add_join_table_between_users_and_diary_entries.rb @@ -11,7 +11,7 @@ class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration def up DiaryEntry.find_each do |diary_entry| - diary_entry.subscriptions.create(user: diary_entry.user) unless diary_entry.subscribers.exists?(@user) + diary_entry.subscriptions.create(:user => diary_entry.user) unless diary_entry.subscribers.exists?(@user.id) end end diff --git a/test/controllers/diary_entry_controller_test.rb b/test/controllers/diary_entry_controller_test.rb index 91131ee8d..77d340ffe 100644 --- a/test/controllers/diary_entry_controller_test.rb +++ b/test/controllers/diary_entry_controller_test.rb @@ -330,7 +330,7 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_select "h2", :text => "No entry with the id: 9999", :count => 1 end - post :subscribe, {:id => entry.id, :display_name => entry.user.display_name}, { :user => users(:normal_user).id} + post :subscribe, { :id => entry.id, :display_name => entry.user.display_name }, { :user => users(:normal_user).id } # Now try an invalid comment with an empty body assert_no_difference "ActionMailer::Base.deliveries.size" do @@ -378,7 +378,7 @@ class DiaryEntryControllerTest < ActionController::TestCase def test_comment_spammy # Find the entry to comment on entry = create(:diary_entry, :user_id => users(:normal_user).id) - post :subscribe, {:id => entry.id, :display_name => entry.user.display_name}, { :user => users(:normal_user).id} + post :subscribe, { :id => entry.id, :display_name => entry.user.display_name }, { :user => users(:normal_user).id } # Generate some spammy content spammy_text = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ") @@ -667,10 +667,8 @@ class DiaryEntryControllerTest < ActionController::TestCase def test_subscribe_success diary_entry = create(:diary_entry, :user_id => users(:normal_user).id) - #basic_authorization(users(:public_user).email, "test") - assert_difference "diary_entry.subscribers.count", 1 do - post :subscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id} + post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => users(:public_user).id } end assert_response :redirect end @@ -687,13 +685,13 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_response :forbidden # bad diary id - post :subscribe, {:id => 999111, :display_name => "username"}, { :user => users(:public_user).id} + post :subscribe, { :id => 999111, :display_name => "username" }, { :user => users(:public_user).id } assert_response :not_found # trying to subscribe when already subscribed - post :subscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id} + post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => users(:public_user).id } assert_no_difference "diary_entry.subscribers.count" do - post :subscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id} + post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id } end end @@ -702,9 +700,9 @@ class DiaryEntryControllerTest < ActionController::TestCase def test_unsubscribe_success diary_entry = create(:diary_entry, :user_id => users(:normal_user).id) - post :subscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id} + post :subscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => users(:public_user).id } assert_difference "diary_entry.subscribers.count", -1 do - post :unsubscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id} + post :unsubscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => users(:public_user).id } end assert_response :redirect end @@ -721,12 +719,12 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_response :forbidden # bad diary id - post :unsubscribe, {:id => 999111, :display_name => "username"}, { :user => users(:public_user).id} + post :unsubscribe, { :id => 999111, :display_name => "username" }, { :user => users(:public_user).id } assert_response :not_found # trying to subscribe when already subscribed assert_no_difference "diary_entry.subscribers.count" do - post :unsubscribe, {:id => diary_entry.id, :display_name => diary_entry.user.display_name}, { :user => users(:public_user).id} + post :unsubscribe, { :id => diary_entry.id, :display_name => diary_entry.user.display_name }, { :user => users(:public_user).id } end end -- 2.39.5