OSDN Git Service

add test
[pettanr/pettanr.git] / spec / manifests / author_spec.rb
1 # -*- encoding: utf-8 -*-
2 #作家
3 require 'spec_helper'
4
5 describe Author do
6   include ManifestsMacros
7   before do
8     @model = Author
9   end
10   
11   describe 'ペタナイズに於いて' do
12     it 'オーナーである' do
13       expect(@model.ancestors.include?(Peta::Owner)).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 'author'
32     end
33     describe 'actionに於いて' do
34       before do
35         @actions = @controller.actions
36         @actions_names = ['index', 'show', 
37           'count', 
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, 'author', 'public'
55         end
56       end
57       describe 'showに於いて' do
58         before do
59           @action = @actions['show']
60         end
61         it 'showタイプのアクションである' do
62           expect(@action.type).to eq 'show'
63         end
64       end
65       describe 'countに於いて' do
66         before do
67           @action = @actions['count']
68         end
69         it 'countタイプのアクションである' do
70           expect(@action.type).to eq 'count'
71         end
72         it 'マニフェストから設定を取り出している' do
73           #作家の公開リストのカウントを返すように定義している
74           set_list_action? @action, 'author', 'public'
75         end
76       end
77       describe 'newに於いて' do
78         before do
79           @action = @actions['new']
80         end
81         it 'newタイプのアクションである' do
82           expect(@action.type).to eq 'new'
83         end
84         it 'type' do
85           expect(@action.item_name).to eq 'author'
86         end
87       end
88       describe 'editに於いて' do
89         before do
90           @action = @actions['edit']
91         end
92         it 'editタイプのアクションである' do
93           expect(@action.type).to eq 'edit'
94         end
95         it 'type' do
96           expect(@action.item_name).to eq 'author'
97         end
98       end
99       describe 'createに於いて' do
100         before do
101           @action = @actions['create']
102         end
103         it 'createタイプのアクションである' do
104           expect(@action.type).to eq 'create'
105         end
106         it 'type' do
107           expect(@action.item_name).to eq 'author'
108         end
109       end
110       describe 'updateに於いて' do
111         before do
112           @action = @actions['update']
113         end
114         it 'updateタイプのアクションである' do
115           expect(@action.type).to eq 'update'
116         end
117         it 'type' do
118           expect(@action.item_name).to eq 'author'
119         end
120       end
121       describe 'destroyに於いて' do
122         before do
123           @action = @actions['destroy']
124         end
125         it 'destroyタイプのアクションである' do
126           expect(@action.type).to eq 'destroy'
127         end
128         it 'type' do
129           expect(@action.item_name).to eq 'author'
130         end
131       end
132     end
133     
134   end
135   
136   describe 'モデルに於いて' do
137     before do
138       @my_manifest = @model.my_manifest
139     end
140     it 'サポート機能が動作している' do
141       expect(@my_manifest.model_name).to eq 'author'
142       expect(@my_manifest.classify).to eq @model
143       expect(@my_manifest.table_name).to eq 'authors'
144     end
145     
146     describe 'associationsに於いて' do
147       describe 'belongs_toに於いて' do
148         before do
149           @belongs_to = @my_manifest.associations.belongs_to
150           @names = []
151         end
152         it 'これらのモデルに所属している' do
153           set_associations? @belongs_to, @names
154         end
155       end
156       describe 'has_manyに於いて' do
157         before do
158           @has_many = @model.my_manifest.associations.has_many
159           @names = ['scrolls', 'comics', 'stories', 'sheets', 'panels']
160         end
161         it 'これらのモデルを所持している' do
162           set_associations? @has_many, @names
163         end
164         describe 'scrollsに於いて' do
165           before do
166             @mani = @has_many['scrolls']
167           end
168           it 'マニフェストから設定を取り出している' do
169             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
170             expect(@mani.model_name).to eq 'scroll'
171             expect(@mani.foreign_key).to eq 'author_id'
172             expect(@mani.through).to be nil
173           end
174           it 'サポート機能が動作している' do
175             # モデルを再現できている, 中間モデルフラグ
176             expect(@mani.through?).to be false
177             expect(@mani.model).to eq Scroll
178           end
179         end
180         describe 'comicsに於いて' do
181           before do
182             @mani = @has_many['comics']
183           end
184           it 'マニフェストから設定を取り出している' do
185             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
186             expect(@mani.model_name).to eq 'comic'
187             expect(@mani.foreign_key).to eq 'author_id'
188             expect(@mani.through).to be nil
189           end
190           it 'サポート機能が動作している' do
191             # モデルを再現できている, 中間モデルフラグ
192             expect(@mani.through?).to be false
193             expect(@mani.model).to eq Comic
194           end
195         end
196         describe 'storiesに於いて' do
197           before do
198             @mani = @has_many['stories']
199           end
200           it 'マニフェストから設定を取り出している' do
201             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
202             expect(@mani.model_name).to eq 'story'
203             expect(@mani.foreign_key).to eq 'author_id'
204             expect(@mani.through).to be nil
205           end
206           it 'サポート機能が動作している' do
207             # モデルを再現できている, 中間モデルフラグ
208             expect(@mani.through?).to be false
209             expect(@mani.model).to eq Story
210           end
211         end
212         describe 'sheetsに於いて' do
213           before do
214             @mani = @has_many['sheets']
215           end
216           it 'マニフェストから設定を取り出している' do
217             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
218             expect(@mani.model_name).to eq 'sheet'
219             expect(@mani.foreign_key).to eq 'author_id'
220             expect(@mani.through).to be nil
221           end
222           it 'サポート機能が動作している' do
223             # モデルを再現できている, 中間モデルフラグ
224             expect(@mani.through?).to be false
225             expect(@mani.model).to eq Sheet
226           end
227         end
228         describe 'panelsに於いて' do
229           before do
230             @mani = @has_many['panels']
231           end
232           it 'マニフェストから設定を取り出している' do
233             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
234             expect(@mani.model_name).to eq 'panel'
235             expect(@mani.foreign_key).to eq 'author_id'
236             expect(@mani.through).to be nil
237           end
238           it 'サポート機能が動作している' do
239             # モデルを再現できている, 中間モデルフラグ
240             expect(@mani.through?).to be false
241             expect(@mani.model).to eq Panel
242           end
243         end
244       end
245     end
246     
247     describe 'attributesに於いて' do
248       before do
249         @attributes = @model.my_manifest.attributes
250       end
251       it 'これらのカラムを定義している' do
252         set_attributes? @attributes, 
253           ['id', 'name', 'user_id', 
254           'created_at', 'updated_at']
255       end
256       describe 'nameに於いて' do
257         before do
258           @attribute = @attributes['name']
259         end
260         it 'textタイプである' do
261           expect(@attribute.type).to eq 'text'
262         end
263       end
264       describe 'author_idに於いて' do
265         before do
266           @attribute = @attributes['user_id']
267         end
268         it 'numberタイプである' do
269           expect(@attribute.type).to eq 'number'
270         end
271       end
272     end
273     
274   end
275   
276 end