generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
users_can_create_a_matched_effort_spec.rb
84 lines (67 loc) · 3.19 KB
/
users_can_create_a_matched_effort_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
RSpec.describe "Users can create a matched effort" do
context "when signed in as a partner organisation user" do
let(:user) { create(:partner_organisation_user) }
let(:programme) { create(:programme_activity, extending_organisation: user.organisation) }
let!(:project) { create(:project_activity, :with_report, organisation: user.organisation, parent: programme) }
let!(:matched_effort_provider) { create(:matched_effort_provider) }
before { authenticate!(user: user) }
before do
visit organisation_activity_path(project.organisation, project)
click_on "Other funding"
click_on t("page_content.matched_effort.button.create")
end
after { logout }
scenario "they can add a matched effort" do
template = build(:matched_effort,
organisation: matched_effort_provider,
funding_type: "in_kind",
category: "training",
committed_amount: "1234",
currency: "VND",
exchange_rate: "0.0000305832",
date_of_exchange_rate: Date.parse("2021-01-01"),
notes: "Here are some notes")
fill_in_matched_effort_form(template)
expect(page).to have_content(t("action.matched_effort.create.success"))
matched_effort = MatchedEffort.order("created_at ASC").last
expect(matched_effort.organisation).to eq(matched_effort_provider)
expect(matched_effort.funding_type).to eq("in_kind")
expect(matched_effort.category).to eq("training")
expect(matched_effort.committed_amount).to eq(1234.00)
expect(matched_effort.currency).to eq("VND")
expect(matched_effort.exchange_rate).to eq(0.0000305832)
expect(matched_effort.date_of_exchange_rate).to eq(Date.parse("2021-01-01"))
expect(matched_effort.notes).to eq("Here are some notes")
within("table.implementing_organisations") do
expect(page).to have_content(matched_effort_provider.name)
expect(page).to have_content("In kind")
expect(page).to have_content("Training")
expect(page).to have_content("£1,234.00")
end
end
scenario "they see a summary and the error message when the category does not match the funding type" do
template = build(:matched_effort,
funding_type: "reciprocal",
category: "staff_time",
organisation: matched_effort_provider)
fill_in_matched_effort_form(template)
expect(page).to have_selector(".govuk-error-summary")
expect(page).to_not have_content(t("action.matched_effort.create.success"))
expect(page).to have_content(
t(
"activerecord.errors.models.matched_effort.attributes.category.invalid",
category: "Staff time",
funding_type: "Reciprocal"
)
)
expect(page.find(:xpath, "//input[@value='#{template.category}']").checked?).to be(false)
end
scenario "they see a summary and the errors when required fields are left blank" do
page.find(:xpath, "//input[@value='in_kind']").set(true)
click_on t("default.button.submit")
expect(page).to have_selector(".govuk-error-summary")
expect(page).to have_content("Organisation can't be blank")
expect(page).to have_content("Category can't be blank")
end
end
end