Sha256: 1f8c1d4a24b5ce5f4152c6e1f47da864ed4a7b59e2264862b4ebc37aefd5d186

Contents?: true

Size: 1.75 KB

Versions: 32

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Spree::Preference, :type => :model do

  it "should require a key" do
    @preference = Spree::Preference.new
    @preference.key = :test
    @preference.value = true
    expect(@preference).to be_valid
  end

  describe "type coversion for values" do
    def round_trip_preference(key, value)
      p = Spree::Preference.new
      p.value = value
      p.key = key
      p.save

      Spree::Preference.find_by_key(key)
    end

    it ":boolean" do
      value = true
      key = "boolean_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it "false :boolean" do
      value = false
      key = "boolean_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it ":integer" do
      value = 10
      key = "integer_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it ":decimal" do
      value = 1.5
      key = "decimal_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it ":string" do
      value = "This is a string"
      key = "string_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it ":text" do
      value = "This is a string stored as text"
      key = "text_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it ":password" do
      value = "This is a password"
      key = "password_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

    it ":any" do
      value = [1, 2]
      key = "any_key"
      pref = round_trip_preference(key, value)
      expect(pref.value).to eq value
    end

  end

end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
solidus_core-1.2.3 spec/models/spree/preference_spec.rb
solidus_core-1.1.4 spec/models/spree/preference_spec.rb
solidus_core-1.0.7 spec/models/spree/preference_spec.rb
spree_core-3.1.5 spec/models/spree/preference_spec.rb
spree_core-3.1.4 spec/models/spree/preference_spec.rb
spree_core-3.1.3 spec/models/spree/preference_spec.rb
spree_core-3.1.2 spec/models/spree/preference_spec.rb
spree_core-3.0.10 spec/models/spree/preference_spec.rb
spree_core-3.1.1 spec/models/spree/preference_spec.rb
spree_core-3.1.0 spec/models/spree/preference_spec.rb
spree_core-3.1.0.rc4 spec/models/spree/preference_spec.rb
spree_core-3.0.9 spec/models/spree/preference_spec.rb
spree_core-3.1.0.rc3 spec/models/spree/preference_spec.rb
spree_core-3.1.0.rc2 spec/models/spree/preference_spec.rb
spree_core-3.1.0.rc1 spec/models/spree/preference_spec.rb
solidus_core-1.0.6 spec/models/spree/preference_spec.rb
spree_core-3.0.8 spec/models/spree/preference_spec.rb
solidus_core-1.2.2 spec/models/spree/preference_spec.rb
spree_core-3.0.7 spec/models/spree/preference_spec.rb
solidus_core-1.2.1 spec/models/spree/preference_spec.rb