Sha256: 06e151c261c6c3e885cf1556503797dfc21785da5252791dcfd139893ba1a14d

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe DattsRight, ".where_dynamic_attribute" do
  before do
    reset_database
    @page = Page.create
  end

  it "should be aliased by where_datt" do
    @page.add_dynamic_attribute(:price, "float")
    @page.write_dynamic_attribute :price, 200.0
    Page.where_dynamic_attribute(:price => 200.0).should == Page.where_datt(:price => 200.0)
  end

  it "should automatically join in the dynamic_attributes table" do
    @page.add_dynamic_attribute(:price, "float")
    @page.write_dynamic_attribute :price, 200.0
    @page.add_dynamic_attribute(:farce, "boolean")
    @page.write_dynamic_attribute :farce, true
    @page.save
    
    @page_2 = Page.create
    @page_2.add_dynamic_attribute(:price, "integer")
    @page_2.add_dynamic_attribute(:farce, "boolean")
    @page_2.write_dynamic_attribute :farce, true
    @page_2.write_dynamic_attribute :price, 1
    @page_2.save

    @result = Page.where_dynamic_attribute(:price => 200.0, :farce => true)
    @result.should include(@page)
    @result.should_not include(@page_2)
  end

  it "should allow chaining with where scopes" do
    @page.add_dynamic_attribute(:price, "integer")
    @page.name = "aardvark"
    @page.write_dynamic_attribute :price, 200
    @page.save
    
    @page_2 = Page.create
    @page_2.add_dynamic_attribute(:price, "integer")
    @page_2.write_dynamic_attribute :price, 200
    @page_2.save

    @results = Page.where_dynamic_attribute(:price => 200).where(:name => "aardvark")
    @results.should include(@page)
    @results.should_not include(@page_2)
  end

  it "should return an empty array if we're looking for a field that doesn't exist" do
    Page.where_dynamic_attribute(:bogus_field => "none").should be_empty
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datts_right-0.0.20 spec/datts_right/where_dynamic_attribute_spec.rb