From 2d8b5bd54c6f08fa4d2fee060f2d0ac44974b9f1 Mon Sep 17 00:00:00 2001 From: Ilyaaaaaaaaaaaaa Zhitomirskiy Date: Mon, 4 Jul 2011 16:39:28 -0700 Subject: [PATCH] refactored the controller, moved flash message into translations --- app/controllers/tag_followings_controller.rb | 12 ++++++---- config/locales/diaspora/en.yml | 8 +++++++ .../tag_followings_controller_spec.rb | 23 +++++++++++++++---- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index f26c06442..2883f501d 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -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 + flash[:error] = I18n.t('tag_followings.destroy.failure', :name => params[:name]) end + + redirect_to tag_path(:name => params[:name]) end end diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 4dc934cb9..208ea5dfa 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -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" diff --git a/spec/controllers/tag_followings_controller_spec.rb b/spec/controllers/tag_followings_controller_spec.rb index 2acae2a69..60dfb6bdc 100644 --- a/spec/controllers/tag_followings_controller_spec.rb +++ b/spec/controllers/tag_followings_controller_spec.rb @@ -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