1 # -*- encoding: utf-8 -*-
8 @admin =FactoryGirl.create :admin
9 @user_yas = FactoryGirl.create :user_yas_with_owner
10 @user_rom = FactoryGirl.create :user_rom
11 @author_yas = @user_yas.author
16 @item = FactoryGirl.build :scroll_hello, author: @author_yas
19 context 'オーソドックスなデータのとき' do
23 expect(@item).to be_valid
28 expect(@item).to be_valid
32 context 'titleを検証するとき' do
35 expect(@item).to_not be_valid
39 expect(@item).to_not be_valid
42 context 'visibleを検証するとき' do
45 expect(@item).to_not be_valid
49 expect(@item).to_not be_valid
53 expect(@item).to_not be_valid
57 context 'author_idを検証するとき' do
60 expect(@item).to_not be_valid
64 expect(@item).to_not be_valid
66 it '存在する作家でなければ失敗する' do
68 expect(@item).to_not be_valid
73 describe 'デフォルト値補充に於いて' do
74 it 'visibleが0になっている' do
75 @item = FactoryGirl.build :scroll_hello, author: @author_yas
77 expect(@item.visible).to eq 0
81 describe '上書き補充に於いて' do
83 @item = FactoryGirl.build :scroll_hello, author: @author_yas
84 @item.overwrite @author
85 expect(@item.author_id).to eq @author.id
89 describe '所持判定に於いて' do
91 @item = FactoryGirl.build :scroll_hello, author: @author_yas
93 context 'ロール内作家が取得できるとき' do
96 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
97 Scroll.stub(:get_author_from_roles).with(any_args).and_return(@author)
98 r = @item.own?([@author])
101 it 'ロール内作家のidが自身の作家idと一致しないならno' do
102 Scroll.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
103 @item.own?(@other_author).should be_false
106 context 'ロール内作家が取得できないとき' do
108 Scroll.stub(:get_author_from_roles).with(any_args).and_return(nil)
111 r = @item.own?([@author])
117 describe '閲覧許可に於いて' do
119 @item = FactoryGirl.build :scroll_hello, author: @author_yas
121 context 'オープンモードのとき' do
123 MagicNumber['run_mode'] = 0
126 it '他人のの非公開スクロールでも許可する' do
130 it '自分のスクロールなら許可する' do
131 Scroll.any_instance.stub(:own?).and_return(true)
132 Scroll.any_instance.stub(:visible).and_return(0)
133 r = @item.visible?([@author])
136 it '他人の非公開スクロールなら許可しない' do
138 it '他人のスクロールでも公開なら許可する' do
141 context 'adminのとき' do
142 it '他人のの非公開スクロールでも許可する' do
146 context 'クローズドモードのとき' do
148 MagicNumber['run_mode'] = 1
151 it '他人のの非公開スクロールでも許可する' do
155 it '自分のスクロールなら許可する' do
156 Scroll.any_instance.stub(:own?).and_return(true)
157 Scroll.any_instance.stub(:visible).and_return(0)
158 r = @item.visible?([@author])
161 it '他人の非公開スクロールなら許可しない' do
163 it '他人のスクロールでも公開なら許可する' do
166 context 'adminのとき' do
167 it '他人のの非公開スクロールでも許可する' do
173 describe '単体取得に於いて' do
175 @item = FactoryGirl.create :scroll, :author_id => @author.id
178 c = Scroll.show @item.id, @author
181 context '閲覧許可が出なかったとき' do
182 it '403Forbidden例外を返す' do
183 Scroll.any_instance.stub(:visible?).and_return(false)
185 Scroll.show @item.id, @author
186 }.should raise_error(ActiveRecord::Forbidden)
189 context '存在しないスクロールを開こうとしたとき' do
190 it '404RecordNotFound例外を返す' do
192 Scroll.show 110, @author
193 }.should raise_error(ActiveRecord::RecordNotFound)
198 describe '編集取得に於いて' do
200 @item = FactoryGirl.create :scroll, :author_id => @author.id
202 context 'つつがなく終わるとき' do
203 it '単体取得オプションを利用している' do
204 Scroll.stub(:show_opt).with(any_args).and_return({})
205 Scroll.should_receive(:show_opt).with(any_args).exactly(1)
206 r = Scroll.edit @item.id, @author
208 it '所持判定を問い合わせている' do
209 Scroll.any_instance.stub(:own?).with(any_args).and_return(true)
210 Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
211 r = Scroll.edit @item.id, @author
215 Scroll.any_instance.stub(:own?).and_return(true)
216 c = Scroll.edit @item.id, @author.id
219 context '他人のスクロールを開こうとしたとき' do
220 it '403Forbidden例外を返す' do
221 Scroll.any_instance.stub(:own?).and_return(false)
223 Scroll.edit @item.id, @author
224 }.should raise_error(ActiveRecord::Forbidden)
227 context '存在しないスクロールを開こうとしたとき' do
228 it '404RecordNotFound例外を返す' do
230 Scroll.edit 110, @author
231 }.should raise_error(ActiveRecord::RecordNotFound)
238 @item = FactoryGirl.create :scroll, :author_id => @author.id
239 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
240 @item_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @item.id, :panel_id => @panel.id
241 @other_scroll = FactoryGirl.create :scroll, :author_id => @author.id
242 @other_scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @other_scroll.id, :panel_id => @panel.id
244 context 'つつがなく終わるとき' do
247 r = @item.destroy_with_scroll_panel
248 }.should change(Scroll, :count).by(-1)
250 r = Scroll.find @item.id
253 it '自身にリンクしているスクコマをすべて削除する' do
255 r = @item.destroy_with_scroll_panel
256 }.should change(ScrollPanel, :count).by(-1)
258 r = ScrollPanel.find @item_panel.id
262 r = @item.destroy_with_scroll_panel
266 context '削除に失敗したとき' do
268 ScrollPanel.any_instance.stub(:destroy).with(any_args).and_return(false)
271 r = @item.destroy_with_scroll_panel
276 r = @item.destroy_with_scroll_panel
277 }.should_not change(Scroll, :count)
279 r = @item.destroy_with_scroll_panel
280 }.should_not change(ScrollPanel, :count)