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()
136
136
{
137
137
$ this ->options_to_a ('methods ' );
138
138
139
- foreach ($ this ->options ['methods ' ] as $ method )
139
+ foreach ($ this ->options ['methods ' ] as $ method => $ name )
140
140
{
141
+ if (is_numeric ($ method ))
142
+ $ method = $ name ;
143
+
141
144
if (method_exists ($ this ->model , $ method ))
142
- $ this ->attributes [$ method ] = $ this ->model ->$ method ();
145
+ $ this ->attributes [$ name ] = $ this ->model ->$ method ();
143
146
}
144
147
}
145
148
}
Original file line number Diff line number Diff line change @@ -64,14 +64,21 @@ public function test_methods_takes_a_string()
64
64
$ this ->assert_equals ('ANCIENT ART OF MAIN TANKING ' , $ a ['upper_name ' ]);
65
65
}
66
66
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
69
68
public function test_methods_method_same_as_attribute ()
70
69
{
71
70
$ a = $ this ->_a (array ('methods ' => 'name ' ));
72
71
$ this ->assert_equals ('ancient art of main tanking ' , $ a ['name ' ]);
73
72
}
74
73
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
+
75
82
public function test_include ()
76
83
{
77
84
$ a = $ this ->_a (array ('include ' => array ('author ' )));
You can’t perform that action at this time.
0 commit comments