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
honkster-acts_as_solr-0.1.0 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.2.0 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.2.1 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.2.2 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.2.3 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.2.4 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.2.5 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.3.4 test/unit/acts_methods_shoulda.rb
jbasdf-acts_as_solr-0.3.3 test/unit/acts_methods_shoulda.rb
jbasdf-jbasdf-acts_as_solr-0.4.0 test/unit/acts_methods_shoulda.rb
jbasdf-muck-solr-0.4.0 test/unit/acts_methods_shoulda.rb
jbasdf-muck-solr-0.4.1 test/unit/acts_methods_shoulda.rb
jbasdf-muck-solr-0.4.2 test/unit/acts_methods_shoulda.rb
muck-solr-3.0.1 test/unit/acts_methods_shoulda.rb
muck-solr-3.0.0 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.7 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.6 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.3.7 test/unit/acts_methods_shoulda.rb
honkster-acts_as_solr-0.3.6 test/unit/acts_methods_shoulda.rb
muck-solr-0.4.5 test/unit/acts_methods_shoulda.rb