From 51d688897aba29b5993317c465a714723db7bf27 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 20 Jun 2016 21:07:32 +0200 Subject: [PATCH] displays badge option if official position is level 1 --- app/views/account/show.html.erb | 22 +++++++++++---------- spec/features/account_spec.rb | 35 +++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index deaa4c889..247aa6024 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -87,16 +87,18 @@ <% end %> -
- <%= f.label :official_position_badge do %> - <%= f.check_box :official_position_badge, - title: t('account.show.official_position_badge_label'), - label: false %> - - <%= t("account.show.official_position_badge_label") %> - - <% end %> -
+ <% if @account.official_level == 1 %> +
+ <%= f.label :official_position_badge do %> + <%= f.check_box :official_position_badge, + title: t('account.show.official_position_badge_label'), + label: false %> + + <%= t("account.show.official_position_badge_label") %> + + <% end %> +
+ <% end %> <%= f.submit t("account.show.save_changes_submit"), class: "button" %> diff --git a/spec/features/account_spec.rb b/spec/features/account_spec.rb index 604872a58..d1c547185 100644 --- a/spec/features/account_spec.rb +++ b/spec/features/account_spec.rb @@ -37,7 +37,6 @@ feature 'Account' do check 'account_email_on_comment_reply' uncheck 'account_email_digest' uncheck 'account_email_on_direct_message' - check 'account_official_position_badge' click_button 'Save changes' expect(page).to have_content "Changes saved" @@ -49,7 +48,6 @@ feature 'Account' do expect(find("#account_email_on_comment_reply")).to be_checked expect(find("#account_email_digest")).to_not be_checked expect(find("#account_email_on_direct_message")).to_not be_checked - expect(find("#account_official_position_badge")).to be_checked end scenario 'Edit Organization' do @@ -71,6 +69,39 @@ feature 'Account' do expect(find("#account_email_on_comment_reply")).to be_checked end + context "Option to display badge for official position" do + + scenario "Users with official position of level 1" do + official_user = create(:user, official_level: 1) + + login_as(official_user) + visit account_path + + check 'account_official_position_badge' + click_button 'Save changes' + expect(page).to have_content "Changes saved" + + visit account_path + expect(find("#account_official_position_badge")).to be_checked + end + + scenario "Users with official position of level 2 and above" do + official_user2 = create(:user, official_level: 2) + official_user3 = create(:user, official_level: 3) + + login_as(official_user2) + visit account_path + + expect(page).to_not have_css '#account_official_position_badge' + + login_as(official_user3) + visit account_path + + expect(page).to_not have_css '#account_official_position_badge' + end + + end + scenario "Errors on edit" do visit account_path