Skip to content

Commit

Permalink
Patching up specs for new relationship code
Browse files Browse the repository at this point in the history
  • Loading branch information
lancecarlson committed Jan 28, 2008
1 parent 2ebaa1e commit 53cedd2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
10 changes: 5 additions & 5 deletions sequel_model/lib/sequel_model/relationships.rb
@@ -1,5 +1,5 @@
files = %w[
block has_n_relationship join_table
abstract_relationship block join_table
]
dir = File.join(File.dirname(__FILE__), "relationships")
files.each {|f| require(File.join(dir, f))}
Expand Down Expand Up @@ -87,9 +87,9 @@ def has(arity, relation, options = {})

# Create and store the relationship
case arity
when :one : HasOneRelationship.new(self, arity, relation, options).create
when :many : HasManyRelationship.new(self, arity, relation, options).create
else Sequel::Error, "Arity must be specified {:one, :many}."
when :one : HasOneRelationship.new(self, relation, options).create
when :many : HasManyRelationship.new(self, relation, options).create
else raise Sequel::Error, "Arity must be specified {:one, :many}."
end
#unless normalized
# :required => true # The relationship must be populated to save
Expand All @@ -108,7 +108,7 @@ def has_many(relation, options = {})
end

def belongs_to(relation, options = {})
BelongsToRelationship.new(self, arity, relation, options).create
BelongsToRelationship.new(self, relation, options).create
end

end
Expand Down
Expand Up @@ -5,11 +5,10 @@ class Model
# HasOneRelationship.new Post, :one, :comments
class AbstractRelationship

attr_reader :klass, :arity, :relation, :options
attr_reader :klass, :relation, :options

def initialize(klass, arity, relation, options)
def initialize(klass, relation, options)
@klass = klass
@arity = arity
@relation = relation
@options = options
end
Expand Down Expand Up @@ -49,6 +48,6 @@ def relation_class

class HasOneRelationship < AbstractRelationship; end
class HasManyRelationship < AbstractRelationship; end
class BelognsToRelationship < HasOneRelationship; end
class BelongsToRelationship < HasOneRelationship; end
end
end
4 changes: 2 additions & 2 deletions sequel_model/spec/relationships/abstract_relationship_spec.rb
Expand Up @@ -4,8 +4,8 @@
describe "intance methods" do
before :each do
class Post; end
@one = Sequel::Model::AbstractRelationship.new Post, :one, :author, {}
@many = Sequel::Model::AbstractRelationship.new Post, :many, :comments, {:force => true}
@one = Sequel::Model::HasOneRelationship.new Post, :author, {}
@many = Sequel::Model::HasManyRelationship.new Post, :comments, {:force => true}
@join_table = mock(Sequel::Model::JoinTable)
end

Expand Down
4 changes: 3 additions & 1 deletion sequel_model/spec/relationships_spec.rb
Expand Up @@ -37,7 +37,9 @@ class User < Sequel::Model; end

describe "belongs_to" do
it "should pass arguments to has :one" do
User.should_receive(:has).with(:one, :boss, {}).and_return(true)
@belongs_to_relationship = mock(Sequel::Model::BelongsToRelationship)
@belongs_to_relationship.should_receive(:create)
Sequel::Model::BelongsToRelationship.should_receive(:new).with(User, :boss, {}).and_return(@belongs_to_relationship)
User.send(:belongs_to, :boss)
end
end
Expand Down

0 comments on commit 53cedd2

Please sign in to comment.