diff --git a/app/controllers/admin/valuators_controller.rb b/app/controllers/admin/valuators_controller.rb
index 10a5c6fdd..6dc827684 100644
--- a/app/controllers/admin/valuators_controller.rb
+++ b/app/controllers/admin/valuators_controller.rb
@@ -47,7 +47,8 @@ class Admin::ValuatorsController < Admin::BaseController
def valuator_params
params[:valuator][:description] = nil if params[:valuator][:description].blank?
- params.require(:valuator).permit(:user_id, :description, :valuator_group_id)
+ params.require(:valuator).permit(:user_id, :description, :valuator_group_id,
+ :can_comment, :can_edit_dossier)
end
end
diff --git a/app/helpers/valuators_helper.rb b/app/helpers/valuators_helper.rb
index 17dd7fc24..616cb6fef 100644
--- a/app/helpers/valuators_helper.rb
+++ b/app/helpers/valuators_helper.rb
@@ -4,4 +4,9 @@ module ValuatorsHelper
truncate([valuator.name, valuator.email, valuator.description].compact.join(" - "), length: 100)
end
+ def valuator_abilities(valuator)
+ [ valuator.can_comment ? I18n.t("admin.valuators.index.can_comment") : nil ,
+ valuator.can_edit_dossier ? I18n.t("admin.valuators.index.can_edit_dossier") : nil
+ ].compact.join(", ")
+ end
end
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index 386303b35..c034ab5c7 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -65,6 +65,7 @@ module Abilities
can [:hide, :update, :toggle_selection], Budget::Investment
can [:valuate, :comment_valuation], Budget::Investment
can :create, Budget::ValuatorAssignment
+ can [:edit_dossier], Budget::Investment
can(:read_admin_stats, Budget) { |budget| budget.balloting_or_later? }
diff --git a/app/models/abilities/valuator.rb b/app/models/abilities/valuator.rb
index fcfa0a0c7..dde522b6a 100644
--- a/app/models/abilities/valuator.rb
+++ b/app/models/abilities/valuator.rb
@@ -4,10 +4,20 @@ module Abilities
def initialize(user)
valuator = user.valuator
+ assigned_investment_ids = valuator.assigned_investment_ids
+ finished = { phase: "finished" }
- can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.assigned_investment_ids
- can [:valuate], Budget::Investment, { id: valuator.assigned_investment_ids, valuation_finished: false }
- cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: "finished" }
+ can [:read, :update], Budget::Investment, id: assigned_investment_ids
+ can [:valuate], Budget::Investment, { id: assigned_investment_ids, valuation_finished: false }
+ cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: finished
+
+ if valuator.can_edit_dossier?
+ can [:edit_dossier], Budget::Investment, id: assigned_investment_ids
+ end
+
+ if valuator.can_comment?
+ can [:comment_valuation], Budget::Investment, id: assigned_investment_ids
+ end
end
end
end
diff --git a/app/views/admin/valuators/_user_row.html.erb b/app/views/admin/valuators/_user_row.html.erb
new file mode 100644
index 000000000..609291eae
--- /dev/null
+++ b/app/views/admin/valuators/_user_row.html.erb
@@ -0,0 +1,14 @@
+
<% if @users.any? %>
<%= page_entries_info @users %>
-
-
-
- | <%= t("admin.valuators.index.name") %> |
- <%= t("admin.valuators.index.email") %> |
- <%= t("admin.valuators.index.description") %> |
- <%= t("admin.shared.actions") %> |
-
-
- <% @users.each do |user| %>
-
- | <%= user.name %> |
- <%= user.email %> |
-
- <% if user.valuator? %>
- <% if user.valuator.description.present? %>
- <%= user.valuator.description %>
- <% else %>
- <%= t("admin.valuators.index.no_description") %>
- <% end %>
- <% else %>
- <%= t("admin.valuators.index.no_description") %>
- <% end %>
- |
- <% if user.valuator? %>
- <%= link_to t("admin.actions.edit"),
- edit_admin_valuator_path(user.valuator),
- class: "button hollow" %>
-
- <%= link_to t("admin.valuators.valuator.delete"),
- admin_valuator_path(user),
- method: :delete,
- class: "button hollow alert expanded" %>
- <% else %>
- <%= form_for Valuator.new(user: user), url: admin_valuators_path do |f| %>
- <%= f.hidden_field :user_id %>
- <%= f.submit t("admin.valuators.valuator.add"),
- class: "button success expanded" %>
- <% end %>
- <% end %>
- |
-
- <% end %>
-
-
+ <%= render partial: "valuators", locals: {valuators: @users} %>
<% else %>
<%= t("admin.shared.no_search_results") %>
diff --git a/app/views/admin/valuators/show.html.erb b/app/views/admin/valuators/show.html.erb
index f1768c42f..ebe1ec87c 100644
--- a/app/views/admin/valuators/show.html.erb
+++ b/app/views/admin/valuators/show.html.erb
@@ -27,4 +27,13 @@
<%= t("admin.valuators.show.no_group") %>
<% end %>
+
+
+ <%= t("admin.valuators.show.abilities") %>
+ <% if valuator_abilities(@valuator).present? %>
+ <%= valuator_abilities(@valuator) %>
+ <% else %>
+ <%= t("admin.valuators.show.no_abilities") %>
+ <% end %>
+
diff --git a/app/views/valuation/budget_investments/_valuation_comments.html.erb b/app/views/valuation/budget_investments/_valuation_comments.html.erb
index 0eacfa825..c1cbafc71 100644
--- a/app/views/valuation/budget_investments/_valuation_comments.html.erb
+++ b/app/views/valuation/budget_investments/_valuation_comments.html.erb
@@ -1,10 +1,11 @@
<%= t("valuation.budget_investments.valuation_comments") %>
<% unless @comment_tree.nil? %>
- <%= render partial: "/comments/comment_tree", locals: {
- comment_tree: @comment_tree,
+ <% can_comment = (!@budget.finished? && can?(:comment_valuation, @investment)) %>
+
+ <%= render partial: "/comments/comment_tree", locals: { comment_tree: @comment_tree,
comment_flags: @comment_flags,
display_comments_count: false,
valuation: true,
- allow_comments: !@budget.finished?,
+ allow_comments: can_comment,
admin_layout: true } %>
<% end %>
diff --git a/app/views/valuation/budget_investments/edit.html.erb b/app/views/valuation/budget_investments/edit.html.erb
index 463987bce..388774e74 100644
--- a/app/views/valuation/budget_investments/edit.html.erb
+++ b/app/views/valuation/budget_investments/edit.html.erb
@@ -1,10 +1,10 @@
<%= link_to valuation_budget_budget_investment_path(@budget, @investment), class: "back" do %>
- <%= "#{t("valuation.budget_investments.show.title")} #{@investment.id}"%>
+ <%= "#{t("valuation.budget_investments.show.title")} #{@investment.id}" %>
<% end %>
<%= t("valuation.budget_investments.edit.dossier") %>
-<% if can?(:valuate, @investment) %>
+<% if can?(:valuate, @investment) && can?(:edit_dossier, @investment) %>
<%= render partial: "/valuation/budget_investments/dossier_form", locals: {investment: @investment} %>
<% else %>
<%= render partial: "/valuation/budget_investments/dossier_detail", locals: {investment: @investment} %>
diff --git a/config/locales/ar/admin.yml b/config/locales/ar/admin.yml
index 10c1d77ab..9303bde72 100644
--- a/config/locales/ar/admin.yml
+++ b/config/locales/ar/admin.yml
@@ -912,7 +912,6 @@ ar:
cost: التكلفة
form:
edit_title: "المقيّمون: تعديل المقيّمين"
- update: "تحديث المقيّم"
updated: "تم تحديث المقيّمين بنجاح"
show:
description: "الوصف"
diff --git a/config/locales/de-DE/admin.yml b/config/locales/de-DE/admin.yml
index 3c1b77a3f..dc42f35c2 100644
--- a/config/locales/de-DE/admin.yml
+++ b/config/locales/de-DE/admin.yml
@@ -787,7 +787,6 @@ de:
cost: Gesamtkosten
form:
edit_title: "Begutachter*innen: Begutachter*in bearbeiten"
- update: "Begutachter*in aktualisieren"
updated: "Begutachter*in erfolgreich aktualisiert"
show:
description: "Beschreibung"
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index b2c262eec..ae89d99fa 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -352,6 +352,11 @@ en:
link:
label: Title
url: Link
+ valuator:
+ description: Description
+ valuator_group_id: Valuator group
+ can_comment: Can create comments
+ can_edit_dossier: Can edit dossiers
errors:
models:
user:
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index af6bb0f6f..e5dee9951 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -903,6 +903,9 @@ en:
valuator_groups: "Valuator Groups"
group: "Group"
no_group: "No group"
+ abilities: "Abilities"
+ can_comment: "Can comment"
+ can_edit_dossier: "Can edit dossier"
valuator:
add: Add to valuators
delete: Delete
@@ -910,14 +913,15 @@ en:
title: "Valuators: User search"
form:
edit_title: "Valuators: Edit valuator"
- update: "Update valuator"
updated: "Valuator updated successfully"
show:
description: "Description"
email: "Email"
group: "Group"
+ abilities: "Abilities"
no_description: "Without description"
no_group: "Without group"
+ no_abilities: "Without abilities"
valuator_groups:
index:
title: "Valuator groups"
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index 4e5b8acd8..ced14d9cc 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -354,6 +354,11 @@ es:
link:
label: Título
url: Enlace
+ valuator:
+ description: Descripción
+ valuator_group_id: Grupo de evaluación
+ can_comment: Puede comentar
+ can_edit_dossier: Puede editar informes
errors:
models:
user:
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 32922cd92..69d305826 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -902,6 +902,9 @@ es:
valuator_groups: "Grupo de evaluadores"
group: "Grupo"
no_group: "Sin grupo"
+ abilities: "Habilidades"
+ can_comment: "Puede comentar"
+ can_edit_dossier: "Puede editar informes"
valuator:
add: Añadir como evaluador
delete: Borrar
@@ -909,14 +912,15 @@ es:
title: "Evaluadores: Búsqueda de usuarios"
form:
edit_title: "Evaluadores: Editar evaluador"
- update: "Actualizar evaluador"
updated: "Evaluador actualizado correctamente"
show:
description: "Descripción"
email: "Email"
group: "Grupo"
+ abilities: "Habilidades"
no_description: "Sin descripción"
no_group: "Sin grupo"
+ no_abilities: "Sin habilidades"
valuator_groups:
index:
title: "Grupos de evaluadores"
diff --git a/config/locales/fa-IR/admin.yml b/config/locales/fa-IR/admin.yml
index c5bd4365c..9bef0a576 100644
--- a/config/locales/fa-IR/admin.yml
+++ b/config/locales/fa-IR/admin.yml
@@ -630,7 +630,6 @@ fa:
cost: "هزینه\n"
form:
edit_title: "ارزیابی کنندگان: ویرایش ارزیاب"
- update: "به روزرسانی ارزیابی "
updated: " ارزیابی با موفقیت به روز رسانی شده"
show:
description: "توضیحات"
diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml
index 2426f0d4c..b499a4c64 100644
--- a/config/locales/fr/admin.yml
+++ b/config/locales/fr/admin.yml
@@ -868,7 +868,6 @@ fr:
cost: Coût
form:
edit_title: "Évaluateurs : modifier l'évaluateur"
- update: "Modifier l'évaluateur"
updated: "L'évaluateur a bien été modifié"
show:
description: "Description"
diff --git a/config/locales/gl/admin.yml b/config/locales/gl/admin.yml
index ca064b21f..18ea91fd6 100644
--- a/config/locales/gl/admin.yml
+++ b/config/locales/gl/admin.yml
@@ -798,7 +798,6 @@ gl:
cost: Custo total
form:
edit_title: "Avaliadores: Editar avaliador"
- update: "Actualizar avaliador"
updated: "Avaliador actualizado correctamente"
show:
description: "Descrición"
diff --git a/config/locales/it/admin.yml b/config/locales/it/admin.yml
index db37ca49c..8cfb8642f 100644
--- a/config/locales/it/admin.yml
+++ b/config/locales/it/admin.yml
@@ -710,7 +710,6 @@ it:
cost: Costi
form:
edit_title: "Stimatori: Modificare stimatore"
- update: "Aggiorna stimatore"
updated: "Stimatore aggiornato con successo"
show:
description: "Descrizione"
diff --git a/config/locales/nl/admin.yml b/config/locales/nl/admin.yml
index 6742eedbe..e428a5ecd 100644
--- a/config/locales/nl/admin.yml
+++ b/config/locales/nl/admin.yml
@@ -826,7 +826,6 @@ nl:
cost: Kosten
form:
edit_title: "Beoordelaars: Bewerk Beoordelaar"
- update: "Sla op"
updated: "Beoordelaar aangepast"
show:
description: "Beschrijving"
diff --git a/config/locales/pl-PL/admin.yml b/config/locales/pl-PL/admin.yml
index b776bb972..137fb6618 100644
--- a/config/locales/pl-PL/admin.yml
+++ b/config/locales/pl-PL/admin.yml
@@ -823,7 +823,6 @@ pl:
cost: Koszt
form:
edit_title: "Wyceniający: Edytuj wyceniającego"
- update: "Aktualizuj wyceniającego"
updated: "Wyceniający zaktualizowany pomyślnie"
show:
description: "Opis"
diff --git a/config/locales/pt-BR/admin.yml b/config/locales/pt-BR/admin.yml
index 38f117d45..ee086d86d 100644
--- a/config/locales/pt-BR/admin.yml
+++ b/config/locales/pt-BR/admin.yml
@@ -709,7 +709,6 @@ pt-BR:
cost: Custo
form:
edit_title: "Avaliadores: editar avaliador"
- update: "Atualizar avaliador"
updated: "Avalaiador atualizado com sucesso"
show:
description: "Descrição"
diff --git a/config/locales/ru/admin.yml b/config/locales/ru/admin.yml
index b13892510..234a0eb6c 100644
--- a/config/locales/ru/admin.yml
+++ b/config/locales/ru/admin.yml
@@ -826,7 +826,6 @@ ru:
cost: Стоимость
form:
edit_title: "Оценщики: Редактировать оценщика"
- update: "Обновить оценщика"
updated: "Оценщик обновлен успешно"
show:
description: "Описание"
diff --git a/config/locales/sl-SI/admin.yml b/config/locales/sl-SI/admin.yml
index 031b32760..ff443f148 100644
--- a/config/locales/sl-SI/admin.yml
+++ b/config/locales/sl-SI/admin.yml
@@ -525,7 +525,6 @@ sl:
cost: Cena
form:
edit_title: "Cenilci: Uredi cenilce"
- update: "Posodobi cenilca"
updated: "Cenilec uspešno posodobljen"
show:
description: "Opis"
diff --git a/config/locales/so-SO/admin.yml b/config/locales/so-SO/admin.yml
index 54a2afc26..1070dc461 100644
--- a/config/locales/so-SO/admin.yml
+++ b/config/locales/so-SO/admin.yml
@@ -715,7 +715,6 @@ so:
cost: Kharashaad
form:
edit_title: "Qiimeeyayaasha: Tafatiraha qiimeeyaha"
- update: "Cusboneysi Qimeeyaha"
updated: "Siguula ayaa loo cusboneysiyey"
show:
description: "Sharaxaad"
diff --git a/config/locales/sq-AL/admin.yml b/config/locales/sq-AL/admin.yml
index 3a2867073..f146cd330 100644
--- a/config/locales/sq-AL/admin.yml
+++ b/config/locales/sq-AL/admin.yml
@@ -717,7 +717,6 @@ sq:
cost: Kosto
form:
edit_title: "Vlerësuesit: Ndrysho vlerësuesin"
- update: "Përditëso vlerësuesin"
updated: "Vlerësuesi u përditësua me sukses"
show:
description: "Përshkrimi"
diff --git a/config/locales/val/admin.yml b/config/locales/val/admin.yml
index 1067c80c6..e6f3c2bf5 100644
--- a/config/locales/val/admin.yml
+++ b/config/locales/val/admin.yml
@@ -764,7 +764,6 @@ val:
cost: Cost total
form:
edit_title: "Avaluadors: Editar avaluador"
- update: "Actualitzar avaluador"
updated: "Avaluador actualitzat correctament"
show:
description: "Descripció"
diff --git a/config/locales/zh-CN/admin.yml b/config/locales/zh-CN/admin.yml
index 95876f09c..240920088 100644
--- a/config/locales/zh-CN/admin.yml
+++ b/config/locales/zh-CN/admin.yml
@@ -718,7 +718,6 @@ zh-CN:
cost: 成本
form:
edit_title: "评估员:编辑评估员"
- update: "更新评估员"
updated: "评估员已成功更新"
show:
description: "说明"
diff --git a/config/locales/zh-TW/admin.yml b/config/locales/zh-TW/admin.yml
index 55474f555..f0223f921 100644
--- a/config/locales/zh-TW/admin.yml
+++ b/config/locales/zh-TW/admin.yml
@@ -708,7 +708,6 @@ zh-TW:
cost: 成本
form:
edit_title: "評估員:編輯評估員"
- update: "更新評估員"
updated: "評估員已成功更新"
show:
description: "描述"
diff --git a/db/migrate/20190408083819_add_actions_to_valuators.rb b/db/migrate/20190408083819_add_actions_to_valuators.rb
new file mode 100644
index 000000000..62f5cf213
--- /dev/null
+++ b/db/migrate/20190408083819_add_actions_to_valuators.rb
@@ -0,0 +1,6 @@
+class AddActionsToValuators < ActiveRecord::Migration
+ def change
+ add_column :valuators, :can_comment, :boolean, default: true
+ add_column :valuators, :can_edit_dossier, :boolean, default: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index fed6d8263..d8192343c 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -1487,6 +1487,8 @@ ActiveRecord::Schema.define(version: 20190607160900) do
t.string "description"
t.integer "budget_investments_count", default: 0
t.integer "valuator_group_id"
+ t.boolean "can_comment", default: true
+ t.boolean "can_edit_dossier", default: true
t.index ["user_id"], name: "index_valuators_on_user_id", using: :btree
end
diff --git a/spec/features/admin/valuator_groups_spec.rb b/spec/features/admin/valuator_groups_spec.rb
index 12134379e..a78a2bbcd 100644
--- a/spec/features/admin/valuator_groups_spec.rb
+++ b/spec/features/admin/valuator_groups_spec.rb
@@ -88,7 +88,7 @@ describe "Valuator groups" do
visit edit_admin_valuator_path(valuator)
select "Health", from: "valuator_valuator_group_id"
- click_button "Update valuator"
+ click_button "Update Valuator"
expect(page).to have_content "Valuator updated successfully"
expect(page).to have_content "Health"
@@ -102,7 +102,7 @@ describe "Valuator groups" do
visit edit_admin_valuator_path(valuator)
select "Economy", from: "valuator_valuator_group_id"
- click_button "Update valuator"
+ click_button "Update Valuator"
expect(page).to have_content "Valuator updated successfully"
expect(page).to have_content "Economy"
@@ -115,7 +115,7 @@ describe "Valuator groups" do
visit edit_admin_valuator_path(valuator)
select "", from: "valuator_valuator_group_id"
- click_button "Update valuator"
+ click_button "Update Valuator"
expect(page).to have_content "Valuator updated successfully"
expect(page).not_to have_content "Health"
diff --git a/spec/features/admin/valuators_spec.rb b/spec/features/admin/valuators_spec.rb
index a8a08b9f9..65c8a5d7f 100644
--- a/spec/features/admin/valuators_spec.rb
+++ b/spec/features/admin/valuators_spec.rb
@@ -2,104 +2,112 @@ require "rails_helper"
describe "Admin valuators" do
+ let(:admin) { create(:administrator) }
+ let!(:user) { create(:user, username: "Jose Luis Balbin") }
+ let!(:valuator) { create(:valuator) }
+
before do
- @admin = create(:administrator)
- @user = create(:user, username: "Jose Luis Balbin")
- @valuator = create(:valuator)
- login_as(@admin.user)
+ login_as(admin.user)
visit admin_valuators_path
end
scenario "Show" do
- visit admin_valuator_path(@valuator)
+ visit admin_valuator_path(valuator)
- expect(page).to have_content @valuator.name
- expect(page).to have_content @valuator.description
- expect(page).to have_content @valuator.email
+ expect(page).to have_content valuator.name
+ expect(page).to have_content valuator.description
+ expect(page).to have_content valuator.email
+ expect(page).to have_content "Can comment, Can edit dossier"
end
scenario "Index" do
- expect(page).to have_content(@valuator.name)
- expect(page).to have_content(@valuator.email)
- expect(page).not_to have_content(@user.name)
+ expect(page).to have_content(valuator.name)
+ expect(page).to have_content(valuator.email)
+ expect(page).not_to have_content(user.name)
end
scenario "Create", :js do
- fill_in "name_or_email", with: @user.email
+ fill_in "name_or_email", with: user.email
click_button "Search"
- expect(page).to have_content(@user.name)
+ expect(page).to have_content(user.name)
click_button "Add to valuators"
within("#valuators") do
- expect(page).to have_content(@user.name)
+ expect(page).to have_content(user.name)
end
end
scenario "Edit" do
- visit edit_admin_valuator_path(@valuator)
+ visit edit_admin_valuator_path(valuator)
+
+ expect(page).to have_field("Can create comments", checked: true)
+ expect(page).to have_field("Can edit dossiers", checked: true)
fill_in "valuator_description", with: "Valuator for health"
- click_button "Update valuator"
+ uncheck "Can edit dossiers"
+ click_button "Update Valuator"
expect(page).to have_content "Valuator updated successfully"
- expect(page).to have_content @valuator.email
+ expect(page).to have_content valuator.email
expect(page).to have_content "Valuator for health"
+ expect(page).to have_content "Can comment"
+ expect(page).not_to have_content "Can edit dossier"
end
scenario "Destroy" do
click_link "Delete"
within("#valuators") do
- expect(page).not_to have_content(@valuator.name)
+ expect(page).not_to have_content(valuator.name)
end
end
context "Search" do
+ let!(:user1) { create(:user, username: "David Foster Wallace", email: "david@wallace.com") }
+ let!(:user2) { create(:user, username: "Steven Erikson", email: "steven@erikson.com") }
+ let!(:valuator1) { create(:valuator, user: user1) }
+ let!(:valuator2) { create(:valuator, user: user2) }
before do
- user = create(:user, username: "David Foster Wallace", email: "david@wallace.com")
- user2 = create(:user, username: "Steven Erikson", email: "steven@erikson.com")
- @valuator1 = create(:valuator, user: user)
- @valuator2 = create(:valuator, user: user2)
visit admin_valuators_path
end
scenario "returns no results if search term is empty" do
- expect(page).to have_content(@valuator1.name)
- expect(page).to have_content(@valuator2.name)
+ expect(page).to have_content(valuator1.name)
+ expect(page).to have_content(valuator2.name)
fill_in "name_or_email", with: " "
click_button "Search"
expect(page).to have_content("Valuators: User search")
expect(page).to have_content("No results found")
- expect(page).not_to have_content(@valuator1.name)
- expect(page).not_to have_content(@valuator2.name)
+ expect(page).not_to have_content(valuator1.name)
+ expect(page).not_to have_content(valuator2.name)
end
scenario "search by name" do
- expect(page).to have_content(@valuator1.name)
- expect(page).to have_content(@valuator2.name)
+ expect(page).to have_content(valuator1.name)
+ expect(page).to have_content(valuator2.name)
fill_in "name_or_email", with: "Foster"
click_button "Search"
expect(page).to have_content("Valuators: User search")
- expect(page).to have_content(@valuator1.name)
- expect(page).not_to have_content(@valuator2.name)
+ expect(page).to have_content(valuator1.name)
+ expect(page).not_to have_content(valuator2.name)
end
scenario "search by email" do
- expect(page).to have_content(@valuator1.email)
- expect(page).to have_content(@valuator2.email)
+ expect(page).to have_content(valuator1.email)
+ expect(page).to have_content(valuator2.email)
- fill_in "name_or_email", with: @valuator2.email
+ fill_in "name_or_email", with: valuator2.email
click_button "Search"
expect(page).to have_content("Valuators: User search")
- expect(page).to have_content(@valuator2.email)
- expect(page).not_to have_content(@valuator1.email)
+ expect(page).to have_content(valuator2.email)
+ expect(page).not_to have_content(valuator1.email)
end
end
diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb
index 096206389..324292ca5 100644
--- a/spec/models/abilities/valuator_spec.rb
+++ b/spec/models/abilities/valuator_spec.rb
@@ -44,4 +44,18 @@ describe Abilities::Valuator do
it { should_not be_able_to(:update, finished_assigned_investment) }
it { should_not be_able_to(:valuate, finished_assigned_investment) }
+
+ it "can update dossier information if not set can_edit_dossier attribute" do
+ should be_able_to(:edit_dossier, assigned_investment)
+ allow(valuator).to receive(:can_edit_dossier?).and_return(false)
+ ability = Ability.new(user)
+ expect(ability.can?(:edit_dossier, assigned_investment)).to be_falsey
+ end
+
+ it "cannot create valuation comments if not set not can_comment attribute" do
+ should be_able_to(:comment_valuation, assigned_investment)
+ allow(valuator).to receive(:can_comment?).and_return(false)
+ ability = Ability.new(user)
+ expect(ability.can?(:comment_valuation, assigned_investment)).to be_falsey
+ end
end
diff --git a/spec/models/valuator_spec.rb b/spec/models/valuator_spec.rb
index 854171a3b..7f1efa3c7 100644
--- a/spec/models/valuator_spec.rb
+++ b/spec/models/valuator_spec.rb
@@ -50,4 +50,13 @@ describe Valuator do
expect(assigned_investment_ids).not_to include investment3.id
end
end
+
+ describe "abilities" do
+ context "by default" do
+ let(:valuator) { Valuator.new }
+ it { expect(valuator.can_comment).to be_truthy }
+ it { expect(valuator.can_edit_dossier).to be_truthy }
+ end
+ end
+
end