Skip to content

Commit

Permalink
Enhanced readability (publiclab#4610)
Browse files Browse the repository at this point in the history
* Enhanced readability

* .

* .
  • Loading branch information
SidharthBansal authored Jan 13, 2019
1 parent 4c12b26 commit f805382
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ def digest
end

def multiple_add
if !params[:names] || params[:names] == ''
if !params[:tagnames] || params[:tagnames] == ''
flash[:notice] = "Please enter tags for subscription in the url."
redirect_to "/subscriptions" + "?_=" + Time.now.to_i.to_s
return
end
if params[:names].is_a? String
tag_list = params[:names].split(',')
if params[:tagnames].is_a? String
tag_list = params[:tagnames].split(',')
else
tag_list = params[:names]
tag_list = params[:tagnames]
end
# should be logged in to subscribe
if current_user
Expand All @@ -136,7 +136,7 @@ def multiple_add
tag_list.each do |t|
if t.length.positive?
tag = Tag.find_by(name: t)
# t should be not nil consider params[:names] = balloon,,mapping,,kites,oil
# t should be not nil consider params[:tagnames] = balloon,,mapping,,kites,oil
if tag.nil?
# if the tag doesn't exist, we should create it!
# this could fail validations; error out if so...
Expand Down Expand Up @@ -166,7 +166,7 @@ def multiple_add
if request.xhr?
render :json => true
else
flash[:notice] = "You are now following '#{params[:names]}'."
flash[:notice] = "You are now following '#{params[:tagnames]}'."
redirect_to "/subscriptions" + "?_=" + Time.now.to_i.to_s
end
end
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
get 'subscribe/:type/:name' => 'subscription#add'
get 'subscriptions' => 'subscription#index'
get 'subscriptions/digest' => 'subscription#digest'
get 'subscribe/multiple/:type/:names' => 'subscription#multiple_add'
post 'subscribe/multiple/:type/:names' => 'subscription#multiple_add'
get 'subscribe/multiple/:type/:tagnames' => 'subscription#multiple_add'
post 'subscribe/multiple/:type/:tagnames' => 'subscription#multiple_add'
get 'subscribe/multiple/:type' => 'subscription#multiple_add'
post 'subscribe/multiple/:type' => 'subscription#multiple_add'
get 'wiki/stale' => 'wiki#stale'
Expand Down
6 changes: 3 additions & 3 deletions test/functional/subscription_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setup
test 'should subscribe to multiple tags' do
UserSession.create(users(:bob))
assert users(:bob).following(:awesome)
get :multiple_add, params: { type: 'tag', names: 'blog,kites,,balloon,awesome' }
get :multiple_add, params: { type: 'tag', tagnames: 'blog,kites,,balloon,awesome' }
assert_response :redirect
assert users(:bob).following(:blog)
assert users(:bob).following(:awesome)
Expand All @@ -41,13 +41,13 @@ def setup
test 'should not subscribe to multiple tags in case of empty string' do
UserSession.create(users(:bob))
assert users(:bob).following(:awesome)
get :multiple_add, params: { type: 'tag', names: '' }
get :multiple_add, params: { type: 'tag', tagnames: '' }
assert_response :redirect
assert_equal "Please enter tags for subscription in the url.", flash[:notice]
end

test 'user is not logged in and tries to subscribe multiple tags' do
get :multiple_add, params: { type: 'tag', names: 'kites,balloon' }
get :multiple_add, params: { type: 'tag', tagnames: 'kites,balloon' }
assert_redirected_to '/login?return_to=/subscribe/multiple/tag/kites,balloon'
assert_equal "You must be logged in to subscribe for email updates!", flash[:warning]
end
Expand Down

0 comments on commit f805382

Please sign in to comment.