|
15 | 15 | participation: Fabricate(:event_participation, participant: people(:mitglied), event: event)).participation |
16 | 16 | end |
17 | 17 | let(:revenue) { event_costs(:participation_fee) } |
18 | | - let(:expenditure) { event_costs(:transport) } |
| 18 | + let(:expense) { event_costs(:transport) } |
19 | 19 | let(:receipt) { event_cost_receipts(:tankstelle) } |
20 | 20 | let(:form) { described_class.new(report) } |
21 | 21 |
|
|
81 | 81 | expect { form.save }.to change { report.costs.count }.by(-1) |
82 | 82 | end |
83 | 83 |
|
84 | | - it "persists changes to existing expenditure" do |
85 | | - form.expenditures_attributes = { |
| 84 | + it "persists changes to existing expense" do |
| 85 | + form.expenses_attributes = { |
86 | 86 | "0" => { |
87 | | - id: expenditure.id, |
| 87 | + id: expense.id, |
88 | 88 | description: "something else" |
89 | 89 | } |
90 | 90 | } |
91 | 91 |
|
92 | | - expect { form.save }.to change { expenditure.reload.description }.to("something else") |
| 92 | + expect { form.save }.to change { expense.reload.description }.to("something else") |
93 | 93 | end |
94 | 94 |
|
95 | | - it "persists new expenditure" do |
96 | | - form.expenditures_attributes = { |
| 95 | + it "persists new expense" do |
| 96 | + form.expenses_attributes = { |
97 | 97 | "0" => { |
98 | | - description: "New expenditure", |
| 98 | + description: "New expense", |
99 | 99 | count: "2", |
100 | 100 | amount: "75" |
101 | 101 | } |
|
104 | 104 | expect { form.save }.to change { report.costs.where(income: false).count }.by(1) |
105 | 105 | end |
106 | 106 |
|
107 | | - it "destroys expenditure marked for destruction" do |
108 | | - form.expenditures_attributes = { |
| 107 | + it "destroys expense marked for destruction" do |
| 108 | + form.expenses_attributes = { |
109 | 109 | "0" => { |
110 | | - id: expenditure.id, |
| 110 | + id: expense.id, |
111 | 111 | _destroy: "1" |
112 | 112 | } |
113 | 113 | } |
|
162 | 162 | describe "#revenues" do |
163 | 163 | it "returns costs with income true" do |
164 | 164 | expect(form.revenues).to include(revenue) |
165 | | - expect(form.revenues).not_to include(expenditure) |
| 165 | + expect(form.revenues).not_to include(expense) |
166 | 166 | end |
167 | 167 | end |
168 | 168 |
|
169 | | - describe "#expenditures" do |
| 169 | + describe "#expenses" do |
170 | 170 | it "returns costs with income false" do |
171 | | - expect(form.expenditures).to include(expenditure) |
172 | | - expect(form.expenditures).not_to include(revenue) |
| 171 | + expect(form.expenses).to include(expense) |
| 172 | + expect(form.expenses).not_to include(revenue) |
173 | 173 | end |
174 | 174 | end |
175 | 175 |
|
|
227 | 227 | expect(form.revenues.first.errors.full_messages).to match_array ["Bezeichnung muss ausgefüllt werden"] |
228 | 228 | end |
229 | 229 |
|
230 | | - it "is not valid if expenditure is invalid" do |
231 | | - form.expenditures_attributes = { |
| 230 | + it "is not valid if expense is invalid" do |
| 231 | + form.expenses_attributes = { |
232 | 232 | "0" => { |
233 | | - id: expenditure.id, |
| 233 | + id: expense.id, |
234 | 234 | description: "" |
235 | 235 | } |
236 | 236 | } |
237 | 237 |
|
238 | 238 | expect(form).not_to be_valid |
239 | 239 | expect(form.errors.full_messages).to match_array ["Bezeichnung muss ausgefüllt werden"] |
240 | | - expect(form.expenditures.first.errors.full_messages).to match_array ["Bezeichnung muss ausgefüllt werden"] |
| 240 | + expect(form.expenses.first.errors.full_messages).to match_array ["Bezeichnung muss ausgefüllt werden"] |
241 | 241 | end |
242 | 242 |
|
243 | 243 | it "is not valid if receipt is invalid" do |
|
252 | 252 | expect(form.errors.full_messages).to match_array ["Beschreibung muss ausgefüllt werden"] |
253 | 253 | expect(form.receipts.first.errors.full_messages).to match_array ["Beschreibung muss ausgefüllt werden"] |
254 | 254 | end |
| 255 | + |
| 256 | + it "is valid if invalid revenue is marked for destruction" do |
| 257 | + form.revenues_attributes = { |
| 258 | + "0" => { |
| 259 | + id: revenue.id, |
| 260 | + description: "", |
| 261 | + _destroy: "1" |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + expect(form).to be_valid |
| 266 | + end |
255 | 267 | end |
256 | 268 |
|
257 | 269 | describe "#tour_completed?" do |
|
0 commit comments