-
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.
#236 - Make it possible to initialize new Model instances from query …
…sets
- Loading branch information
Showing
4 changed files
with
92 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
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 |
---|---|---|
|
@@ -16,6 +16,34 @@ describe Marten::DB::Query::RelatedSet do | |
end | ||
end | ||
|
||
describe "#build" do | ||
it "initializes 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.build(title: "Post") | ||
|
||
new_post.persisted?.should be_false | ||
new_post.author.should eq user | ||
new_post.title.should eq "Post" | ||
end | ||
|
||
it "initializes 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.build do |p| | ||
p.title = "Post" | ||
end | ||
|
||
new_post.persisted?.should be_false | ||
new_post.author.should eq user | ||
new_post.title.should eq "Post" | ||
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") | ||
|
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