Permalink
Browse files

Release v0.0.1

  • Loading branch information...
1 parent ff35566 commit de306ca77ed421b97911f5342db321f213fdf79a @jah2488 committed Feb 26, 2012
View
@@ -0,0 +1,3 @@
+## v0.0.1
+
+* Initial Release
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Justin Herrick
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency("mongoid", "2.2")
+ s.add_dependency("mongoid", "2.2.6")
s.add_dependency("rake")
s.add_dependency("bson_ext","~> 1.5")
s.add_development_dependency "rspec"
Binary file not shown.
@@ -7,10 +7,11 @@ module Mongoid
describe ".counter_cache" do
context "when the document is associated" do
+
before do
Library.delete_all
- Book.delete_all
end
+
let(:library) do
Library.new
end
@@ -20,34 +21,57 @@ module Mongoid
end
before do
- library.books = [ book ]
+ library.save
+ library.books.create(:title => "War and Peace")
end
it "sets the target of the relation" do
- library.books.should == [ book ]
+ library.books.first.title.should == "War and Peace"
end
it "should have 1 book in books" do
- library.books.count.should == 1
+ library.books.size.should == 1
end
it "should have 1 song in counter" do
- library.books.count.should == library.book_count
+ library.book_count.should == 1
+ end
+
+ it "should have book_count and relation count equal" do
+ library.book_count.should == library.books.size
end
it "sets the counter cache equal to the relation count on addition" do
5.times do |n|
library.books << Book.new
- library.books.count.should == library.book_count
+ library.book_count.should == library.books.size
end
end
- it "decreases the counter cache when records are deleted" do
- library.books.delete_all
- library.books.count.should == 0
+
+ it "should increase counter when new books are added" do
+ library.books.push( book )
+ library.books.size.should == 2
end
+
+ it "should increase counter when new books are added" do
+ library.books.push( book )
+ library.books.size.should == library.book_count
+ end
+
+ it "should increase counter when new books are added" do
+ library.books.push( book )
+ book.destroy
+ library.books.size.should == 1
+ end
+
+ it "should increase counter when new books are added" do
+ library.books.push( book )
+ book.destroy
+ library.books.size.should == library.book_count
+ end
+
it "decreases the counter cache when records are deleted" do
- library.books.delete_all
- library.books.count.should == library.book_count
+ library.book_count.should == library.books.entries.size
end
context "when the referenced document has an embedded document" do
@@ -58,14 +82,15 @@ module Mongoid
before do
book.pages.create(:title => "it was a long and stormy night")
+ library.books << book
end
it "should have 1 page in pages" do
- book.pages.length.should == 1
+ book.pages.size.should == 1
end
it "should be accessible through parent" do
- library.books.first.pages.length.should == 1
+ library.books.last.pages.size.should == 1
end
it "should have 1 page in counter" do
@@ -132,33 +157,43 @@ module Mongoid
end
end
- context "when the field is specified directly" do
+ context "when the field is specified directly in an associated context" do
+
before do
Person.delete_all
end
-
+
let(:person) do
Person.new
end
-
+
let(:feeling) do
Feeling.new
end
before do
- person.feelings = [ feeling ]
- end
-
- it "should association relation correctly" do
- person.feelings == [ feeling ]
+ person.save
+ person.feelings.create
end
it "should have 1 feeling in feelings" do
- person.feelings.length.should == 1
+ person.feelings.size.should == 1
end
it "should have 1 feeling in counter" do
- person.feelings.length.should == person.all_my_feels
+ person.all_my_feels.should == person.feelings.size
+ end
+
+ it "sets the counter cache equal to the relation count on addition" do
+ 5.times do |n|
+ person.feelings.create
+ person.feelings.size.should == person.all_my_feels
+ end
+ end
+ it "decreases the counter cache when records are deleted" do
+ person.feelings.push( feeling )
+ feeling.destroy
+ person.all_my_feels.should == person.feelings.size
end
end
end

0 comments on commit de306ca

Please sign in to comment.