File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -136,10 +136,13 @@ private function check_methods()
136136 {
137137 $ this ->options_to_a ('methods ' );
138138
139- foreach ($ this ->options ['methods ' ] as $ method )
139+ foreach ($ this ->options ['methods ' ] as $ method => $ name )
140140 {
141+ if (is_numeric ($ method ))
142+ $ method = $ name ;
143+
141144 if (method_exists ($ this ->model , $ method ))
142- $ this ->attributes [$ method ] = $ this ->model ->$ method ();
145+ $ this ->attributes [$ name ] = $ this ->model ->$ method ();
143146 }
144147 }
145148 }
Original file line number Diff line number Diff line change @@ -64,14 +64,21 @@ public function test_methods_takes_a_string()
6464 $ this ->assert_equals ('ANCIENT ART OF MAIN TANKING ' , $ a ['upper_name ' ]);
6565 }
6666
67- // methods added last should we shuld have value of the method in our json
68- // rather than the regular attribute value
67+ // methods should take precedence over attributes
6968 public function test_methods_method_same_as_attribute ()
7069 {
7170 $ a = $ this ->_a (array ('methods ' => 'name ' ));
7271 $ this ->assert_equals ('ancient art of main tanking ' , $ a ['name ' ]);
7372 }
7473
74+ public function test_methods_method_alias ()
75+ {
76+ $ a = $ this ->_a (array ('methods ' => array ('name ' => 'alias_name ' )));
77+ $ this ->assert_equals ('ancient art of main tanking ' , $ a ['alias_name ' ]);
78+ $ a = $ this ->_a (array ('methods ' => array ('upper_name ' => 'name ' )));
79+ $ this ->assert_equals ('ANCIENT ART OF MAIN TANKING ' , $ a ['name ' ]);
80+ }
81+
7582 public function test_include ()
7683 {
7784 $ a = $ this ->_a (array ('include ' => array ('author ' )));
You can’t perform that action at this time.
0 commit comments