1 # -*- encoding: utf-8 -*-
7 @admin =FactoryGirl.create :admin
8 @user_yas = FactoryGirl.create :user_yas_with_owner
9 @user_rom = FactoryGirl.create :user_rom
10 @author_yas = @user_yas.author
15 @item = FactoryGirl.build :scroll_hello, author: @author_yas
18 context 'オーソドックスなデータのとき' do
22 expect(@item).to be_valid
27 expect(@item).to be_valid
31 context 'titleを検証するとき' do
34 expect(@item).to_not be_valid
38 expect(@item).to_not be_valid
41 context 'visibleを検証するとき' do
44 expect(@item).to_not be_valid
48 expect(@item).to_not be_valid
52 expect(@item).to_not be_valid
56 context 'author_idを検証するとき' do
59 expect(@item).to_not be_valid
63 expect(@item).to_not be_valid
65 it '存在する作家でなければ失敗する' do
67 expect(@item).to_not be_valid
72 describe 'デフォルト値補充に於いて' do
73 it 'visibleが0になっている' do
74 @item = FactoryGirl.build :scroll_hello, author: @author_yas
76 expect(@item.visible).to eq 0
80 describe '上書き補充に於いて' do
82 @item = FactoryGirl.build :scroll_hello, author: @author_yas
83 @item.overwrite @author
84 expect(@item.author_id).to eq @author.id
88 describe '所持判定に於いて' do
90 @item = FactoryGirl.build :scroll_hello, author: @author_yas
92 context 'ロール内作家が取得できるとき' do
95 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
96 Scroll.stub(:get_author_from_roles).with(any_args).and_return(@author)
97 r = @item.own?([@author])
100 it 'ロール内作家のidが自身の作家idと一致しないならno' do
101 Scroll.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
102 @item.own?(@other_author).should be_false
105 context 'ロール内作家が取得できないとき' do
107 Scroll.stub(:get_author_from_roles).with(any_args).and_return(nil)
110 r = @item.own?([@author])
116 describe '閲覧許可に於いて' do
118 @item = FactoryGirl.build :scroll_hello, author: @author_yas
120 context 'オープンモードのとき' do
122 MagicNumber['run_mode'] = 0
125 it '他人のの非公開スクロールでも許可する' do
129 it '自分のスクロールなら許可する' do
130 Scroll.any_instance.stub(:own?).and_return(true)
131 Scroll.any_instance.stub(:visible).and_return(0)
132 r = @item.visible?([@author])
135 it '他人の非公開スクロールなら許可しない' do
137 it '他人のスクロールでも公開なら許可する' do
140 context 'adminのとき' do
141 it '他人のの非公開スクロールでも許可する' do
145 context 'クローズドモードのとき' do
147 MagicNumber['run_mode'] = 1
150 it '他人のの非公開スクロールでも許可する' do
154 it '自分のスクロールなら許可する' do
155 Scroll.any_instance.stub(:own?).and_return(true)
156 Scroll.any_instance.stub(:visible).and_return(0)
157 r = @item.visible?([@author])
160 it '他人の非公開スクロールなら許可しない' do
162 it '他人のスクロールでも公開なら許可する' do
165 context 'adminのとき' do
166 it '他人のの非公開スクロールでも許可する' do
172 describe '単体取得に於いて' do
174 @item = FactoryGirl.create :scroll, :author_id => @author.id
177 c = Scroll.show @item.id, @author
180 context '閲覧許可が出なかったとき' do
181 it '403Forbidden例外を返す' do
182 Scroll.any_instance.stub(:visible?).and_return(false)
184 Scroll.show @item.id, @author
185 }.should raise_error(ActiveRecord::Forbidden)
188 context '存在しないスクロールを開こうとしたとき' do
189 it '404RecordNotFound例外を返す' do
191 Scroll.show 110, @author
192 }.should raise_error(ActiveRecord::RecordNotFound)
197 describe '編集取得に於いて' do
199 @item = FactoryGirl.create :scroll, :author_id => @author.id
201 context 'つつがなく終わるとき' do
202 it '単体取得オプションを利用している' do
203 Scroll.stub(:show_opt).with(any_args).and_return({})
204 Scroll.should_receive(:show_opt).with(any_args).exactly(1)
205 r = Scroll.edit @item.id, @author
207 it '所持判定を問い合わせている' do
208 Scroll.any_instance.stub(:own?).with(any_args).and_return(true)
209 Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
210 r = Scroll.edit @item.id, @author
214 Scroll.any_instance.stub(:own?).and_return(true)
215 c = Scroll.edit @item.id, @author.id
218 context '他人のスクロールを開こうとしたとき' do
219 it '403Forbidden例外を返す' do
220 Scroll.any_instance.stub(:own?).and_return(false)
222 Scroll.edit @item.id, @author
223 }.should raise_error(ActiveRecord::Forbidden)
226 context '存在しないスクロールを開こうとしたとき' do
227 it '404RecordNotFound例外を返す' do
229 Scroll.edit 110, @author
230 }.should raise_error(ActiveRecord::RecordNotFound)
237 @item = FactoryGirl.create :scroll, :author_id => @author.id
238 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
239 @item_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @item.id, :panel_id => @panel.id
240 @other_scroll = FactoryGirl.create :scroll, :author_id => @author.id
241 @other_scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @other_scroll.id, :panel_id => @panel.id
243 context 'つつがなく終わるとき' do
246 r = @item.destroy_with_scroll_panel
247 }.should change(Scroll, :count).by(-1)
249 r = Scroll.find @item.id
252 it '自身にリンクしているスクコマをすべて削除する' do
254 r = @item.destroy_with_scroll_panel
255 }.should change(ScrollPanel, :count).by(-1)
257 r = ScrollPanel.find @item_panel.id
261 r = @item.destroy_with_scroll_panel
265 context '削除に失敗したとき' do
267 ScrollPanel.any_instance.stub(:destroy).with(any_args).and_return(false)
270 r = @item.destroy_with_scroll_panel
275 r = @item.destroy_with_scroll_panel
276 }.should_not change(Scroll, :count)
278 r = @item.destroy_with_scroll_panel
279 }.should_not change(ScrollPanel, :count)