OSDN Git Service

add test
[pettanr/pettanr.git] / spec / manifests / artist_spec.rb
1 # -*- encoding: utf-8 -*-
2 #絵師
3 require 'spec_helper'
4
5 describe Artist do
6   include ManifestsMacros
7   before do
8     @model = Artist
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 'artist'
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, 'artist', '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, 'artist', '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 'artist'
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 'artist'
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 'artist'
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 'artist'
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 'artist'
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 'artist'
142       expect(@my_manifest.classify).to eq @model
143       expect(@my_manifest.table_name).to eq 'artists'
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 = ['resource_pictures']
160         end
161         it 'これらのモデルを所持している' do
162           set_associations? @has_many, @names
163         end
164         describe 'resource_picturesに於いて' do
165           before do
166             @mani = @has_many['resource_pictures']
167           end
168           it 'マニフェストから設定を取り出している' do
169             # モデル名, 外部キーと中間モデルが定義あるいはデフォルト値補充されている
170             expect(@mani.model_name).to eq 'resource_picture'
171             expect(@mani.foreign_key).to eq 'artist_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 ResourcePicture
178           end
179         end
180       end
181     end
182     
183     describe 'attributesに於いて' do
184       before do
185         @attributes = @model.my_manifest.attributes
186       end
187       it 'これらのカラムを定義している' do
188         set_attributes? @attributes, 
189           ['id', 'name', 'user_id', 
190           'created_at', 'updated_at']
191       end
192       describe 'nameに於いて' do
193         before do
194           @attribute = @attributes['name']
195         end
196         it 'textタイプである' do
197           expect(@attribute.type).to eq 'text'
198         end
199       end
200       describe 'user_idに於いて' do
201         before do
202           @attribute = @attributes['user_id']
203         end
204         it 'numberタイプである' do
205           expect(@attribute.type).to eq 'number'
206         end
207       end
208     end
209     
210   end
211   
212 end