OSDN Git Service

add test
[pettanr/pettanr.git] / spec / manifests / story_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #ストーリー
4
5 describe Story do
6   include ManifestsMacros
7   before do
8     @model = Story
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 'story'
32     end
33     describe 'actionに於いて' do
34       before do
35         @actions = @controller.actions
36         @actions_names = ['index', 'by_author', 'by_comic', 'by_sheet', 'play', 'show', 
37           'count', 'count_by_author', 'count_by_comic', 'count_by_sheet', 
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, 'story', '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, 'story', 'by_author'
67         end
68       end
69       describe 'by_comicに於いて' do
70         before do
71           @action = @actions['by_comic']
72         end
73         it 'listタイプのアクションである' do
74           expect(@action.type).to eq 'list'
75         end
76         it 'マニフェストから設定を取り出している' do
77           #ストーリーのコマフィルタリストを返すように定義している
78           set_list_action? @action, 'story', 'by_comic'
79         end
80       end
81       describe 'by_sheetに於いて' do
82         before do
83           @action = @actions['by_sheet']
84         end
85         it 'listタイプのアクションである' do
86           expect(@action.type).to eq 'list'
87         end
88         it 'マニフェストから設定を取り出している' do
89           #ストーリーのコマフィルタリストを返すように定義している
90           set_list_action? @action, 'story', 'by_sheet'
91         end
92       end
93       describe 'showに於いて' do
94         before do
95           @action = @actions['show']
96         end
97         it 'showタイプのアクションである' do
98           expect(@action.type).to eq 'show'
99         end
100       end
101       describe 'countに於いて' do
102         before do
103           @action = @actions['count']
104         end
105         it 'countタイプのアクションである' do
106           expect(@action.type).to eq 'count'
107         end
108         it 'マニフェストから設定を取り出している' do
109           #ストーリーの公開リストのカウントを返すように定義している
110           set_list_action? @action, 'story', 'public'
111         end
112       end
113       describe 'count_by_authorに於いて' do
114         before do
115           @action = @actions['count_by_author']
116         end
117         it 'countタイプのアクションである' do
118           expect(@action.type).to eq 'count'
119         end
120         it 'マニフェストから設定を取り出している' do
121           # ストーリーの作家フィルタリストのカウントを返すように定義している
122           set_list_action? @action, 'story', 'by_author'
123         end
124       end
125       describe 'count_by_comicに於いて' do
126         before do
127           @action = @actions['count_by_comic']
128         end
129         it 'countタイプのアクションである' do
130           expect(@action.type).to eq 'count'
131         end
132         it 'マニフェストから設定を取り出している' do
133           # ストーリーのコマフィルタリストのカウントを返すように定義している
134           set_list_action? @action, 'story', 'by_comic'
135         end
136       end
137       describe 'count_by_sheetに於いて' do
138         before do
139           @action = @actions['count_by_sheet']
140         end
141         it 'countタイプのアクションである' do
142           expect(@action.type).to eq 'count'
143         end
144         it 'マニフェストから設定を取り出している' do
145           # ストーリーのコマフィルタリストのカウントを返すように定義している
146           set_list_action? @action, 'story', 'by_sheet'
147         end
148       end
149       describe 'newに於いて' do
150         before do
151           @action = @actions['new']
152         end
153         it 'newタイプのアクションである' do
154           expect(@action.type).to eq 'new'
155         end
156         it 'type' do
157           expect(@action.item_name).to eq 'story'
158         end
159       end
160       describe 'editに於いて' do
161         before do
162           @action = @actions['edit']
163         end
164         it 'editタイプのアクションである' do
165           expect(@action.type).to eq 'edit'
166         end
167         it 'type' do
168           expect(@action.item_name).to eq 'story'
169         end
170       end
171       describe 'createに於いて' do
172         before do
173           @action = @actions['create']
174         end
175         it 'createタイプのアクションである' do
176           expect(@action.type).to eq 'create'
177         end
178         it 'type' do
179           expect(@action.item_name).to eq 'story'
180         end
181       end
182       describe 'updateに於いて' do
183         before do
184           @action = @actions['update']
185         end
186         it 'updateタイプのアクションである' do
187           expect(@action.type).to eq 'update'
188         end
189         it 'type' do
190           expect(@action.item_name).to eq 'story'
191         end
192       end
193       describe 'destroyに於いて' do
194         before do
195           @action = @actions['destroy']
196         end
197         it 'destroyタイプのアクションである' do
198           expect(@action.type).to eq 'destroy'
199         end
200         it 'type' do
201           expect(@action.item_name).to eq 'story'
202         end
203       end
204     end
205     
206   end
207   
208   describe 'モデルに於いて' do
209     before do
210       @my_manifest = @model.my_manifest
211     end
212     it 'サポート機能が動作している' do
213       expect(@my_manifest.model_name).to eq 'story'
214       expect(@my_manifest.classify).to eq @model
215       expect(@my_manifest.table_name).to eq 'stories'
216     end
217     
218     describe 'associationsに於いて' do
219       describe 'belongs_toに於いて' do
220         before do
221           @belongs_to = @my_manifest.associations.belongs_to
222           @names = ['author']
223         end
224         it 'これらのモデルに所属している' do
225           set_associations? @belongs_to, @names
226         end
227         describe 'authorに於いて' do
228           before do
229             @mani = @belongs_to['author']
230           end
231           it 'マニフェストから設定を取り出している' do
232             # モデル名と外部キーが定義あるいはデフォルト値補充されている
233             expect(@mani.model_name).to eq 'author'
234             expect(@mani.id_column).to eq 'author_id'
235           end
236           it 'サポート機能が動作している' do
237             # モデルを再現できている
238             expect(@mani.model).to eq Author
239           end
240         end
241       end
242       describe 'has_manyに於いて' do
243         before do
244           @has_many = @model.my_manifest.associations.has_many
245           @names = ['comic_stories', 'comics', 'comic_stories', 'comics']
246         end
247         it 'これらのモデルを所持している' do
248           set_associations? @has_many, @names
249         end
250         describe 'comic_storiesに於いて' do
251           before do
252             @mani = @has_many['comic_stories']
253           end
254           it 'マニフェストから設定を取り出している' do
255             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
256             expect(@mani.model_name).to eq 'comic_story'
257             expect(@mani.foreign_key).to eq 'story_id'
258             expect(@mani.through).to be nil
259           end
260           it 'サポート機能が動作している' do
261             # モデルを再現できている, 中間モデルフラグ
262             expect(@mani.through?).to be false
263             expect(@mani.model).to eq ComicStory
264           end
265         end
266         describe 'comicsに於いて' do
267           before do
268             @mani = @has_many['comics']
269           end
270           it 'マニフェストから設定を取り出している' do
271             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
272             expect(@mani.model_name).to eq 'comic'
273             expect(@mani.foreign_key).to eq 'story_id'
274             expect(@mani.through).to eq 'comic_stories'
275           end
276           it 'サポート機能が動作している' do
277             # モデルを再現できている, 中間モデルフラグ
278             expect(@mani.through?).to be true
279             expect(@mani.model).to eq Comic
280           end
281         end
282         describe 'story_sheetsに於いて' do
283           before do
284             @mani = @has_many['story_sheets']
285           end
286           it 'マニフェストから設定を取り出している' do
287             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
288             expect(@mani.model_name).to eq 'story_sheet'
289             expect(@mani.foreign_key).to eq 'story_id'
290             expect(@mani.through).to be nil
291           end
292           it 'サポート機能が動作している' do
293             # モデルを再現できている, 中間モデルフラグ
294             expect(@mani.through?).to be false
295             expect(@mani.model).to eq StorySheet
296           end
297         end
298         describe 'sheetsに於いて' do
299           before do
300             @mani = @has_many['sheets']
301           end
302           it 'マニフェストから設定を取り出している' do
303             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
304             expect(@mani.model_name).to eq 'sheet'
305             expect(@mani.foreign_key).to eq 'story_id'
306             expect(@mani.through).to eq 'story_sheets'
307           end
308           it 'サポート機能が動作している' do
309             # モデルを再現できている, 中間モデルフラグ
310             expect(@mani.through?).to be true
311             expect(@mani.model).to eq Sheet
312           end
313         end
314       end
315     end
316     
317     describe 'attributesに於いて' do
318       before do
319         @attributes = @model.my_manifest.attributes
320       end
321       it 'これらのカラムを定義している' do
322         set_attributes? @attributes, 
323           ['id', 'title', 'description', 'visible', 't', 'author_id', 
324           'created_at', 'updated_at']
325       end
326       describe 'titleに於いて' do
327         before do
328           @attribute = @attributes['title']
329         end
330         it 'textタイプである' do
331           expect(@attribute.type).to eq 'text'
332         end
333       end
334       describe 'descriptionに於いて' do
335         before do
336           @attribute = @attributes['description']
337         end
338         it 'textタイプである' do
339           expect(@attribute.type).to eq 'text'
340         end
341       end
342       describe 'tに於いて' do
343         before do
344           @attribute = @attributes['t']
345         end
346         it 'numberタイプである' do
347           expect(@attribute.type).to eq 'number'
348         end
349       end
350       describe 'visibleに於いて' do
351         before do
352           @attribute = @attributes['visible']
353         end
354         it 'numberタイプである' do
355           expect(@attribute.type).to eq 'number'
356         end
357         it '選択肢を定数から取得できるように定義している' do
358           expect(@attribute.source.type).to eq 'magic_number'
359           expect(@attribute.source.select_item_name).to eq 'story_visible_items'
360         end
361       end
362       describe 'author_idに於いて' do
363         before do
364           @attribute = @attributes['author_id']
365         end
366         it 'numberタイプである' do
367           expect(@attribute.type).to eq 'number'
368         end
369       end
370     end
371     
372   end
373   
374 end