OSDN Git Service

add test
[pettanr/pettanr.git] / spec / manifests / scroll_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #スクロールマニフェスト
4
5 describe Scroll do
6   include ManifestsMacros
7   before do
8     @model = Scroll
9   end
10   
11   describe 'ペタナイズに於いて' do
12     it 'スクコマを閉じるためのバインダーである' do
13       expect(@model.ancestors.include?(Peta::Binder)).to eq true
14     end
15     it '親モデルは持たない' do
16       expect(@model.my_peta.parent_model_name).to be_blank
17     end
18     describe 'ブーストに於いて' do
19       it '特筆すべき注意事項はない' do
20         expect(@model.my_peta.boost.keys).to be_empty
21       end
22     end
23     
24   end
25   
26   describe 'コントローラに於いて' do
27     before do
28       @controller = @model.my_controller
29     end
30     it 'スクロールのためのコントローラである' do
31       expect(@model.item_name).to eq 'scroll'
32     end
33     describe 'actionに於いて' do
34       before do
35         @actions = @controller.actions
36         @actions_names = ['index', 'by_author', 'by_panel', 'play', 'show', 
37           'count', 'count_by_author', 'count_by_panel', 
38           'new', 'edit', 'create', 'update', 'destroy']
39       end
40       it 'これらのアクションが定義されている' do
41         set_actions? @actions, @actions_names
42       end
43       describe 'baseに於いて' do
44       end
45       describe 'indexに於いて' do
46         before do
47           @action = @actions['index']
48         end
49         it 'listタイプのアクションである' do
50           expect(@action.type).to eq 'list'
51         end
52         it 'マニフェストから設定を取り出している' do
53           # スクロールの公開リストを返すように定義している
54           set_list_action? @action, 'scroll', 'public'
55         end
56       end
57       describe 'by_authorに於いて' do
58         before do
59           @action = @actions['by_author']
60         end
61         it 'listタイプのアクションである' do
62           expect(@action.type).to eq 'list'
63         end
64         it 'マニフェストから設定を取り出している' do
65           # スクロールの作家フィルタリストを返すように定義している
66           set_list_action? @action, 'scroll', 'by_author'
67         end
68       end
69       describe 'by_panelに於いて' do
70         before do
71           @action = @actions['by_panel']
72         end
73         it 'listタイプのアクションである' do
74           expect(@action.type).to eq 'list'
75         end
76         it 'マニフェストから設定を取り出している' do
77           #スクロールのコマフィルタリストを返すように定義している
78           set_list_action? @action, 'scroll', 'by_panel'
79         end
80       end
81       describe 'showに於いて' do
82         before do
83           @action = @actions['show']
84         end
85         it 'showタイプのアクションである' do
86           expect(@action.type).to eq 'show'
87         end
88       end
89       describe 'countに於いて' do
90         before do
91           @action = @actions['count']
92         end
93         it 'countタイプのアクションである' do
94           expect(@action.type).to eq 'count'
95         end
96         it 'マニフェストから設定を取り出している' do
97           #スクロールの公開リストのカウントを返すように定義している
98           set_list_action? @action, 'scroll', 'public'
99         end
100       end
101       describe 'count_by_authorに於いて' do
102         before do
103           @action = @actions['count_by_author']
104         end
105         it 'countタイプのアクションである' do
106           expect(@action.type).to eq 'count'
107         end
108         it 'マニフェストから設定を取り出している' do
109           # スクロールの作家フィルタリストのカウントを返すように定義している
110           set_list_action? @action, 'scroll', 'by_author'
111         end
112       end
113       describe 'count_by_panelに於いて' do
114         before do
115           @action = @actions['count_by_panel']
116         end
117         it 'countタイプのアクションである' do
118           expect(@action.type).to eq 'count'
119         end
120         it 'マニフェストから設定を取り出している' do
121           # スクロールのコマフィルタリストのカウントを返すように定義している
122           set_list_action? @action, 'scroll', 'by_panel'
123         end
124       end
125       describe 'newに於いて' do
126         before do
127           @action = @actions['new']
128         end
129         it 'newタイプのアクションである' do
130           expect(@action.type).to eq 'new'
131         end
132         it 'type' do
133           expect(@action.item_name).to eq 'scroll'
134         end
135       end
136       describe 'editに於いて' do
137         before do
138           @action = @actions['edit']
139         end
140         it 'editタイプのアクションである' do
141           expect(@action.type).to eq 'edit'
142         end
143         it 'type' do
144           expect(@action.item_name).to eq 'scroll'
145         end
146       end
147       describe 'createに於いて' do
148         before do
149           @action = @actions['create']
150         end
151         it 'createタイプのアクションである' do
152           expect(@action.type).to eq 'create'
153         end
154         it 'type' do
155           expect(@action.item_name).to eq 'scroll'
156         end
157       end
158       describe 'updateに於いて' do
159         before do
160           @action = @actions['update']
161         end
162         it 'updateタイプのアクションである' do
163           expect(@action.type).to eq 'update'
164         end
165         it 'type' do
166           expect(@action.item_name).to eq 'scroll'
167         end
168       end
169       describe 'destroyに於いて' do
170         before do
171           @action = @actions['destroy']
172         end
173         it 'destroyタイプのアクションである' do
174           expect(@action.type).to eq 'destroy'
175         end
176         it 'type' do
177           expect(@action.item_name).to eq 'scroll'
178         end
179       end
180     end
181     
182   end
183   
184   describe 'モデルに於いて' do
185     before do
186       @my_manifest = @model.my_manifest
187     end
188     it 'サポート機能が動作している' do
189       expect(@my_manifest.model_name).to eq 'scroll'
190       expect(@my_manifest.classify).to eq @model
191       expect(@my_manifest.table_name).to eq 'scrolls'
192     end
193     
194     describe 'associationsに於いて' do
195       describe 'belongs_toに於いて' do
196         before do
197           @belongs_to = @my_manifest.associations.belongs_to
198           @names = ['author']
199         end
200         it 'これらのモデルに所属している' do
201           set_associations? @belongs_to, @names
202         end
203         describe 'authorに於いて' do
204           before do
205             @mani = @belongs_to['author']
206           end
207           it 'マニフェストから設定を取り出している' do
208             # モデル名と外部キーが定義あるいはデフォルト値補充されている
209             expect(@mani.model_name).to eq 'author'
210             expect(@mani.id_column).to eq 'author_id'
211           end
212           it 'サポート機能が動作している' do
213             # モデルを再現できている
214             expect(@mani.model).to eq Author
215           end
216         end
217       end
218       describe 'has_manyに於いて' do
219         before do
220           @has_many = @model.my_manifest.associations.has_many
221           @names = ['scroll_panels', 'panels']
222         end
223         it 'これらのモデルを所持している' do
224           set_associations? @has_many, @names
225         end
226         describe 'scroll_panelsに於いて' do
227           before do
228             @mani = @has_many['scroll_panels']
229           end
230           it 'マニフェストから設定を取り出している' do
231             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
232             expect(@mani.model_name).to eq 'scroll_panel'
233             expect(@mani.foreign_key).to eq 'scroll_id'
234             expect(@mani.through).to be nil
235           end
236           it 'サポート機能が動作している' do
237             # モデルを再現できている, 中間モデルフラグ
238             expect(@mani.through?).to be false
239             expect(@mani.model).to eq ScrollPanel
240           end
241         end
242         describe 'panelsに於いて' do
243           before do
244             @mani = @has_many['panels']
245           end
246           it 'マニフェストから設定を取り出している' do
247             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
248             expect(@mani.model_name).to eq 'panel'
249             expect(@mani.foreign_key).to eq 'scroll_id'
250             expect(@mani.through).to eq 'scroll_panels'
251           end
252           it 'サポート機能が動作している' do
253             # モデルを再現できている, 中間モデルフラグ
254             expect(@mani.through?).to be true
255             expect(@mani.model).to eq Panel
256           end
257         end
258       end
259     end
260     
261     describe 'attributesに於いて' do
262       before do
263         @attributes = @model.my_manifest.attributes
264       end
265       it 'これらのカラムを定義している' do
266         set_attributes? @attributes, 
267           ['id', 'title', 'description', 'visible', 'author_id', 
268           'created_at', 'updated_at']
269       end
270       describe 'titleに於いて' do
271         before do
272           @attribute = @attributes['title']
273         end
274         it 'textタイプである' do
275           expect(@attribute.type).to eq 'text'
276         end
277       end
278       describe 'descriptionに於いて' do
279         before do
280           @attribute = @attributes['description']
281         end
282         it 'textタイプである' do
283           expect(@attribute.type).to eq 'text'
284         end
285       end
286       describe 'visibleに於いて' do
287         before do
288           @attribute = @attributes['visible']
289         end
290         it 'numberタイプである' do
291           expect(@attribute.type).to eq 'number'
292         end
293         it '選択肢を定数から取得できるように定義している' do
294           expect(@attribute.source.type).to eq 'magic_number'
295           expect(@attribute.source.select_item_name).to eq 'scroll_visible_items'
296         end
297       end
298       describe 'author_idに於いて' do
299         before do
300           @attribute = @attributes['author_id']
301         end
302         it 'numberタイプである' do
303           expect(@attribute.type).to eq 'number'
304         end
305       end
306     end
307     
308   end
309   
310 end