Adding tests to some expected behaviors
This commit is contained in:
parent
e3386a45f4
commit
1a551b54eb
|
@ -2,7 +2,7 @@ module CouchRest
|
|||
module Model
|
||||
module Associations
|
||||
|
||||
# Basic support for relationships between ExtendedDocuments
|
||||
# Basic support for relationships between CouchRest::Model::Base
|
||||
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
|
@ -175,14 +175,17 @@ module CouchRest
|
|||
end
|
||||
super(array)
|
||||
end
|
||||
|
||||
def << obj
|
||||
casted_by[property.to_s] << obj.id
|
||||
super(obj)
|
||||
end
|
||||
|
||||
def push(obj)
|
||||
casted_by[property.to_s].push obj.id
|
||||
super(obj)
|
||||
end
|
||||
|
||||
def unshift(obj)
|
||||
casted_by[property.to_s].unshift obj.id
|
||||
super(obj)
|
||||
|
@ -197,6 +200,7 @@ module CouchRest
|
|||
casted_by[property.to_s].pop
|
||||
super
|
||||
end
|
||||
|
||||
def shift
|
||||
casted_by[property.to_s].shift
|
||||
super
|
||||
|
|
|
@ -1,31 +1,6 @@
|
|||
# encoding: utf-8
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
class Client < CouchRest::Model::Base
|
||||
use_database DB
|
||||
|
||||
property :name
|
||||
property :tax_code
|
||||
end
|
||||
|
||||
class SaleEntry < CouchRest::Model::Base
|
||||
use_database DB
|
||||
|
||||
property :description
|
||||
property :price
|
||||
end
|
||||
|
||||
class SaleInvoice < CouchRest::Model::Base
|
||||
use_database DB
|
||||
|
||||
belongs_to :client
|
||||
belongs_to :alternate_client, :class_name => 'Client', :foreign_key => 'alt_client_id'
|
||||
|
||||
collection_of :entries, :class_name => 'SaleEntry'
|
||||
|
||||
property :date, Date
|
||||
property :price, Integer
|
||||
end
|
||||
require File.join(FIXTURE_PATH, 'more', 'sale_invoice')
|
||||
|
||||
|
||||
describe "Assocations" do
|
||||
|
@ -159,7 +134,7 @@ describe "Assocations" do
|
|||
end
|
||||
|
||||
describe "proxy" do
|
||||
|
||||
|
||||
it "should ensure new entries to proxy are matched" do
|
||||
@invoice.entries << @entries.first
|
||||
@invoice.entry_ids.first.should eql(@entries.first.id)
|
||||
|
@ -202,12 +177,17 @@ describe "Assocations" do
|
|||
@invoice.entries.first.should eql(@entries[1])
|
||||
@invoice.entry_ids.first.should eql(@entries[1].id)
|
||||
end
|
||||
|
||||
|
||||
it "should save all entries when invoice is saved" do
|
||||
SaleEntry.find_by_description('test entry').should be_nil
|
||||
entry = SaleEntry.new(:description => 'test entry', :price => 500)
|
||||
@invoice.entries << entry
|
||||
@invoice.save.should be_true
|
||||
SaleEntry.find_by_description('test entry').should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
6
spec/fixtures/more/client.rb
vendored
Normal file
6
spec/fixtures/more/client.rb
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
class Client < CouchRest::Model::Base
|
||||
use_database DB
|
||||
|
||||
property :name
|
||||
property :tax_code
|
||||
end
|
9
spec/fixtures/more/sale_entry.rb
vendored
Normal file
9
spec/fixtures/more/sale_entry.rb
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
class SaleEntry < CouchRest::Model::Base
|
||||
use_database DB
|
||||
|
||||
property :description
|
||||
property :price
|
||||
|
||||
view_by :description
|
||||
|
||||
end
|
13
spec/fixtures/more/sale_invoice.rb
vendored
Normal file
13
spec/fixtures/more/sale_invoice.rb
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.join(FIXTURE_PATH, 'more', 'client')
|
||||
require File.join(FIXTURE_PATH, 'more', 'sale_entry')
|
||||
class SaleInvoice < CouchRest::Model::Base
|
||||
use_database DB
|
||||
|
||||
belongs_to :client
|
||||
belongs_to :alternate_client, :class_name => 'Client', :foreign_key => 'alt_client_id'
|
||||
|
||||
collection_of :entries, :class_name => 'SaleEntry'
|
||||
|
||||
property :date, Date
|
||||
property :price, Integer
|
||||
end
|
Loading…
Reference in a new issue