-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
1 parent
e8a1600
commit ad803ca
Showing
2 changed files
with
61 additions
and
35 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 |
---|---|---|
|
@@ -1029,35 +1029,61 @@ class Admin < ROM::Struct | |
|
||
context "using associations" do | ||
context "with traits" do | ||
before do | ||
factories.define(:user) do |f| | ||
f.first_name "Jane" | ||
f.last_name "Doe" | ||
f.email "[email protected]" | ||
f.timestamps | ||
f.association(:tasks, :important, count: 2) | ||
end | ||
context "sequential" do | ||
before do | ||
factories.define(:user) do |f| | ||
f.first_name "Jane" | ||
f.last_name "Doe" | ||
f.email "[email protected]" | ||
f.timestamps | ||
f.association(:tasks, :important, count: 2) | ||
end | ||
|
||
factories.define(:task) do |f| | ||
f.sequence(:title) { |n| "Task #{n}" } | ||
f.trait :important do |t| | ||
t.sequence(:title) { |n| "Important Task #{n}" } | ||
factories.define(:task) do |f| | ||
f.sequence(:title) { |n| "Task #{n}" } | ||
f.trait :important do |t| | ||
t.sequence(:title) { |n| "Important Task #{n}" } | ||
end | ||
end | ||
end | ||
end | ||
|
||
it "creates associated records with the given trait" do | ||
user = factories[:user] | ||
it "creates associated records with the given trait" do | ||
user = factories[:user] | ||
|
||
expect(user.tasks.count).to be(2) | ||
expect(user.tasks.count).to be(2) | ||
|
||
t1, t2 = user.tasks | ||
t1, t2 = user.tasks | ||
|
||
expect(t1.user_id).to be(user.id) | ||
expect(t1.title).to eql("Important Task 1") | ||
expect(t1.user_id).to be(user.id) | ||
expect(t1.title).to eql("Important Task 1") | ||
|
||
expect(t2.user_id).to be(user.id) | ||
expect(t2.title).to eql("Important Task 2") | ||
end | ||
end | ||
|
||
context "keyword" do | ||
before do | ||
factories.define(:user) do |f| | ||
f.first_name "Jane" | ||
f.last_name "Doe" | ||
f.email "[email protected]" | ||
f.timestamps | ||
f.association(:tasks, count: 2, traits: [:important]) | ||
end | ||
|
||
expect(t2.user_id).to be(user.id) | ||
expect(t2.title).to eql("Important Task 2") | ||
factories.define(:task) do |f| | ||
f.sequence(:title) { |n| "Task #{n}" } | ||
f.trait :important do |t| | ||
t.sequence(:title) { |n| "Important Task #{n}" } | ||
end | ||
end | ||
end | ||
|
||
it "creates associated records with the given trait" do | ||
user = factories[:user] | ||
expect(user.tasks.count).to be(2) | ||
end | ||
end | ||
end | ||
|
||
|