-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
301 additions
and
23 deletions.
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
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 |
---|---|---|
@@ -1,2 +1,13 @@ | ||
class CreateGroup < StandardInteraction | ||
def validate_input | ||
context.fail!(errors: "invalid input") unless context.group_params | ||
end | ||
|
||
def execute | ||
context.group = context.user.groups.create(context.group_params) | ||
end | ||
|
||
def validate_output | ||
context.fail!(errors: context.group.errors) unless context.group.persisted? | ||
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
class DeleteGroup | ||
include Interactor | ||
class DeleteGroup < StandardInteraction | ||
def validate_input | ||
context.fail!(errors: "invalid input") unless context.id | ||
end | ||
|
||
def execute | ||
context.group = Group.destroy(context.id) | ||
end | ||
|
||
def validate_output | ||
context.fail!(errors: "group not deleted") unless context.group.destroyed? | ||
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
class ShowGroup | ||
include Interactor | ||
class ShowGroup < StandardInteraction | ||
def validate_input | ||
context.fail!(errors: "invalid input") unless context.id | ||
end | ||
|
||
def execute | ||
context.group = Group.find_by(id: context.id) | ||
end | ||
|
||
def validate_output | ||
context.fail!(errors: "invalid output") unless context.group | ||
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 |
---|---|---|
@@ -1,3 +1,19 @@ | ||
class UpdateGroup | ||
include Interactor | ||
class UpdateGroup < StandardInteraction | ||
def validate_input | ||
context.fail!(errors: "invalid input") unless valid_input? | ||
end | ||
|
||
def execute | ||
context.fail!(errors: "group update failed") unless update_group | ||
end | ||
|
||
private | ||
|
||
def update_group | ||
Group.update(context.id, context.group_params) | ||
end | ||
|
||
def valid_input? | ||
context.group_params && context.id | ||
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
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
FactoryGirl.define do | ||
factory :group do | ||
name Faker::Hipster.words(2) | ||
name Faker::Team.name | ||
city Faker::Address.city | ||
state Faker::Address.state | ||
country Faker::Address.country | ||
facebook Faker::Internet.url("facebook.com") | ||
twitter Faker::Internet.url("twitter.com") | ||
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,60 @@ | ||
RSpec.describe CreateGroup do | ||
describe ".call" do | ||
let(:user) do | ||
create(:confirmed_user) | ||
end | ||
|
||
let(:group_params) do | ||
{ | ||
name: "Weasley's Kneesleys", | ||
city: "Baltimore", | ||
state: "MD", | ||
country: "USA", | ||
facebook: "http://facebook.com/weasley", | ||
twitter: "http://twitter.com/weasley" | ||
} | ||
end | ||
|
||
subject do | ||
described_class.call(user: user, group_params: group_params) | ||
end | ||
|
||
context "when successful" do | ||
it "returns a successful context" do | ||
is_expected.to be_a_success | ||
end | ||
|
||
it "creates a new group" do | ||
expect(subject.group).to be_a Group | ||
end | ||
end | ||
|
||
context "when group is not saved" do | ||
before do | ||
group_params["name"] = "" | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors.messages).to eq(name: ["can't be blank"]) | ||
end | ||
end | ||
|
||
context "when invalid input is provided" do | ||
subject do | ||
described_class.call(group_params: nil) | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors).to eq("invalid input") | ||
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,51 @@ | ||
RSpec.describe DeleteGroup do | ||
describe ".call" do | ||
let(:group) { create(:group) } | ||
|
||
context "when successful" do | ||
subject do | ||
described_class.call(id: group.id) | ||
end | ||
|
||
it "returns a successful context" do | ||
is_expected.to be_a_success | ||
end | ||
|
||
it "deletes the group record" do | ||
expect(subject.group.destroyed?).to be_truthy | ||
end | ||
end | ||
|
||
context "when group id is invalid" do | ||
subject do | ||
described_class.call(id: nil) | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors).to eq("invalid input") | ||
end | ||
end | ||
|
||
context "when destroy fails" do | ||
before do | ||
allow_any_instance_of(Group).to receive(:destroyed?).and_return(false) | ||
end | ||
|
||
subject do | ||
described_class.call(id: group.id) | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors).to eq("group not deleted") | ||
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,47 @@ | ||
RSpec.describe ShowGroup do | ||
describe ".call" do | ||
let(:group) { create(:group, id: 876) } | ||
|
||
context "when successful" do | ||
subject do | ||
described_class.call(id: group.id) | ||
end | ||
|
||
it "returns a successful context" do | ||
is_expected.to be_a_success | ||
end | ||
|
||
it "returns a valid group record" do | ||
expect(subject.group).to be_a Group | ||
end | ||
end | ||
|
||
context "when invalid id is provided" do | ||
subject do | ||
described_class.call(id: nil) | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors).to eq("invalid input") | ||
end | ||
end | ||
|
||
context "when a Group was not found" do | ||
subject do | ||
described_class.call(id: 9999) | ||
end | ||
|
||
it "fails" do | ||
is_expected.to be_a_failure | ||
end | ||
|
||
it "returns an error" do | ||
expect(subject.errors).to eq("invalid output") | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.