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
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
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
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
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
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
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(" ")
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
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
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
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