spec/gitmodel/persistable_spec.rb in gitmodel-0.0.4 vs spec/gitmodel/persistable_spec.rb in gitmodel-0.0.5

- old
+ new

@@ -200,19 +200,20 @@ end it 'also deletes blobs associated with the given object' do id = 'Lemuridae' TestEntity.create!(:id => id, :blobs => {:crowned => "Eulemur coronatus", :brown => "Eulemur fulvus"}) - (GitModel.current_tree / File.join(TestEntity.db_subdir, id, 'crowned')).data.should_not be_nil - (GitModel.current_tree / File.join(TestEntity.db_subdir, id, 'brown')).data.should_not be_nil + b = GitModel.default_branch + (GitModel.current_tree(b) / File.join(TestEntity.db_subdir, id, 'crowned')).data.should_not be_nil + (GitModel.current_tree(b) / File.join(TestEntity.db_subdir, id, 'brown')).data.should_not be_nil TestEntity.delete(id) - (GitModel.current_tree / File.join(TestEntity.db_subdir, id, 'attributes.json')).should be_nil - (GitModel.current_tree / File.join(TestEntity.db_subdir, id, 'attributes.json')).should be_nil + (GitModel.current_tree(b) / File.join(TestEntity.db_subdir, id, 'attributes.json')).should be_nil + (GitModel.current_tree(b) / File.join(TestEntity.db_subdir, id, 'attributes.json')).should be_nil - (GitModel.current_tree / File.join(TestEntity.db_subdir, id, 'crowned')).should be_nil - (GitModel.current_tree / File.join(TestEntity.db_subdir, id, 'brown')).should be_nil + (GitModel.current_tree(b) / File.join(TestEntity.db_subdir, id, 'crowned')).should be_nil + (GitModel.current_tree(b) / File.join(TestEntity.db_subdir, id, 'brown')).should be_nil end end @@ -221,11 +222,11 @@ it 'deletes all objects of the same type from the database' do TestEntity.create!(:id => 'monkey') TestEntity.create!(:id => 'ape') TestEntity.delete_all - TestEntity.index! + TestEntity.index!(GitModel.default_branch) TestEntity.find_all.should be_empty end end @@ -345,11 +346,11 @@ describe 'with a literal value' do it 'returns an array of all objects that match' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'two', :attributes => {:a => 2, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => 1) r.size.should == 2 r.first.id.should == 'one' r.second.id.should == 'three' @@ -359,11 +360,11 @@ describe 'with a lambda as the value' do it 'returns an array of all objects that match' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'two', :attributes => {:a => 2, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:b => lambda{|b| b > 1}, :order => :asc) r.size.should == 2 r.first.id.should == 'three' r.second.id.should == 'two' @@ -375,11 +376,11 @@ describe 'with a literal value' do it 'returns an array of all objects that match both (i.e. AND)' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 2}) TestEntity.create!(:id => 'two', :attributes => {:a => 1, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 1}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => 1, :b => 2, :order => :asc) r.size.should == 2 r.first.id.should == 'one' r.second.id.should == 'two' @@ -390,11 +391,11 @@ it 'returns an array of all objects that match both (i.e. AND)' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 3}) TestEntity.create!(:id => 'two', :attributes => {:a => 2, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'four', :attributes => {:a => 3, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => lambda{|a| a > 1}, :b => lambda{|b| b > 2}, :order => :asc) r.size.should == 1 r.first.id.should == 'four' end @@ -432,11 +433,11 @@ it 'can return results in ascending order' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'two', :attributes => {:a => 2, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => 1, :order => :asc) r.size.should == 2 r.first.id.should == 'one' r.second.id.should == 'three' @@ -444,11 +445,11 @@ it 'can return results in descending order' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'two', :attributes => {:a => 2, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => 1, :order => :desc) r.size.should == 2 r.first.id.should == 'three' r.second.id.should == 'one' @@ -456,11 +457,11 @@ it 'can limit the number of results returned with ascending order' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'two', :attributes => {:a => 1, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => 1, :order => :asc, :limit => 2) r.size.should == 2 r.first.id.should == 'one' r.second.id.should == 'three' @@ -468,11 +469,11 @@ it 'can limit the number of results returned with descending order' do TestEntity.create!(:id => 'one', :attributes => {:a => 1, :b => 1}) TestEntity.create!(:id => 'two', :attributes => {:a => 1, :b => 2}) TestEntity.create!(:id => 'three', :attributes => {:a => 1, :b => 3}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) r = TestEntity.find_all(:a => 1, :order => :desc, :limit => 2) r.size.should == 2 r.first.id.should == 'two' r.second.id.should == 'three' @@ -495,18 +496,18 @@ describe ".index!" do it "generates and saves the index" do TestEntity.index.should_receive(:generate!) TestEntity.index.should_receive(:save) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) end end describe '.all_values_for_attr' do it 'returns a list of all values that exist for a given attribute' do o = TestEntity.create!(:id => 'first', :attributes => {"a" => 1, "b" => 2}) o = TestEntity.create!(:id => 'second', :attributes => {"a" => 3, "b" => 4}) - TestEntity.index! + TestEntity.index!(GitModel.default_branch) TestEntity.all_values_for_attr("a").should == [1, 3] end end describe '#attributes' do