From bf8726a273b86886c9f3ae449785c1e9a4cd93e2 Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Tue, 17 Sep 2013 17:28:56 +0200 Subject: [PATCH] If the user not watch app. Not see the unwatch button --- app/assets/javascripts/apps.show.js | 3 +++ app/views/apps/show.html.haml | 3 ++- config/locales/en.yml | 1 + spec/views/apps/show.html.haml_spec.rb | 32 ++++++++++++++++++++++++++++---- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/apps.show.js b/app/assets/javascripts/apps.show.js index 2300d81..f340d32 100644 --- a/app/assets/javascripts/apps.show.js +++ b/app/assets/javascripts/apps.show.js @@ -1,10 +1,13 @@ $(function() { + $("#watchers_toggle").click(function() { $("#watchers_div").slideToggle("slow"); }); + $("#repository_toggle").click(function() { $("#repository_div").slideToggle("slow"); }); + $("#deploys_toggle").click(function() { $("#deploys_div").slideToggle("slow"); }); diff --git a/app/views/apps/show.html.haml b/app/views/apps/show.html.haml index 9522664..f44216a 100644 --- a/app/views/apps/show.html.haml +++ b/app/views/apps/show.html.haml @@ -15,8 +15,9 @@ = link_to t('.unresolved_errs'), app_path(app), :class => 'button' - else = link_to t('.all_errs'), app_path(app, :all_errs => true), :class => 'button' - = link_to t('.unwatch'), app_watcher_path({:app_id => app, :id => current_user.id}), :method => :delete, :class => 'button', :confirm => 'Are you sure?' + - if current_user.watching?(app) + = link_to t('.unwatch'), app_watcher_path({:app_id => app, :id => current_user.id}), :method => :delete, :class => 'button', :confirm => t('.are_you_sure') %h3#watchers_toggle =t('.watchers') %span.click_span=t('.show_hide') diff --git a/config/locales/en.yml b/config/locales/en.yml index b25b248..ade58a0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -83,6 +83,7 @@ en: all_errs: all errs all_users_notified: "All users will be notified when something happens." api_key: "API Key:" + are_you_sure: 'Are you sure?' atom_title: "Errbit notices for %{name} at %{host}" deploy_count: "Deploy Count:" edit: edit diff --git a/spec/views/apps/show.html.haml_spec.rb b/spec/views/apps/show.html.haml_spec.rb index 2904193..6de628a 100644 --- a/spec/views/apps/show.html.haml_spec.rb +++ b/spec/views/apps/show.html.haml_spec.rb @@ -2,17 +2,20 @@ require 'spec_helper' describe "apps/show.html.haml" do let(:app) { stub_model(App) } + let(:user) { stub_model(User) } + + let(:action_bar) do + view.content_for(:action_bar) + end + before do view.stub(:app).and_return(app) view.stub(:all_errs).and_return(false) view.stub(:deploys).and_return([]) - controller.stub(:current_user) { stub_model(User) } + controller.stub(:current_user) { user } end describe "content_for :action_bar" do - def action_bar - view.content_for(:action_bar) - end it "should confirm the 'cancel' link" do render @@ -28,5 +31,26 @@ describe "apps/show.html.haml" do rendered.should match(/No errs have been/) end end + + context "with user watch application" do + before do + user.stub(:watching?).with(app).and_return(true) + end + it 'see the unwatch button' do + render + expect(action_bar).to include(I18n.t('apps.show.unwatch')) + end + end + + context "with user not watch application" do + before do + user.stub(:watching?).with(app).and_return(false) + end + it 'not see the unwatch button' do + render + expect(action_bar).to_not include(I18n.t('apps.show.unwatch')) + end + end + end -- libgit2 0.21.2