Merge branch 'master' of github.com:couchrest/couchrest_model

Conflicts:
	history.md
	lib/couchrest/model/property.rb
This commit is contained in:
Sam Lown 2011-06-08 18:37:00 +02:00
commit 7e054fd948
7 changed files with 79 additions and 8 deletions

View file

@ -6,6 +6,7 @@
* Properties with a nil value are now no longer sent to the database. * Properties with a nil value are now no longer sent to the database.
* Now possible to build new objects via CastedArray#build * Now possible to build new objects via CastedArray#build
* Implement #get! and #find! class methods * Implement #get! and #find! class methods
* Now is possible delete particular elements in casted array(Kostiantyn Kahanskyi)
* Minor fixes * Minor fixes
* #as_json now correctly uses ActiveSupports methods. * #as_json now correctly uses ActiveSupports methods.
@ -20,7 +21,7 @@
* #reload no longer uses Hash#merge! which was causing issues with dirty tracking on casted models. (pointer by kostia) * #reload no longer uses Hash#merge! which was causing issues with dirty tracking on casted models. (pointer by kostia)
* Non-property mass assignment on #new no longer possible without :directly_set_attributes option. * Non-property mass assignment on #new no longer possible without :directly_set_attributes option.
* Using CouchRest 1.1.0.pre3. (No more Hashes!) * Using CouchRest 1.1.0.pre3. (No more Hashes!)
* Fixing problem assigning a CastedHash to a property declared as a Hash (Kostiantyn Kahanskyi, gfmtim)
## 1.1.0.beta5 - 2011-04-30 ## 1.1.0.beta5 - 2011-04-30

View file

@ -50,6 +50,16 @@ module CouchRest::Model
super super
end end
def delete(obj)
couchrest_parent_will_change! if use_dirty? && self.length > 0
super(obj)
end
def delete_at(index)
couchrest_parent_will_change! if use_dirty? && self.length > 0
super(index)
end
def build(*args) def build(*args)
obj = casted_by_property.build(*args) obj = casted_by_property.build(*args)
self.push(obj) self.push(obj)

View file

@ -244,6 +244,7 @@ module CouchRest
else else
options = { :limit => per_page, :skip => per_page * (page - 1) } options = { :limit => per_page, :skip => per_page * (page - 1) }
end end
options[:include_docs] = true
view_options.merge(options) view_options.merge(options)
end end

View file

@ -27,21 +27,20 @@ describe "Collections" do
end end
it "should provide a class method for paginate" do it "should provide a class method for paginate" do
articles = Article.paginate(:design_doc => 'Article', :view_name => 'by_date', articles = Article.paginate(:design_doc => 'Article', :view_name => 'by_date',
:per_page => 3, :descending => true, :key => Date.today, :include_docs => true) :per_page => 3, :descending => true, :key => Date.today)
articles.size.should == 3 articles.size.should == 3
articles = Article.paginate(:design_doc => 'Article', :view_name => 'by_date', articles = Article.paginate(:design_doc => 'Article', :view_name => 'by_date',
:per_page => 3, :page => 2, :descending => true, :key => Date.today, :include_docs => true) :per_page => 3, :page => 2, :descending => true, :key => Date.today)
articles.size.should == 3 articles.size.should == 3
articles = Article.paginate(:design_doc => 'Article', :view_name => 'by_date', articles = Article.paginate(:design_doc => 'Article', :view_name => 'by_date',
:per_page => 3, :page => 3, :descending => true, :key => Date.today, :include_docs => true) :per_page => 3, :page => 3, :descending => true, :key => Date.today)
articles.size.should == 1 articles.size.should == 1
end end
it "should provide a class method for paginated_each" do it "should provide a class method for paginated_each" do
options = { :design_doc => 'Article', :view_name => 'by_date', options = { :design_doc => 'Article', :view_name => 'by_date',
:per_page => 3, :page => 1, :descending => true, :key => Date.today, :per_page => 3, :page => 1, :descending => true, :key => Date.today }
:include_docs => true }
Article.paginated_each(options) do |a| Article.paginated_each(options) do |a|
a.should_not be_nil a.should_not be_nil
end end

View file

@ -257,6 +257,50 @@ describe "Dirty" do
end end
end end
it "should report changes on deletion from an array" do
should_change_array do |array, obj|
array << "keyword"
obj.save!
array.delete_at(0)
end
should_change_array do |array, obj|
array << "keyword"
obj.save!
array.delete("keyword")
end
end
it "should report changes on deletion from an array after reload" do
should_change_array do |array, obj|
array << "keyword"
obj.save!
obj.reload
array.delete_at(0)
end
should_change_array do |array, obj|
array << "keyword"
obj.save!
obj.reload
array.delete("keyword")
end
end
it "should report no changes on deletion from an empty array" do
should_not_change_array do |array, obj|
array.clear
obj.save!
array.delete_at(0)
end
should_not_change_array do |array, obj|
array.clear
obj.save!
array.delete("keyword")
end
end
it "should report changes if an array is pushed" do it "should report changes if an array is pushed" do
should_change_array do |array, obj| should_change_array do |array, obj|
array.push("keyword") array.push("keyword")

View file

@ -9,6 +9,7 @@ require File.join(FIXTURE_PATH, 'more', 'service')
require File.join(FIXTURE_PATH, 'more', 'event') require File.join(FIXTURE_PATH, 'more', 'event')
require File.join(FIXTURE_PATH, 'more', 'user') require File.join(FIXTURE_PATH, 'more', 'user')
require File.join(FIXTURE_PATH, 'more', 'course') require File.join(FIXTURE_PATH, 'more', 'course')
require File.join(FIXTURE_PATH, "more", "key_chain")
describe "Model properties" do describe "Model properties" do
@ -239,6 +240,16 @@ describe "Model properties" do
end end
describe "properties of hash of casted models" do
it "should be able to assign a casted hash to a hash property" do
chain = KeyChain.new
keys = {"House" => "8==$", "Office" => "<>==U"}
chain.keys = keys
chain.keys = chain.keys
chain.keys.should == keys
end
end
describe "properties of array of casted models" do describe "properties of array of casted models" do
before(:each) do before(:each) do

5
spec/fixtures/more/key_chain.rb vendored Normal file
View file

@ -0,0 +1,5 @@
class KeyChain < CouchRest::Model::Base
use_database(DB)
property(:keys, Hash)
end