Created
October 31, 2009 08:58
-
-
Save lennart/222994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/couch_potato/view/model_view_spec.rb b/lib/couch_potato/view/model_view_spec.rb | |
index 844d6e0..fe11779 100644 | |
--- a/lib/couch_potato/view/model_view_spec.rb | |
+++ b/lib/couch_potato/view/model_view_spec.rb | |
@@ -18,7 +18,7 @@ module CouchPotato | |
def map_function | |
"function(doc) { | |
- if(doc.ruby_class && doc.ruby_class == '#{@klass.name}') { | |
+ if(doc.#{JSON.create_id} && doc.#{JSON.create_id} == '#{@klass.name}') { | |
emit(#{formatted_key(key)}, null); | |
} | |
}" | |
@@ -58,4 +58,4 @@ module CouchPotato | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/lib/couch_potato/view/properties_view_spec.rb b/lib/couch_potato/view/properties_view_spec.rb | |
index 86d5cf0..3e7e8ad 100644 | |
--- a/lib/couch_potato/view/properties_view_spec.rb | |
+++ b/lib/couch_potato/view/properties_view_spec.rb | |
@@ -7,7 +7,7 @@ module CouchPotato | |
class PropertiesViewSpec < ModelViewSpec | |
def map_function | |
"function(doc) { | |
- if(doc.ruby_class && doc.ruby_class == '#{@klass.name}') { | |
+ if(doc.#{JSON.create_id} && doc.#{JSON.create_id} == '#{@klass.name}') { | |
emit(#{formatted_key(key)}, #{properties_for_map(properties)}); | |
} | |
}" | |
@@ -36,4 +36,4 @@ module CouchPotato | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/spec/create_spec.rb b/spec/create_spec.rb | |
index 43eb5da..7293826 100644 | |
--- a/spec/create_spec.rb | |
+++ b/spec/create_spec.rb | |
@@ -8,7 +8,7 @@ describe "create" do | |
it "should store the class" do | |
@comment = Comment.new :title => 'my_title' | |
CouchPotato.database.save_document! @comment | |
- CouchPotato.couchrest_database.get(@comment.id).ruby_class.should == 'Comment' | |
+ CouchPotato.couchrest_database.get(@comment.id).method(JSON.create_id).call.should == 'Comment' | |
end | |
end | |
describe "fails" do | |
diff --git a/spec/custom_view_spec.rb b/spec/custom_view_spec.rb | |
index d154708..a870a1d 100644 | |
--- a/spec/custom_view_spec.rb | |
+++ b/spec/custom_view_spec.rb | |
@@ -39,7 +39,7 @@ describe 'view' do | |
CouchPotato.database.view Build.timeline(:key => 1) | |
end | |
- it "should not return documents that don't have a matching ruby_class" do | |
+ it "should not return documents that don't have a matching JSON.create_id" do | |
CouchPotato.couchrest_database.save_doc({:time => 'x'}) | |
CouchPotato.database.view(Build.timeline).should == [] | |
end | |
@@ -55,24 +55,24 @@ describe 'view' do | |
describe "properties defined" do | |
it "should assign the configured properties" do | |
- CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', :ruby_class => 'Build') | |
+ CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build') | |
CouchPotato.database.view(Build.minimal_timeline).first.state.should == 'success' | |
end | |
it "should not assign the properties not configured" do | |
- CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', :ruby_class => 'Build') | |
+ CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build') | |
CouchPotato.database.view(Build.minimal_timeline).first.time.should be_nil | |
end | |
it "should assign the id even if it is not configured" do | |
- id = CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', :ruby_class => 'Build')['id'] | |
+ id = CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')['id'] | |
CouchPotato.database.view(Build.minimal_timeline).first._id.should == id | |
end | |
end | |
describe "no properties defined" do | |
it "should assign all properties to the objects by default" do | |
- id = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', :ruby_class => 'Build'})['id'] | |
+ id = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build'})['id'] | |
result = CouchPotato.database.view(Build.timeline).first | |
result.state.should == 'success' | |
result.time.should == '2008-01-01' | |
@@ -112,8 +112,8 @@ describe 'view' do | |
CouchPotato.database.view(Build.custom_timeline_returns_docs).map(&:state).should == ['success'] | |
end | |
- it "should still return instance of class if document included 'ruby_class'" do | |
- CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', :ruby_class => "Build"}) | |
+ it "should still return instance of class if document included JSON.create_id" do | |
+ CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => "Build"}) | |
view_data = CouchPotato.database.view(Build.custom_timeline_returns_docs) | |
view_data.map(&:class).should == [Build] | |
view_data.map(&:state).should == ['success'] | |
@@ -163,4 +163,4 @@ describe 'view' do | |
CouchPotato.database.view(CustomBuild.timeline).first.should be_kind_of(CustomBuild) | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb | |
index c476d41..cb436c2 100644 | |
--- a/spec/spec_helper.rb | |
+++ b/spec/spec_helper.rb | |
@@ -24,8 +24,7 @@ class Comment | |
end | |
def recreate_db | |
- CouchPotato.couchrest_database.delete! rescue nil | |
- CouchPotato.couchrest_database.server.create_db CouchPotato::Config.database_name | |
+ CouchPotato.couchrest_database.recreate! | |
end | |
recreate_db | |
diff --git a/spec/unit/attributes_spec.rb b/spec/unit/attributes_spec.rb | |
index 60e28d0..ffd5ea1 100644 | |
--- a/spec/unit/attributes_spec.rb | |
+++ b/spec/unit/attributes_spec.rb | |
@@ -25,12 +25,12 @@ describe "attributes" do | |
# useful when loading models from custom views | |
describe "accessing ghost attributes" do | |
it "should allow me to access attributes that are in the couchdb document but not defined as a property" do | |
- plant = Plant.json_create({"ruby_class" => "Plant", "color" => "red", "leaf_count" => 1}) | |
+ plant = Plant.json_create({JSON.create_id => "Plant", "color" => "red", "leaf_count" => 1}) | |
plant.color.should == 'red' | |
end | |
it "should raise a no method error when trying to read attributes that are not in the document" do | |
- plant = Plant.json_create({"ruby_class" => "Plant", "leaf_count" => 1}) | |
+ plant = Plant.json_create({JSON.create_id => "Plant", "leaf_count" => 1}) | |
lambda do | |
plant.length | |
end.should raise_error(NoMethodError) | |
diff --git a/spec/unit/database_spec.rb b/spec/unit/database_spec.rb | |
index 00508f1..b403f33 100644 | |
--- a/spec/unit/database_spec.rb | |
+++ b/spec/unit/database_spec.rb | |
@@ -55,13 +55,13 @@ describe CouchPotato::Database, 'load' do | |
it "should set itself on the model" do | |
user = mock 'user' | |
DbTestUser.stub!(:new).and_return(user) | |
- db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => DbTestUser.json_create({'ruby_class' => 'DbTestUser'}))) | |
+ db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => DbTestUser.json_create({JSON.create_id => 'DbTestUser'}))) | |
user.should_receive(:database=).with(db) | |
db.load '1' | |
end | |
it "should load namespaced models" do | |
- db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => Parent::Child.json_create({'ruby_class' => 'Parent::Child'}))) | |
+ db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => Parent::Child.json_create({JSON.create_id => 'Parent::Child'}))) | |
db.load('1').class.should == Parent::Child | |
end | |
end | |
diff --git a/spec/unit/dirty_attributes_spec.rb b/spec/unit/dirty_attributes_spec.rb | |
index bdb58e7..83812e8 100644 | |
--- a/spec/unit/dirty_attributes_spec.rb | |
+++ b/spec/unit/dirty_attributes_spec.rb | |
@@ -86,7 +86,7 @@ describe 'dirty attribute tracking' do | |
describe "object loaded from database" do | |
before(:each) do | |
- couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', 'ruby_class' => 'Plate'}), :info => nil) | |
+ couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', JSON.create_id => 'Plate'}), :info => nil) | |
@plate = CouchPotato::Database.new(couchrest_db).load_document '1' | |
end | |
@@ -104,7 +104,7 @@ describe 'dirty attribute tracking' do | |
end | |
it "should return true if array attribute changed" do | |
- couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => ['sushi'], 'ruby_class' => 'Plate'}), :info => nil) | |
+ couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => ['sushi'], JSON.create_id => 'Plate'}), :info => nil) | |
plate = CouchPotato::Database.new(couchrest_db).load_document '1' | |
plate.food << 'burger' | |
plate.should be_food_changed | |
@@ -119,7 +119,7 @@ describe 'dirty attribute tracking' do | |
describe "after save" do | |
it "should reset all attributes to not dirty" do | |
- couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', 'ruby_class' => 'Plate'}), :info => nil, :save_doc => {}) | |
+ couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', JSON.create_id => 'Plate'}), :info => nil, :save_doc => {}) | |
db = CouchPotato::Database.new(couchrest_db) | |
@plate = db.load_document '1' | |
@plate.food = 'burger' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment