Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests

  • Loading branch information...
commit fcd0a5c66f04a34aed598bab293fb731bd1cbc12 1 parent 8ff8581
Emil Kampp ekampp authored
Showing with 31 additions and 6 deletions.
  1. +3 −1 spec/models/product.rb
  2. +28 −5 spec/mongoid_search_spec.rb
4 spec/models/product.rb
View
@@ -4,10 +4,12 @@ class Product
field :brand
field :name
field :attrs, :type => Array
+ field :info, :type => Hash
references_many :tags
referenced_in :category
embeds_many :subproducts
- search_in :brand, :name, :outlet, :attrs, :tags => :name, :category => :name, :subproducts => [:brand, :name]
+ search_in :brand, :name, :outlet, :attrs, :tags => :name, :category => :name,
+ :subproducts => [:brand, :name], :info => [ :summary, :description ]
end
33 spec/mongoid_search_spec.rb
View
@@ -11,7 +11,30 @@
:name => "iPhone",
:tags => ["Amazing", "Awesome", "Olé"].map { |tag| Tag.new(:name => tag) },
:category => Category.new(:name => "Mobile"),
- :subproducts => [Subproduct.new(:brand => "Apple", :name => "Craddle")]
+ :subproducts => [Subproduct.new(:brand => "Apple", :name => "Craddle")],
+ :info => { :summary => "Info-summary",
+ :description => "Info-description"}
+ end
+
+ describe "Serialized hash fields" do
+ context "when the hash is populated" do
+ it "should return the product" do
+ Product.search("Info-summary").first.should eq @product
+ Product.search("Info-description").first.should eq @product
+ end
+ end
+
+ context "when the hash is empty" do
+ before(:each) do
+ @product.info = nil
+ @product.save
+ end
+
+ it "should not return the product" do
+ Product.search("Info-description").size.should eq 0
+ Product.search("Info-summary").size.should eq 0
+ end
+ end
end
context "utf-8 characters" do
@@ -40,7 +63,7 @@
lambda { Product.create! }.should_not raise_error
end
end
-
+
subject { Product.create :brand => "Apple", :name => "iPhone" }
its(:_keywords) { should == ["apple", "iphone"] }
@@ -66,13 +89,13 @@
it "should set the _keywords field with stemmed words if stem is enabled" do
Product.stem_keywords = true
@product.save!
- @product._keywords.should == ["amaz", "appl", "awesom", "craddl", "iphon", "mobil", "ol"]
+ @product._keywords.sort.should == ["amaz", "appl", "awesom", "craddl", "iphon", "mobil", "ol", "info", "descript", "summari"].sort
end
it "should ignore keywords in an ignore list" do
Product.ignore_list = YAML.load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))["ignorelist"]
@product.save!
- @product._keywords.should == ["apple", "craddle", "iphone", "mobile", "ole"]
+ @product._keywords.sort.should == ["apple", "craddle", "iphone", "mobile", "ole", "info", "description", "summary"].sort
end
it "should incorporate numbers as keywords" do
@@ -157,5 +180,5 @@
Product.index_keywords!.should_not include(false)
end
-
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.