refactored the controller, moved flash message into translations
This commit is contained in:
parent
edac7601f5
commit
2d8b5bd54c
3 changed files with 34 additions and 9 deletions
|
|
@ -8,10 +8,12 @@ class TagFollowingsController < ApplicationController
|
|||
@tag_following = current_user.tag_followings.new(:tag_id => @tag.id)
|
||||
|
||||
if @tag_following.save
|
||||
redirect_to(tag_path(:name => params[:name]), :notice => "Successfully following: #{params[:name]}" )
|
||||
flash[:notice] = I18n.t('tag_followings.create.success', :name => params[:name])
|
||||
else
|
||||
render :nothing => true, :status => 406
|
||||
flash[:error] = I18n.t('tag_followings.create.failure', :name => params[:name])
|
||||
end
|
||||
|
||||
redirect_to tag_path(:name => params[:name])
|
||||
end
|
||||
|
||||
# DELETE /tag_followings/1
|
||||
|
|
@ -20,9 +22,11 @@ class TagFollowingsController < ApplicationController
|
|||
@tag = ActsAsTaggableOn::Tag.find_by_name(params[:name])
|
||||
@tag_following = current_user.tag_followings.where(:tag_id => @tag.id).first
|
||||
if @tag_following && @tag_following.destroy
|
||||
redirect_to(tag_path(:name => params[:name]), :notice => "Successfully stopped following: #{params[:name]}" )
|
||||
flash[:notice] = I18n.t('tag_followings.destroy.success', :name => params[:name])
|
||||
else
|
||||
render :nothing => true, :status => 410
|
||||
end
|
||||
flash[:error] = I18n.t('tag_followings.destroy.failure', :name => params[:name])
|
||||
end
|
||||
|
||||
redirect_to tag_path(:name => params[:name])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -701,6 +701,14 @@ en:
|
|||
follow: "Follow #%{tag}"
|
||||
stop_following: "Stop Following #%{tag}"
|
||||
|
||||
tag_followings:
|
||||
create:
|
||||
success: "Successfully following: #%{name}"
|
||||
failure: "Failed to follow: #%{name}"
|
||||
destroy:
|
||||
success: "Successfully stopped following: #%{name}"
|
||||
failure: "Failed to stop following: #%{name}"
|
||||
|
||||
tokens:
|
||||
show:
|
||||
connect_to_cubbies: "Connect to Cubbi.es"
|
||||
|
|
|
|||
|
|
@ -41,15 +41,19 @@ describe TagFollowingsController do
|
|||
}.to_not change(alice.tag_followings, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the tag page" do
|
||||
it "redirects and flashes success to the tag page" do
|
||||
post :create, valid_attributes
|
||||
|
||||
response.should redirect_to(tag_path(:name => valid_attributes[:name]))
|
||||
flash[:notice].should == "Successfully following: ##{valid_attributes[:name]}"
|
||||
end
|
||||
|
||||
it "returns a 406 if you already have a tag" do
|
||||
it "redirects and flashes error if you already have a tag" do
|
||||
TagFollowing.any_instance.stub(:save).and_return(false)
|
||||
post :create, valid_attributes
|
||||
response.code.should == "406"
|
||||
|
||||
response.should redirect_to(tag_path(:name => valid_attributes[:name]))
|
||||
flash[:error].should == "Failed to follow: ##{valid_attributes[:name]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -66,10 +70,19 @@ describe TagFollowingsController do
|
|||
}.to change(TagFollowing, :count).by(-1)
|
||||
end
|
||||
|
||||
it "returns a 410 if you already have a tag" do
|
||||
it "redirects and flashes error if you already don't follow the tag" do
|
||||
delete :destroy, valid_attributes
|
||||
|
||||
response.should redirect_to(tag_path(:name => valid_attributes[:name]))
|
||||
flash[:notice].should == "Successfully stopped following: ##{valid_attributes[:name]}"
|
||||
end
|
||||
|
||||
it "redirects and flashes error if you already don't follow the tag" do
|
||||
TagFollowing.any_instance.stub(:destroy).and_return(false)
|
||||
delete :destroy, valid_attributes
|
||||
response.code.should == "410"
|
||||
|
||||
response.should redirect_to(tag_path(:name => valid_attributes[:name]))
|
||||
flash[:error].should == "Failed to stop following: ##{valid_attributes[:name]}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue