forked from fs/task_tracker_itis_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added tests for destroy & update * rubocop fix * gitignore fix * minor changes
- Loading branch information
1 parent
e9763ff
commit 11cd4e5
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,5 @@ yarn-debug.log* | |
.idea/ | ||
|
||
.env | ||
|
||
/dump.rdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
factory :user do | ||
first_name { "test" } | ||
last_name { "test" } | ||
email { "[email protected]" } | ||
sequence(:email) { |n| Faker::Internet.email.gsub("@", "-#{n}@") } | ||
role { "member" } | ||
password { "123456" } | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "rails_helper" | ||
|
||
describe Projects::Destroy do | ||
describe ".call" do | ||
let(:interactor) { described_class.new(project: project, users: users) } | ||
let!(:project) { create(:project) } | ||
let!(:users) { create_list(:user, 3, projects: [project]) } | ||
|
||
it "destroys the project" do | ||
expect { interactor.run }.to change(Project, :count).from(1).to(0) | ||
end | ||
|
||
it "sends project destruction emails to all users" do | ||
allow(ProjectMailer).to receive(:project_destroyed).and_call_original | ||
interactor.run | ||
|
||
users.each do |user| | ||
expect(ProjectMailer).to have_received(:project_destroyed).with(user).once | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "rails_helper" | ||
|
||
describe Projects::Update do # rubocop:disable Metrics/BlockLength | ||
describe ".call" do | ||
let(:interactor) { described_class.new(context) } | ||
let!(:project) { create(:project) } | ||
let!(:users) { create_list(:user, 3, projects: [project]) } | ||
|
||
context "when project update is successful" do | ||
let(:context) { { project: project, project_params: { name: "New Name" } } } | ||
|
||
it "updates the project" do | ||
interactor.run | ||
expect(project.reload.name).to eq("New Name") | ||
end | ||
|
||
it "sends project update emails to all users" do | ||
allow(ProjectMailer).to receive(:project_updated).and_call_original | ||
interactor.run | ||
|
||
users.each do |user| | ||
expect(ProjectMailer).to have_received(:project_updated).with(project, user).once | ||
end | ||
end | ||
end | ||
|
||
context "when project update fails" do | ||
let(:context) { { project: project, project_params: { name: "" } } } | ||
|
||
it "fails the context with an error message" do | ||
interactor.run | ||
expect(interactor.context.failure?).to be true | ||
expect(interactor.context.error).to eq("Invalid data") | ||
end | ||
end | ||
end | ||
end |