require 'helper' class Account < ActiveRecord::Base has_settings do setting :archive_reports setting :ssl, :protected => true setting :archive setting :reports end end class TestHasSettings < ActiveSupport::TestCase context "settings" do fixtures :accounts, :account_settings should "be accessable from the owner association" do a = Account.create(:name => 'name') assert a.settings.empty? assert !a.settings.archive? assert a.settings.archive.create assert a.settings.size == 1 assert a.settings.archive? assert a.settings.archive.id == a.settings.archive.create.id end should "be destroyable via the association" do a = accounts(:account1) assert a.settings.archive? assert a.settings.archive.destroy a.settings.reload assert !a.settings.archive? end should "have convenience methods for checking presence" do a = accounts(:account1) assert a.settings.archive? assert a.settings.ssl? assert !a.settings.reports? end should "support mass updates" do a = Account.create(:name => 'name') assert a.settings.empty? assert !a.settings.archive? assert !a.settings.reports? a.update_attributes(:settings => { :archive => '1', :reports => '1' }) assert a.settings.archive? assert a.settings.reports? a.update_attributes(:settings => { :archive => '0', :reports => '0' }) assert !a.settings.archive? assert !a.settings.reports? end should "support protecting certain settings from mass updates" do a = Account.create(:name => 'name') assert a.settings.empty? assert !a.settings.archive? assert !a.settings.ssl? a.update_attributes(:settings => {:archive => '1', :ssl => '1'}) assert a.settings.archive? assert !a.settings.ssl? assert a.settings.ssl.create assert a.settings.ssl? a.update_attributes(:settings => {:archive => '0', :ssl => '0'}) assert !a.settings.archive? assert a.settings.ssl? end end end