-
Notifications
You must be signed in to change notification settings - Fork 0
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
257 additions
and
193 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,36 @@ | ||
Feature: belongs_to association | ||
|
||
|
||
Background: | ||
Given the default Recliner::Document database is set to "http://localhost:5984/recliner-features" | ||
And the database "http://localhost:5984/recliner-features" exists | ||
And the following document definitions: | ||
""" | ||
class User < Recliner::Document | ||
end | ||
class Article < Recliner::Document | ||
belongs_to :author | ||
end | ||
""" | ||
|
||
Scenario: assigning instance to association | ||
Given I have a saved instance of "User" with id "user-1" | ||
And I have a saved instance of "Article" with id "article-1" | ||
When I set its author to the "User" with id "user-1" | ||
Then its "author" should be the "User" with id "user-1" | ||
|
||
Scenario: assigning id to association | ||
Given I have a saved instance of "User" with id "user-1" | ||
And I have a saved instance of "Article" with id "article-1" | ||
When I set its author_id to "user-1" | ||
Then its "author" should be the "User" with id "user-1" | ||
|
||
Scenario: loading association | ||
Given I have a saved instance of "User" with id "user-1" | ||
And I have a saved instance of "Article" with attributes: | ||
| id | article-1 | | ||
| author_id | user-1 | | ||
When I load the "Article" instance with id "article-1" | ||
Then its "author" should be the "User" with id "user-1" | ||
|
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,8 @@ | ||
When /^I set its (\w+) to the "([^\"]*)" with id "([^\"]*)"$/ do |association, model, id| | ||
@instance.send("#{association}=", model.constantize.load!(id)) | ||
end | ||
|
||
Then /^its "([^\"]*)" should be the "([^\"]*)" with id "([^\"]*)"$/ do |association, model, id| | ||
@instance.send(association).should be_an_instance_of(model.constantize) | ||
@instance.send(association).id.should == id | ||
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
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
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,40 @@ | ||
module Recliner | ||
module Associations | ||
class Reference | ||
attr_reader :id | ||
|
||
def initialize(id=nil) | ||
@id = id | ||
end | ||
|
||
def ==(other) | ||
other.is_a?(Reference) && id == other.id | ||
end | ||
|
||
def self.from_couch(id) | ||
new(id) | ||
end | ||
|
||
def self.parse(id) | ||
new(id) | ||
end | ||
|
||
def to_couch | ||
id | ||
end | ||
|
||
def inspect | ||
id.nil? ? 'nil' : id | ||
end | ||
|
||
def replace(object) | ||
@id = object.id | ||
@target = object | ||
end | ||
|
||
def target | ||
@target ||= Recliner::Document.load!(id) if id | ||
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
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
Oops, something went wrong.