Displays badge for official positions
This commit is contained in:
@@ -133,6 +133,16 @@ class User < ActiveRecord::Base
|
||||
update official_position: nil, official_level: 0
|
||||
end
|
||||
|
||||
def has_official_email?
|
||||
domain = Setting['email_domain_for_officials']
|
||||
!email.blank? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") )
|
||||
end
|
||||
|
||||
def display_official_position_badge?
|
||||
return true if official_level > 1
|
||||
official_position_badge? && official_level == 1
|
||||
end
|
||||
|
||||
def block
|
||||
debates_ids = Debate.where(author_id: id).pluck(:id)
|
||||
comments_ids = Comment.where(user_id: id).pluck(:id)
|
||||
@@ -197,11 +207,6 @@ class User < ActiveRecord::Base
|
||||
!erased?
|
||||
end
|
||||
|
||||
def has_official_email?
|
||||
domain = Setting['email_domain_for_officials']
|
||||
!email.blank? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") )
|
||||
end
|
||||
|
||||
def locale
|
||||
self[:locale] ||= I18n.default_locale.to_s
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<span class="user-name"><%= t("comments.comment.user_deleted") %></span>
|
||||
<% else %>
|
||||
<span class="user-name"><%= link_to comment.user.name, user_path(comment.user) %></span>
|
||||
<% if comment.user.official? %>
|
||||
<% if comment.user.display_official_position_badge? %>
|
||||
•
|
||||
<span class="label round level-<%= comment.user.official_level %>">
|
||||
<%= comment.user.official_position %>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<span class="author">
|
||||
<%= debate.author.name %>
|
||||
</span>
|
||||
<% if debate.author.official? %>
|
||||
<% if debate.author.display_official_position_badge? %>
|
||||
<span class="bullet"> • </span>
|
||||
<span class="label round level-<%= debate.author.official_level %>">
|
||||
<%= debate.author.official_position %>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<span class="author">
|
||||
<%= proposal.author.name %>
|
||||
</span>
|
||||
<% if proposal.author.official? %>
|
||||
<% if proposal.author.display_official_position_badge? %>
|
||||
<span class="bullet"> • </span>
|
||||
<span class="label round level-<%= proposal.author.official_level %>">
|
||||
<%= proposal.author.official_position %>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<span class="author"><%= t("proposals.show.author_deleted") %></span>
|
||||
<% else %>
|
||||
<span class="author"><%= proposal.author.name %></span>
|
||||
<% if proposal.author.official? %>
|
||||
<% if proposal.author.display_official_position_badge? %>
|
||||
<span class="label round level-<%= proposal.author.official_level %>">
|
||||
<%= proposal.author.official_position %>
|
||||
</span>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<% if resource.author.official? %>
|
||||
<% if resource.author.display_official_position_badge? %>
|
||||
•
|
||||
<span class="label round level-<%= resource.author.official_level %>">
|
||||
<%= resource.author.official_position %>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<span class="author">
|
||||
<%= spending_proposal.author.name %>
|
||||
</span>
|
||||
<% if spending_proposal.author.official? %>
|
||||
<% if spending_proposal.author.display_official_position_badge? %>
|
||||
<span class="bullet"> • </span>
|
||||
<span class="label round level-<%= spending_proposal.author.official_level %>">
|
||||
<%= spending_proposal.author.official_position %>
|
||||
|
||||
97
spec/features/official_positions_spec.rb
Normal file
97
spec/features/official_positions_spec.rb
Normal file
@@ -0,0 +1,97 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Official positions' do
|
||||
|
||||
context "Badge" do
|
||||
|
||||
background do
|
||||
@user1 = create(:user, official_level: 1, official_position: "Employee", official_position_badge: true)
|
||||
@user2 = create(:user, official_level: 0, official_position: "")
|
||||
end
|
||||
|
||||
scenario "Comments" do
|
||||
proposal = create(:proposal)
|
||||
comment1 = create(:comment, commentable: proposal, user: @user1)
|
||||
comment2 = create(:comment, commentable: proposal, user: @user2)
|
||||
|
||||
visit proposal_path(proposal)
|
||||
|
||||
expect_badge_for("comment", comment1)
|
||||
expect_no_badge_for("comment", comment2)
|
||||
end
|
||||
|
||||
context "Debates" do
|
||||
|
||||
background do
|
||||
@debate1 = create(:debate, author: @user1)
|
||||
@debate2 = create(:debate, author: @user2)
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
visit debates_path
|
||||
|
||||
expect_badge_for("debate", @debate1)
|
||||
expect_no_badge_for("debate", @debate2)
|
||||
end
|
||||
|
||||
scenario "Show" do
|
||||
visit debate_path(@debate1)
|
||||
expect_badge_for("debate", @debate1)
|
||||
|
||||
visit debate_path(@debate2)
|
||||
expect_no_badge_for("debate", @debate2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "Proposals" do
|
||||
|
||||
background do
|
||||
@proposal1 = create(:proposal, author: @user1)
|
||||
@proposal2 = create(:proposal, author: @user2)
|
||||
|
||||
featured_proposals = 3.times { create(:proposal) }
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
visit proposals_path
|
||||
|
||||
expect_badge_for("proposal", @proposal1)
|
||||
expect_no_badge_for("proposal", @proposal2)
|
||||
end
|
||||
|
||||
scenario "Show" do
|
||||
visit proposal_path(@proposal1)
|
||||
expect_badge_for("proposal", @proposal1)
|
||||
|
||||
visit proposal_path(@proposal2)
|
||||
expect_no_badge_for("proposal", @proposal2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "Spending proposals" do
|
||||
|
||||
background do
|
||||
@spending_proposal1 = create(:spending_proposal, author: @user1)
|
||||
@spending_proposal2 = create(:spending_proposal, author: @user2)
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
visit spending_proposals_path
|
||||
|
||||
expect_badge_for("spending_proposal", @spending_proposal1)
|
||||
expect_no_badge_for("spending_proposal", @spending_proposal2)
|
||||
end
|
||||
|
||||
scenario "Show" do
|
||||
visit spending_proposal_path(@spending_proposal1)
|
||||
expect_badge_for("spending_proposal", @spending_proposal1)
|
||||
|
||||
visit spending_proposal_path(@spending_proposal2)
|
||||
expect_no_badge_for("spending_proposal", @spending_proposal2)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -289,6 +289,42 @@ describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe "official_position_badge" do
|
||||
|
||||
describe "Users of level 1" do
|
||||
|
||||
it "displays the badge if set in preferences" do
|
||||
user = create(:user, official_level: 1, official_position_badge: true)
|
||||
|
||||
expect(user.display_official_position_badge?).to eq true
|
||||
end
|
||||
|
||||
it "does not display the badge if set in preferences" do
|
||||
user = create(:user, official_level: 1, official_position_badge: false)
|
||||
|
||||
expect(user.display_official_position_badge?).to eq false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Users higher than level 1" do
|
||||
|
||||
it "displays the badge regardless of preferences" do
|
||||
user1 = create(:user, official_level: 2, official_position_badge: false)
|
||||
user2 = create(:user, official_level: 3, official_position_badge: false)
|
||||
user3 = create(:user, official_level: 4, official_position_badge: false)
|
||||
user4 = create(:user, official_level: 5, official_position_badge: false)
|
||||
|
||||
expect(user1.display_official_position_badge?).to eq true
|
||||
expect(user2.display_official_position_badge?).to eq true
|
||||
expect(user3.display_official_position_badge?).to eq true
|
||||
expect(user4.display_official_position_badge?).to eq true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "self.search" do
|
||||
it "find users by email" do
|
||||
user1 = create(:user, email: "larry@madrid.es")
|
||||
|
||||
@@ -231,4 +231,18 @@ module CommonActions
|
||||
DirectMessage.last
|
||||
end
|
||||
|
||||
def expect_badge_for(resource_name, resource)
|
||||
within("##{resource_name}_#{resource.id}") do
|
||||
expect(page).to have_css ".label.round"
|
||||
expect(page).to have_content "Employee"
|
||||
end
|
||||
end
|
||||
|
||||
def expect_no_badge_for(resource_name, resource)
|
||||
within("##{resource_name}_#{resource.id}") do
|
||||
expect(page).to_not have_css ".label.round"
|
||||
expect(page).to_not have_content "Employee"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user