Sha256: d916cd2aab122c6b984d7640be23059b82f5d810aafccbf2f7e8d210c40dc043

Contents?: true

Size: 1.57 KB

Versions: 25

Compression:

Stored size: 1.57 KB

Contents

require File.expand_path("#{File.dirname(__FILE__)}/test_helper")

class ActsMethodsTest < Test::Unit::TestCase
  class Model
    attr_accessor :birthdate
    
    def initialize(birthdate)
      @birthdate = birthdate
    end
    
    def self.configuration
      @configuration ||= {:solr_fields => {}}
    end

    def self.columns_hash=(columns_hash)
      @columns_hash = columns_hash
    end
    
    def self.columns_hash
      @columns_hash
    end
    
    def [](key)
      @birthday
    end
    
    self.extend ActsAsSolr::ActsMethods
  end
  
  
  context "when getting field values" do
    setup do
      Model.columns_hash = {"birthdate" => stub("column", :type => :date)}
      Model.send(:get_field_value, :birthdate)
    end
    
    should "define an accessor methods for a solr converted value" do
      assert Model.instance_methods.include?("birthdate_for_solr")
    end
    
    context "for date types" do
      setup do
        @model = Model.new(Date.today)
      end
      
      should "return nil when field is nil" do
        @model.birthdate = nil
        assert_nil @model.birthdate_for_solr
      end
      
      should "return the formatted date" do
        assert_equal Date.today.strftime("%Y-%m-%dT%H:%M:%SZ"), @model.birthdate_for_solr
      end
    end
    
    context "for timestamp types" do
      setup do
        @now = Time.now
        @model = Model.new(@now)
      end
      
      should "return a formatted timestamp string for timestamps" do
        assert_equal @now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"), @model.birthdate_for_solr
      end
    end
  end
  
end

Version data entries

25 entries across 25 versions & 5 rubygems

Version Path
muck-solr-0.4.4 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.3 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.1 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.2 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.0 test/unit/acts_methods_shoulda.rb