|
34 | 34 | describe "#render" do |
35 | 35 | let(:project_phase) { build_stubbed(:project_phase) } |
36 | 36 | let(:other_project_phase) { build_stubbed(:project_phase) } |
37 | | - let(:project_phases) { [project_phase, other_project_phase] } |
| 37 | + let(:project_phases) { [project_phase, other_project_phase].compact } |
38 | 38 | let(:project) { build_stubbed(:project, phases: project_phases) } |
39 | 39 | let(:work_package) { build_stubbed(:work_package, project:) } |
40 | 40 | let(:journal) { build_stubbed(:work_package_journal, journable: work_package) } |
41 | 41 | let(:instance) { described_class.new(journal) } |
42 | 42 |
|
43 | 43 | before do |
| 44 | + allow(Project::PhaseDefinition) |
| 45 | + .to receive(:find_by) |
| 46 | + .and_return(nil) |
| 47 | + |
44 | 48 | project_phases.each do |phase| |
45 | 49 | allow(Project::PhaseDefinition) |
46 | 50 | .to receive(:find_by) |
|
173 | 177 |
|
174 | 178 | it_behaves_like "renders project phase definition change" |
175 | 179 | end |
| 180 | + |
| 181 | + context "when setting a phase whose definition is deleted" do |
| 182 | + let(:old_value) { nil } |
| 183 | + let(:new_value) { -1.to_s } |
| 184 | + let(:expected) do |
| 185 | + I18n.t(:text_journal_set_to, |
| 186 | + label: "<strong>Project phase</strong>", |
| 187 | + value: "<i>#{I18n.t(:"activity.project_phase.deleted_project_phase")}</i>") |
| 188 | + end |
| 189 | + |
| 190 | + it_behaves_like "renders project phase definition change" |
| 191 | + end |
| 192 | + |
| 193 | + context "when changing between two phases whose definition is deleted" do |
| 194 | + let(:old_value) { -1.to_s } |
| 195 | + let(:new_value) { -2.to_s } |
| 196 | + let(:expected) do |
| 197 | + I18n.t(:text_journal_changed_plain, |
| 198 | + label: "<strong>Project phase</strong>", |
| 199 | + linebreak: nil, |
| 200 | + old: "<i>#{I18n.t(:"activity.project_phase.deleted_project_phase")}</i>", |
| 201 | + new: "<i>#{I18n.t(:"activity.project_phase.deleted_project_phase")}</i>") |
| 202 | + end |
| 203 | + |
| 204 | + it_behaves_like "renders project phase definition change" |
| 205 | + end |
| 206 | + |
| 207 | + context "when deleting a phase whose definition is deleted" do |
| 208 | + let(:old_value) { -1.to_s } |
| 209 | + let(:new_value) { nil } |
| 210 | + let(:expected) do |
| 211 | + I18n.t(:text_journal_deleted, |
| 212 | + label: "<strong>Project phase</strong>", |
| 213 | + old: "<strike><i>#{I18n.t(:"activity.project_phase.deleted_project_phase")}</i></strike>") |
| 214 | + end |
| 215 | + |
| 216 | + it_behaves_like "renders project phase definition change" |
| 217 | + end |
| 218 | + |
| 219 | + context "when changing between an active and an inactive phase" do |
| 220 | + let(:project_phase) { build_stubbed(:project_phase, active: true) } |
| 221 | + let(:other_project_phase) { build_stubbed(:project_phase, active: false) } |
| 222 | + let(:old_value) { other_project_phase.definition_id.to_s } |
| 223 | + let(:new_value) { project_phase.definition_id.to_s } |
| 224 | + let(:expected) do |
| 225 | + I18n.t(:text_journal_changed_plain, |
| 226 | + label: "<strong>Project phase</strong>", |
| 227 | + linebreak: nil, |
| 228 | + old: "<i>#{other_project_phase.name} (Inactive)</i>", |
| 229 | + new: "<i>#{project_phase.name}</i>") |
| 230 | + end |
| 231 | + |
| 232 | + it_behaves_like "renders project phase definition change" |
| 233 | + end |
| 234 | + |
| 235 | + context "when changing between an active and a phase not configured in the project" do |
| 236 | + let(:project) { build_stubbed(:project, phases: [other_project_phase]) } |
| 237 | + let(:old_value) { other_project_phase.definition_id.to_s } |
| 238 | + let(:new_value) { project_phase.definition_id.to_s } |
| 239 | + let(:expected) do |
| 240 | + I18n.t(:text_journal_changed_plain, |
| 241 | + label: "<strong>Project phase</strong>", |
| 242 | + linebreak: nil, |
| 243 | + old: "<i>#{other_project_phase.name}</i>", |
| 244 | + new: "<i>#{project_phase.name} (Inactive)</i>") |
| 245 | + end |
| 246 | + |
| 247 | + it_behaves_like "renders project phase definition change" |
| 248 | + end |
| 249 | + |
| 250 | + context "when changing between an active and a deleted phase" do |
| 251 | + let(:old_value) { other_project_phase.definition_id.to_s } |
| 252 | + let(:new_value) { -1.to_s } |
| 253 | + let(:expected) do |
| 254 | + I18n.t(:text_journal_changed_plain, |
| 255 | + label: "<strong>Project phase</strong>", |
| 256 | + linebreak: nil, |
| 257 | + old: "<i>#{other_project_phase.name}</i>", |
| 258 | + new: "<i>#{I18n.t(:"activity.project_phase.deleted_project_phase")}</i>") |
| 259 | + end |
| 260 | + |
| 261 | + it_behaves_like "renders project phase definition change" |
| 262 | + end |
176 | 263 | end |
177 | 264 | end |
0 commit comments