Sha256: 6f576168bd9ca24055557fdf7b422509720534de19c18d0562891ba098164e51

Contents?: true

Size: 1.68 KB

Versions: 62

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'

module Workarea
  class DetailsTest < Workarea::TestCase
    class Foo
      include Mongoid::Document
      include Details
    end

    def test_cleans_details
      model = Foo.new
      model.details = { 'foo' => {} }
      model.valid?
      assert_equal(model.details, {})

      model.details = { 'foo' => 'bar' }
      model.valid?
      assert_equal(model.details['foo'], ['bar'])
    end

    def test_update_details_merges_values
      model = Foo.new(details: { 'foo' => 'bar' })
      model.update_details('foo' => 'baz')

      assert_equal(model.details['foo'], 'baz')
    end

    def test_update_details_removes_blank_values
      model = Foo.new(details: { 'foo' => 'bar' })
      model.update_details('foo' => '')

      refute(model.details.keys.include?('foo'))
    end

    def test_matches_details_array_values
      model = Foo.new(details: { 'foo' => ['BaR  '] })
      assert(model.matches_detail?('foo', ' BAr'))
    end

    def test_matches_details_values
      model = Foo.new(details: { 'foo' => 'BaR  ' })
      assert(model.matches_detail?('foo', ' BAr'))
    end

    def test_matches_details_array_arguments
      model = Foo.new(details: { 'foo' => ['BaR  '] })
      assert(model.matches_details?('foo' => [' BAr']))

      model = Foo.new(details: { 'foo' => 'BaR  ' })
      assert(model.matches_details?('foo' => [' BAr']))
    end

    def test_detail_names
      default_model = Foo.new(details: { 'foo' => 'bar' })
      rehydrated_model = Foo.new(details: {
        I18n.locale.to_s => { 'foo' => 'bar' }
      })

      assert_includes(default_model.detail_names, 'foo')
      assert_includes(rehydrated_model.detail_names, 'foo')
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.27 test/models/workarea/details_test.rb
workarea-core-3.5.4 test/models/workarea/details_test.rb
workarea-core-3.4.26 test/models/workarea/details_test.rb
workarea-core-3.5.3 test/models/workarea/details_test.rb
workarea-core-3.4.25 test/models/workarea/details_test.rb
workarea-core-3.5.2 test/models/workarea/details_test.rb
workarea-core-3.4.24 test/models/workarea/details_test.rb
workarea-core-3.5.1 test/models/workarea/details_test.rb
workarea-core-3.4.23 test/models/workarea/details_test.rb
workarea-core-3.4.22 test/models/workarea/details_test.rb
workarea-core-3.5.0 test/models/workarea/details_test.rb
workarea-core-3.4.21 test/models/workarea/details_test.rb
workarea-core-3.5.0.beta.1 test/models/workarea/details_test.rb
workarea-core-3.4.20 test/models/workarea/details_test.rb
workarea-core-3.4.19 test/models/workarea/details_test.rb
workarea-core-3.4.18 test/models/workarea/details_test.rb
workarea-core-3.4.17 test/models/workarea/details_test.rb
workarea-core-3.4.16 test/models/workarea/details_test.rb
workarea-core-3.4.15 test/models/workarea/details_test.rb
workarea-core-3.4.14 test/models/workarea/details_test.rb