From 53cedd2d6f4ed3e179ffeaf3b143d5fab788785a Mon Sep 17 00:00:00 2001 From: Lance Carlson Date: Mon, 28 Jan 2008 05:30:09 +0000 Subject: [PATCH] Patching up specs for new relationship code --- sequel_model/lib/sequel_model/relationships.rb | 10 +++++----- .../relationships/abstract_relationship.rb | 7 +++---- .../spec/relationships/abstract_relationship_spec.rb | 4 ++-- sequel_model/spec/relationships_spec.rb | 4 +++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sequel_model/lib/sequel_model/relationships.rb b/sequel_model/lib/sequel_model/relationships.rb index 19f4631074..38b40ef90f 100644 --- a/sequel_model/lib/sequel_model/relationships.rb +++ b/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))} @@ -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 @@ -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 diff --git a/sequel_model/lib/sequel_model/relationships/abstract_relationship.rb b/sequel_model/lib/sequel_model/relationships/abstract_relationship.rb index b12cda64f4..0dc179b9c1 100644 --- a/sequel_model/lib/sequel_model/relationships/abstract_relationship.rb +++ b/sequel_model/lib/sequel_model/relationships/abstract_relationship.rb @@ -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 @@ -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 \ No newline at end of file diff --git a/sequel_model/spec/relationships/abstract_relationship_spec.rb b/sequel_model/spec/relationships/abstract_relationship_spec.rb index 0883c52908..f368f93dbd 100644 --- a/sequel_model/spec/relationships/abstract_relationship_spec.rb +++ b/sequel_model/spec/relationships/abstract_relationship_spec.rb @@ -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 diff --git a/sequel_model/spec/relationships_spec.rb b/sequel_model/spec/relationships_spec.rb index 920e23279d..1b58a9feb9 100644 --- a/sequel_model/spec/relationships_spec.rb +++ b/sequel_model/spec/relationships_spec.rb @@ -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