File tree Expand file tree Collapse file tree 3 files changed +37
-12
lines changed
spec/unit/spark_api/models Expand file tree Collapse file tree 3 files changed +37
-12
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,19 @@ def to_param
129
129
attributes [ 'Id' ]
130
130
end
131
131
132
+ def to_partial_path
133
+ "#{ underscore ( resource_pluralized ) } /#{ underscore ( self . class . name . split ( '::' ) . last ) } "
134
+ end
135
+
136
+ # can be overridden
137
+ def resource_pluralized
138
+ resource = self . class . name . split ( '::' ) . last
139
+ unless resource . split ( '' ) . last == "s"
140
+ resource = resource + "s"
141
+ end
142
+ resource
143
+ end
144
+
132
145
protected
133
146
134
147
def write_attribute ( attribute , value )
@@ -139,6 +152,16 @@ def write_attribute(attribute, value)
139
152
end
140
153
end
141
154
155
+ private
156
+
157
+ def underscore ( string )
158
+ string . to_s . gsub ( /::/ , '/' ) .
159
+ gsub ( /([A-Z]+)([A-Z][a-z])/ , '\1_\2' ) .
160
+ gsub ( /([a-z\d ])([A-Z])/ , '\1_\2' ) .
161
+ tr ( "-" , "_" ) .
162
+ downcase
163
+ end
164
+
142
165
end
143
166
end
144
167
end
Original file line number Diff line number Diff line change @@ -59,15 +59,6 @@ def update_attributes_after_create(result)
59
59
attributes . merge! result
60
60
end
61
61
62
- # can be overridden
63
- def resource_pluralized
64
- resource = self . class . name . split ( '::' ) . last
65
- unless resource . split ( '' ) . last == "s"
66
- resource = resource + "s"
67
- end
68
- resource
69
- end
70
-
71
62
end
72
63
73
64
end
Original file line number Diff line number Diff line change 1
1
require './spec/spec_helper'
2
2
3
3
# Sample resource models for testing the base class
4
- class MyExampleModel < Base
5
- self . element_name = "example"
6
- self . prefix = "/test/"
4
+ module SparkApi
5
+ module Models
6
+ class MyExampleModel < Base
7
+ self . element_name = "example"
8
+ self . prefix = "/test/"
9
+ end
10
+ end
7
11
end
8
12
9
13
class MyDefaultModel < Base
@@ -153,4 +157,11 @@ class MyDefaultModel < Base
153
157
154
158
end
155
159
160
+ describe "to_partial_path" do
161
+ it "should return the partial path" do
162
+ model = MyExampleModel . new ( )
163
+ model . to_partial_path . should eq ( "my_example_models/my_example_model" )
164
+ end
165
+ end
166
+
156
167
end
You can’t perform that action at this time.
0 commit comments