OSDN Git Service

add test
[pettanr/pettanr.git] / spec / manifests / ground_picture_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #絵地
4
5 describe GroundPicture do
6   include ManifestsMacros
7   before do
8     @model = GroundPicture
9   end
10   
11   describe 'ペタナイズに於いて' do
12     it 'パネルの要素として利用されるエレメントである' do
13       expect(@model.ancestors.include?(Peta::Element)).to eq true
14     end
15     it '親モデルはパネルである' do
16       expect(@model.my_peta.parent_model_name).to eq 'panel'
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 'ground_picture'
32     end
33     describe 'actionに於いて' do
34       before do
35         @actions = @controller.actions
36         @actions_names = ['index', 'by_author', 'by_panel', 'show', 
37           'count', 'count_by_author', 'count_by_panel', 
38           'new', 'edit']
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, 'ground_picture', '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, 'ground_picture', '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, 'ground_picture', '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, 'ground_picture', '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, 'ground_picture', '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, 'ground_picture', '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 'ground_picture'
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 'ground_picture'
145         end
146       end
147     end
148     
149   end
150   
151   describe 'モデルに於いて' do
152     before do
153       @my_manifest = @model.my_manifest
154     end
155     it 'サポート機能が動作している' do
156       expect(@my_manifest.model_name).to eq 'ground_picture'
157       expect(@my_manifest.classify).to eq @model
158       expect(@my_manifest.table_name).to eq 'ground_pictures'
159     end
160     
161     describe 'associationsに於いて' do
162       describe 'belongs_toに於いて' do
163         before do
164           @belongs_to = @my_manifest.associations.belongs_to
165           @names = ['panel']
166         end
167         it 'これらのモデルに所属している' do
168           set_associations? @belongs_to, @names
169         end
170         describe 'panelに於いて' do
171           before do
172             @mani = @belongs_to['panel']
173           end
174           it 'マニフェストから設定を取り出している' do
175             # モデル名と外部キーが定義あるいはデフォルト値補充されている
176             expect(@mani.model_name).to eq 'panel'
177             expect(@mani.id_column).to eq 'panel_id'
178           end
179           it 'サポート機能が動作している' do
180             # モデルを再現できている
181             expect(@mani.model).to eq Panel
182           end
183         end
184       end
185       describe 'has_manyに於いて' do
186         before do
187           @has_many = @model.my_manifest.associations.has_many
188           @names = []
189         end
190         it 'これらのモデルを所持している' do
191           set_associations? @has_many, @names
192         end
193       end
194     end
195     
196     describe 'attributesに於いて' do
197       before do
198         @attributes = @model.my_manifest.attributes
199       end
200       it 'これらのカラムを定義している' do
201         set_attributes? @attributes, 
202           ['id', 'panel_id', 'picture_id', 'caption',  'repeat', 'x', 'y',
203           'z', 't', 
204           'created_at', 'updated_at']
205       end
206       describe 'panel_idに於いて' do
207         before do
208           @attribute = @attributes['panel_id']
209         end
210         it 'numberタイプである' do
211           expect(@attribute.type).to eq 'number'
212         end
213       end
214       describe 'picture_idに於いて' do
215         before do
216           @attribute = @attributes['picture_id']
217         end
218         it 'numberタイプである' do
219           expect(@attribute.type).to eq 'number'
220         end
221       end
222       describe 'captionに於いて' do
223         before do
224           @attribute = @attributes['caption']
225         end
226         it 'textタイプである' do
227           expect(@attribute.type).to eq 'text'
228         end
229       end
230       describe 'repeatに於いて' do
231         before do
232           @attribute = @attributes['repeat']
233         end
234         it 'numberタイプである' do
235           expect(@attribute.type).to eq 'number'
236         end
237         it '選択肢を定数から取得できるように定義している' do
238           expect(@attribute.source.type).to eq 'magic_number'
239           expect(@attribute.source.select_item_name).to eq 'ground_picture_repeat_items'
240         end
241       end
242       describe 'xに於いて' do
243         before do
244           @attribute = @attributes['x']
245         end
246         it 'numberタイプである' do
247           expect(@attribute.type).to eq 'number'
248         end
249       end
250       describe 'yに於いて' do
251         before do
252           @attribute = @attributes['y']
253         end
254         it 'numberタイプである' do
255           expect(@attribute.type).to eq 'number'
256         end
257       end
258       describe 'zに於いて' do
259         before do
260           @attribute = @attributes['z']
261         end
262         it 'numberタイプである' do
263           expect(@attribute.type).to eq 'number'
264         end
265       end
266       describe 'tに於いて' do
267         before do
268           @attribute = @attributes['t']
269         end
270         it 'numberタイプである' do
271           expect(@attribute.type).to eq 'number'
272         end
273       end
274     end
275     
276   end
277   
278 end