fix rubocop warnings
This commit is contained in:
parent
bb22e23dfb
commit
a32076abd6
5 changed files with 17 additions and 19 deletions
|
@ -26,7 +26,7 @@ class DiaryEntryController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Subscribe user to diary comments
|
# 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
|
redirect_to :controller => "diary_entry", :action => "list", :display_name => @user.display_name
|
||||||
else
|
else
|
||||||
|
@ -70,7 +70,7 @@ class DiaryEntryController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add the commenter to the subscribers if necessary
|
# 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
|
redirect_to :controller => "diary_entry", :action => "view", :display_name => @entry.user.display_name, :id => @entry.id
|
||||||
else
|
else
|
||||||
|
@ -83,7 +83,7 @@ class DiaryEntryController < ApplicationController
|
||||||
def subscribe
|
def subscribe
|
||||||
diary_entry = DiaryEntry.find(params[:id])
|
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
|
redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
@ -93,7 +93,7 @@ class DiaryEntryController < ApplicationController
|
||||||
def unsubscribe
|
def unsubscribe
|
||||||
diary_entry = DiaryEntry.find(params[:id])
|
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
|
redirect_to :controller => "diary_entry", :action => "view", :display_name => diary_entry.user.display_name, :id => diary_entry.id
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
|
@ -4,7 +4,7 @@ class DiaryEntry < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment"
|
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 :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
|
has_many :subscribers, :through => :subscriptions, :source => :user
|
||||||
|
|
||||||
scope :visible, -> { where(:visible => true) }
|
scope :visible, -> { where(:visible => true) }
|
||||||
|
|
|
@ -4,7 +4,7 @@ class User < ActiveRecord::Base
|
||||||
has_many :traces, -> { where(:visible => true) }
|
has_many :traces, -> { where(:visible => true) }
|
||||||
has_many :diary_entries, -> { order(:created_at => :desc) }
|
has_many :diary_entries, -> { order(:created_at => :desc) }
|
||||||
has_many :diary_comments, -> { 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 :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 :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
|
has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id
|
||||||
|
|
|
@ -11,7 +11,7 @@ class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration
|
||||||
|
|
||||||
def up
|
def up
|
||||||
DiaryEntry.find_each do |diary_entry|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -330,7 +330,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
||||||
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
|
assert_select "h2", :text => "No entry with the id: 9999", :count => 1
|
||||||
end
|
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
|
# Now try an invalid comment with an empty body
|
||||||
assert_no_difference "ActionMailer::Base.deliveries.size" do
|
assert_no_difference "ActionMailer::Base.deliveries.size" do
|
||||||
|
@ -378,7 +378,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
||||||
def test_comment_spammy
|
def test_comment_spammy
|
||||||
# Find the entry to comment on
|
# Find the entry to comment on
|
||||||
entry = create(:diary_entry, :user_id => users(:normal_user).id)
|
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
|
# Generate some spammy content
|
||||||
spammy_text = 1.upto(50).map { |n| "http://example.com/spam#{n}" }.join(" ")
|
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
|
def test_subscribe_success
|
||||||
diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)
|
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
|
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
|
end
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
end
|
end
|
||||||
|
@ -687,13 +685,13 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
|
|
||||||
# bad diary id
|
# 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
|
assert_response :not_found
|
||||||
|
|
||||||
# trying to subscribe when already subscribed
|
# 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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -702,9 +700,9 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
||||||
def test_unsubscribe_success
|
def test_unsubscribe_success
|
||||||
diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)
|
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
|
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
|
end
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
end
|
end
|
||||||
|
@ -721,12 +719,12 @@ class DiaryEntryControllerTest < ActionController::TestCase
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
|
|
||||||
# bad diary id
|
# 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
|
assert_response :not_found
|
||||||
|
|
||||||
# trying to subscribe when already subscribed
|
# trying to subscribe when already subscribed
|
||||||
assert_no_difference "diary_entry.subscribers.count" do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue