File tree Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ def settings(var)
1313 raise ArgumentError . new ( "Unknown key: #{ var } " ) unless self . class . setting_keys [ var ]
1414
1515 fetch_settings_record ( var )
16+ . becomes ( self . class . setting_keys [ var ] [ :class_name ] . constantize )
1617 end
1718
1819 def settings = ( value )
@@ -44,22 +45,14 @@ def fetch_settings_record(var)
4445 end
4546
4647 def find_settings_record ( var )
47- setting_objects
48- . select { |s | s . var == var . to_s }
49- . map { |s | s . becomes self . class . setting_keys [ var ] [ :class_name ] . constantize }
50- . first
48+ setting_objects . detect { |s | s . var == var . to_s }
5149 end
5250
5351 def build_settings_record ( var )
54- build_args =
55- if RailsSettings . can_protect_attributes?
56- [ { :var => var . to_s } , :without_protection => true ]
57- else
58- [ :var => var . to_s , :target => self ]
59- end
60-
61- setting_objects . build ( *build_args ) do |record |
62- record . becomes self . class . setting_keys [ var ] [ :class_name ] . constantize
52+ if RailsSettings . can_protect_attributes?
53+ setting_objects . build ( { :var => var . to_s } , :without_protection => true )
54+ else
55+ setting_objects . build ( :var => var . to_s , :target => self )
6356 end
6457 end
6558 end
Original file line number Diff line number Diff line change 3232end
3333
3434describe 'Objects' do
35+ context "settings should be an instance of :class_name" do
36+ it "should be an instance of 'SettingObject' by default" do
37+ expect ( User . new . settings ( :dashboard ) ) . to be_a ( RailsSettings ::SettingObject )
38+ end
39+
40+ it "should be an instance of 'ProjectSettingObject' if defined" do
41+ expect ( Project . new . settings ( :info ) ) . to be_a ( ProjectSettingObject )
42+ end
43+ end
44+
3545 context 'without defaults' do
3646 let ( :account ) { Account . new :subdomain => 'foo' }
3747
You can’t perform that action at this time.
0 commit comments