Sha256: 5fa0876e20f3588b8c5a77debfa4b95ea480da93ae3cdc6d165c35cc69efad11
Contents?: true
Size: 1.58 KB
Versions: 3
Compression:
Stored size: 1.58 KB
Contents
require 'spec_helper' require 'flavors' describe Flavors::Preferences do before do User.class_eval do preference :notification, :default => true end Post.class_eval do preference :sticky, :default => false end end subject { User.create } it "returns preferences array" do expect(User.reflections_of_preferences).to eq [:notification] end it "scopes preferences for different classes" do expect(Post.reflections_of_preferences).to eq [:sticky] end it "has a default value" do expect(subject.notification).to be_truthy end it "updates preference" do subject.notification = false expect(subject.notification).to be_falsy end it "scopes preferences for different classes" do expect { subject.sticky }.to raise_error NoMethodError end it "scopes default value for different classes" do Post.class_eval do preference :notification, :default => false end expect(subject.notification).to be_truthy end it "returns if nil if no default value defined" do User.class_eval do preference :foo end expect(subject.foo).to be_nil end it "invokes callback block" do User.class_eval do def buz; end preference :bar do |object, value| object.buz end end expect(subject).to receive(:buz) subject.bar = true end it "responds to the preference name with question mark" do expect(subject).to respond_to(:notification?) expect(subject).to be_notification subject.notification = false expect(subject).not_to be_notification end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
flavors-1.0.0 | spec/preferences_spec.rb |
flavors-1.0.0.rc.1 | spec/preferences_spec.rb |
flavors-0.6.0 | spec/preferences_spec.rb |