-
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.
Add spec for FactoryBurgers::Builder
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "spec_helper" | ||
|
||
describe FactoryBurgers::Builder do | ||
let(:builder) { FactoryBurgers::Builder.new } | ||
|
||
describe "build" do | ||
it "builds a resource" do | ||
user = builder.build(:user, [], {}, nil) | ||
expect(user).to be_persisted | ||
end | ||
|
||
it "can use a trait" do | ||
user = builder.build(:user, [:silly], {}, nil) | ||
expect(user.name.last).to eq("?") | ||
end | ||
|
||
it "can override attributes" do | ||
user = builder.build(:user, [], {name: "Sir Regynald J Bubblesworth"}, nil) | ||
expect(user.name).to eq("Sir Regynald J Bubblesworth") | ||
end | ||
|
||
# This is currently borked | ||
skip "specifying an owner" do | ||
context "when the owner is a belongs_to association" do | ||
it "sets the resource's owner" do | ||
group = Group.create! | ||
user = builder.build(:user, [], {name: "Sir Regynald J Bubblesworth"}, group) | ||
end | ||
end | ||
|
||
context "when the owner is a has_one association" do | ||
it "sets the resource's owner" do | ||
profile = UserProfile.create! | ||
user = builder.build(:user, [], {name: "Sir Regynald J Bubblesworth"}, profile) | ||
end | ||
end | ||
|
||
context "when the owner is a has_many association" do | ||
it "sets the resource's owner" do | ||
post = create :post | ||
user = builder.build(:user, [], {name: "Sir Regynald J Bubblesworth"}, post) | ||
end | ||
end | ||
end | ||
end | ||
end |