Merge branch 'master' of github.com:couchrest/couchrest_model
Conflicts: history.md lib/couchrest/model/property.rb
This commit is contained in:
commit
7e054fd948
|
@ -6,6 +6,7 @@
|
|||
* Properties with a nil value are now no longer sent to the database.
|
||||
* Now possible to build new objects via CastedArray#build
|
||||
* Implement #get! and #find! class methods
|
||||
* Now is possible delete particular elements in casted array(Kostiantyn Kahanskyi)
|
||||
|
||||
* Minor fixes
|
||||
* #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)
|
||||
* Non-property mass assignment on #new no longer possible without :directly_set_attributes option.
|
||||
* 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
|
||||
|
||||
|
|
|
@ -50,6 +50,16 @@ module CouchRest::Model
|
|||
super
|
||||
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)
|
||||
obj = casted_by_property.build(*args)
|
||||
self.push(obj)
|
||||
|
|
|
@ -244,6 +244,7 @@ module CouchRest
|
|||
else
|
||||
options = { :limit => per_page, :skip => per_page * (page - 1) }
|
||||
end
|
||||
options[:include_docs] = true
|
||||
view_options.merge(options)
|
||||
end
|
||||
|
||||
|
|
|
@ -27,21 +27,20 @@ describe "Collections" do
|
|||
end
|
||||
it "should provide a class method for paginate" do
|
||||
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 = 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 = 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
|
||||
end
|
||||
it "should provide a class method for paginated_each" do
|
||||
options = { :design_doc => 'Article', :view_name => 'by_date',
|
||||
:per_page => 3, :page => 1, :descending => true, :key => Date.today,
|
||||
:include_docs => true }
|
||||
:per_page => 3, :page => 1, :descending => true, :key => Date.today }
|
||||
Article.paginated_each(options) do |a|
|
||||
a.should_not be_nil
|
||||
end
|
||||
|
|
|
@ -257,6 +257,50 @@ describe "Dirty" do
|
|||
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
|
||||
should_change_array do |array, obj|
|
||||
array.push("keyword")
|
||||
|
|
|
@ -9,6 +9,7 @@ require File.join(FIXTURE_PATH, 'more', 'service')
|
|||
require File.join(FIXTURE_PATH, 'more', 'event')
|
||||
require File.join(FIXTURE_PATH, 'more', 'user')
|
||||
require File.join(FIXTURE_PATH, 'more', 'course')
|
||||
require File.join(FIXTURE_PATH, "more", "key_chain")
|
||||
|
||||
|
||||
describe "Model properties" do
|
||||
|
@ -239,6 +240,16 @@ describe "Model properties" do
|
|||
|
||||
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
|
||||
|
||||
before(:each) do
|
||||
|
|
5
spec/fixtures/more/key_chain.rb
vendored
Normal file
5
spec/fixtures/more/key_chain.rb
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
class KeyChain < CouchRest::Model::Base
|
||||
use_database(DB)
|
||||
|
||||
property(:keys, Hash)
|
||||
end
|
Loading…
Reference in a new issue