-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#235 - Ensure reverse query set creations are scoped to the related r…
…ecord
- Loading branch information
Showing
4 changed files
with
74 additions
and
4 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 |
---|---|---|
|
@@ -15,4 +15,60 @@ describe Marten::DB::Query::RelatedSet do | |
qset.all.to_set.should eq(Set{post_1, post_3}) | ||
end | ||
end | ||
|
||
describe "#create" do | ||
it "creates a new record with the related field set" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id") | ||
|
||
new_post = qset.create(title: "Post") | ||
|
||
new_post.valid?.should be_true | ||
new_post.persisted?.should be_true | ||
new_post.author.should eq user | ||
end | ||
|
||
it "creates a new record with the related field set when a block is used" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id") | ||
|
||
new_post = qset.create do |p| | ||
p.title = "Post" | ||
end | ||
|
||
new_post.valid?.should be_true | ||
new_post.persisted?.should be_true | ||
new_post.author.should eq user | ||
end | ||
end | ||
|
||
describe "#create!" do | ||
it "creates a new record with the related field set" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id") | ||
|
||
new_post = qset.create!(title: "Post") | ||
|
||
new_post.valid?.should be_true | ||
new_post.persisted?.should be_true | ||
new_post.author.should eq user | ||
end | ||
|
||
it "creates a new record with the related field set when a block is used" do | ||
user = TestUser.create!(username: "jd1", email: "[email protected]", first_name: "John", last_name: "Doe") | ||
|
||
qset = Marten::DB::Query::RelatedSet(Post).new(user, "author_id") | ||
|
||
new_post = qset.create! do |p| | ||
p.title = "Post" | ||
end | ||
|
||
new_post.valid?.should be_true | ||
new_post.persisted?.should be_true | ||
new_post.author.should eq user | ||
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
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