Sha256: 44743417541ef8938c70db6e6d1d31cf4810013798cca060b63fb6f34843591b
Contents?: true
Size: 1.71 KB
Versions: 9
Compression:
Stored size: 1.71 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe DattsRight, "order_by_dynamic_attribute" do before do reset_database @page = Page.create end it "should be aliased by order_by_datt" do @page.add_dynamic_attribute(:price, "integer") @page.write_dynamic_attribute :price, 2 @page.save Page.order_by_dynamic_attribute("price", "integer").should == Page.order_by_datt("price", "integer") end it "should default to asc" do @page.add_dynamic_attribute(:price, "integer") @page.write_dynamic_attribute :price, 2 @page.save @page_2 = Page.create @page_2.add_dynamic_attribute(:price, "integer") @page_2.write_dynamic_attribute :price, 1 @page_2.save @page_3 = Page.create @page_3.add_dynamic_attribute(:price, "float") @page_3.write_dynamic_attribute :price, 3.0 @page_3.save @page_4 = Page.create @page_4.add_dynamic_attribute(:price, "float") @page_4.write_dynamic_attribute :price, 3.5 @page_4.save # What if different records have price but they are of different object_type? # page_1.read_dynamic_attribute(:price) is an "integer" and it's saved in "integer_value" column # page_2.read_dynamic_attribute(:price) is a "float" and it's saved in "float_value" # # How would you work on Page.order_by_dynamic_attribute("price")? # # Answer 1: we could require passing of the object_type in the order method # This way, we know which column to look at => order_by_dynamic_attribute("price", "integer") Page.order_by_dynamic_attribute("price", "integer").should == [@page_2, @page] Page.order_by_dynamic_attribute("price DESC", "float").should == [@page_4, @page_3] end end
Version data entries
9 entries across 9 versions & 1 rubygems