Sha256: fbf978902d675b481d7eaf039e9f3ae4ec5a88eaf35922b52940e5c22fc24bf2

Contents?: true

Size: 1.6 KB

Versions: 31

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

module Spree
  RSpec.describe Preferences::StaticallyConfigurable do
    let(:superklass) do
      # Same interface activerecord's serialization would provide
      Class.new do
        attr_accessor :preferences
        def initialize
          @preferences = { color: 'blue' }
        end

        def [](key)
          return @preferences if key == :preferences
        end
      end
    end
    let(:klass) do
      Class.new(superklass) do
        include Preferences::Preferable
        include Preferences::StaticallyConfigurable

        preference :color, :string

        attr_accessor :preference_source
      end
    end

    subject do
      klass.new.tap do |o|
        o.preference_source = preference_source
      end
    end

    before do
      Spree::Config.static_model_preferences.add(klass, 'credentials', color: 'red')
    end

    describe "available_preference_sources" do
      it "should contain the defined preference sets" do
        expect(klass.available_preference_sources).to eq ['credentials']
      end
    end

    context "with no preference_source" do
      let(:preference_source) { nil }
      it "uses the persisted preference" do
        expect(subject.preferred_color).to eq "blue"
      end
    end

    context "with preference_source set" do
      let(:preference_source) { 'credentials' }
      it "uses the statically configured preference" do
        expect(subject.preferred_color).to eq "red"
      end

      it "ignores assignment" do
        subject.preferences = { color: 'orange' }
        expect(subject.preferred_color).to eq "red"
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.2.2 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.1.1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.0.3 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-1.4.2 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-1.3.2 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.3.0 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.0.2 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-1.4.1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.2.1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.2.0 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.1.0 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/preferences/statically_configurable_spec.rb
solidus_core-2.0.1 spec/models/spree/preferences/statically_configurable_spec.rb