describe ScrollsController do
before do
@admin =FactoryGirl.create :admin
- @author_yas = FactoryGirl.create :yas_with_scrolls
- @user_yas = @author_yas.user
+ @user_yas = FactoryGirl.create :user_yas_with_owner
@user_rom = FactoryGirl.create :user_rom
+ @author_yas = @user_yas.author
end
if Manifest.manifest.magic_numbers['run_mode'] == 1
describe '一覧表示に於いて' do
before do
+ factory_contents :scroll_hello, @author_yas
end
context '正常系の共通処理' do
it 'ステータス OKを返す' do
return_ok_at_get :count, format: :json
end
+ context 'html形式' do
+ it '必要ないので実装していない' do
+ get :count
+ expect(response.status).to eq(406)
+ end
+ end
context 'json形式' do
it 'jsonデータを返す' do
get :count, format: :json
end
describe '作家フィルタ一覧及びカウント' do
before do
+ factory_contents :scroll_hello, @author_yas
end
+
context '正常系の共通処理' do
before do
sign_in @user_yas
end
+ it 'ステータス OKを返して、ファイラーまたはjsonデータを返す。' do
+ list_should_return_filer_or_json :by_author, id: @author_yas.id
+ end
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ get :by_author, id: @author_yas.id
+ expect(assigns(:my_model_class)).to be Scroll
+ end
+ it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+ get :by_author, id: @author_yas.id
+ expect(assigns(:list).item_name).to eq('scroll')
+ expect(assigns(:list).list_name).to eq('by_author')
+ end
it '@itemsにリストを取得している' do
- get :by_author
+ get :by_author, id: @author_yas.id
expect(assigns(:items).size).to be >= 3
end
- it 'ステータスコード200 OKを返す' do
- list_should_return_filer_or_json :by_author, id: @author_yas.id
+ context 'html形式' do
+ it '@filerにファイラーを取得している' do
+ get :by_author, id: @author_yas.id
+ expect(assigns(:filer).class).to be Locmare::Filer
+ end
+ end
+ context 'json形式' do
+ it '@filerにファイラーをセットしていない' do
+ get :by_author, id: @author_yas.id, format: :json
+ expect(assigns(:filer)).to be nil
+ end
end
end
- context '権限' do
- it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+ context '件数取得' do
+ before do
+ sign_in @user_yas
+ end
+ it 'ステータス OKを返す' do
+ return_ok_at_get :count_by_author, id: @author_yas.id, format: :json
+ end
+ context 'html形式' do
+ it '必要ないので実装していない' do
+ get :count_by_author, id: @author_yas.id
+ expect(response.status).to eq(406)
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :count_by_author, id: @author_yas.id, format: :json
+ expect {JSON.parse(response.body)}.not_to raise_error
+ end
+ end
+ end
+ context 'サインインの状態が例外的なとき' do
+ it 'ユーザではなく管理者でも通常通り応答する' do
sign_in @admin
return_ok_at_get :by_author, id: @author_yas.id
return_ok_at_get :by_author, id: @author_yas.id, format: :json
end
- it 'ユーザだが作家登録していないとき 200 OKを返す' do
+ it '創作活動してないROM専の読者にも通常通り応答する' do
sign_in @user_rom
return_ok_at_get :by_author, id: @author_yas.id
return_ok_at_get :by_author, id: @author_yas.id, format: :json
end
- it 'sign_inを返す' do
+ it 'ゲスト(サインインしていない)はサインインページに遷移する' do
announce_sign_in_at_get :by_author, id: @author_yas.id
end
end
describe '単体表示に於いて' do
before do
- @item = @author_yas.scrolls.first
+ @item = FactoryGirl.create :scroll_hello, author: @author_yas
@item_id = @item.id
end
context '正常系の共通処理' do
describe 'プレイリストに於いて' do
before do
- @item = @author_yas.scrolls.first
+ @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
@item_id = @item.id
end
context '正常系の共通処理' do
it 'コントローラのマニフェストからScrollPanelモデルを@my_model_classに取得している' do
# リクエストの対象はスクロールであるが、返されるのはスクコマのリストである。
# くれぐれも間違えないように。
- get :play, :id => @item_id
+ get :play, id: @item_id
expect(assigns(:my_model_class)).to be ScrollPanel
end
it '@itemにリクエストしたスクロールを取得している' do
- get :play, :id => @item_id
+ get :play, id: @item_id
expect(assigns(:item)).to eq(@item)
end
it 'リストグループのマニフェストからプレイリストの取得処理を@listに取得している' do
- get :play, :id => @item_id
+ get :play, id: @item_id
expect(assigns(:list).item_name).to eq('scroll_panel')
expect(assigns(:list).list_name).to eq('play')
end
it '@itemsにプレイリストを取得している' do
- get :play, :id => @item_id
+ get :play, id: @item_id
expect(assigns(:items).size).to be >= 3
expect(assigns(:count)).to be >= 3
- expect(assigns(:pager)).to be nil
+ expect(assigns(:pager)).not_to be nil
end
context 'html形式' do
it 'playテンプレートを描画する' do
- get :play, :id => @item_id
+ get :play, id: @item_id
expect(response).to render_template("play")
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :play, :id => @item_id, :format => :json
+ get :play, id: @item_id, format: :json
expect {JSON.parse(response.body)}.not_to raise_error
end
end
describe '新規作成フォーム表示に於いて' do
before do
- @item = @author_yas.scrolls.first
- @item_id = @item.id
end
context '正常系の共通処理' do
before do
end
it '@itemに新規データを用意している' do
get :new
- expect(assigns(:item)).to eq(@item)
+ @item = assigns(:item)
+ expect(@item.is_a?(Scroll)).to be true
+ expect(@item.new_record?).to be true
end
it '@formに入力フォーム(Bucket)を取得している' do
get :new
+ @item = assigns(:item)
expect(assigns(:form).item).to eq(@item)
expect(assigns(:form).mounted).to eq(true)
expect(assigns(:form).submit).to eq(true)
end
it 'スクロールモデルにデフォルト値補充とブーストを依頼している' do
+ allow_any_instance_of(Scroll).to receive(:supply_default)
+ allow_any_instance_of(Scroll).to receive(:boosts)
expect_any_instance_of(Scroll).to receive(:supply_default)
expect_any_instance_of(Scroll).to receive(:boosts)
get :new
end
context 'サインインの状態が例外的なとき' do
before do
- sign_in @user_rom
end
it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+ sign_in @user_rom
get :new
- expect(response.status).to eq(302)
- expect(response).to redirect_to new_author_path
- return_ok_at_get :play, id: @item_id, format: :json
+ announce_regist_author_for_html
+ announce_regist_author_for_json :get
end
it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :new, id: @item_id
+ announce_sign_in_at_get :new
end
it 'ユーザではなく管理者でもサインインページに遷移する' do
sign_in @admin
- announce_sign_in_at_get :new, id: @item_id
- end
- end
- context 'ユーザだが作家登録していないとき' do
- before do
- @author.destroy
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :new, @attr
- response.status.should eq 302
- end
- it '' do
- get :new, @attr
- response.body.should redirect_to new_author_path
- end
+ announce_sign_in_at_get :new
end
end
end
describe '新規作成に於いて' do
before do
- sign_in @user
- @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
- end
- context '事前チェックしておく' do
- it 'スクロールモデルにデフォルト値補充を依頼している' do
- Scroll.any_instance.should_receive(:supply_default).exactly(1)
- post :create, :scroll => @attr
- end
- it 'スクロールモデルにカラム値復元を依頼している' do
- Scroll.any_instance.should_receive(:attributes=).exactly(1)
- post :create, :scroll => @attr
- end
- it 'スクロールモデルに上書き補充を依頼している' do
- Scroll.any_instance.should_receive(:overwrite).exactly(1)
- post :create, :scroll => @attr
- end
- it 'モデルに保存依頼する' do
- Scroll.any_instance.should_receive(:save).exactly(1)
- post :create, :scroll => @attr
- end
+ @attributes = FactoryGirl.attributes_for(:scroll_hello, author_id: @author_yas.id)
+ @attr = {:scroll => @attributes}
end
context '正常系の共通処理' do
- it "@scrollに作成されたスクロールを保持していて、それがDBにある" do
- post :create, :scroll => @attr
- assigns(:scroll).should be_a(Scroll)
- assigns(:scroll).should be_persisted
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- Scroll.any_instance.stub(:save).and_return(true)
- post :create, :scroll => @attr
- response.status.should eq 302
- end
- it '作成されたスクロールの表示ページへ遷移する' do
-# Scroll.any_instance.stub(:save).and_return(true)
- post :create, :scroll => @attr
- response.should redirect_to(Scroll.last)
- end
+ before do
+ sign_in @user_yas
end
- context 'json形式' do
- it 'ステータスコード200 OKを返す' do
-# Scroll.any_instance.stub(:save).and_return(true)
- post :create, :scroll => @attr, :format => :json
- response.should be_success
- end
- it '作成されたスクロールをjsonデータで返す' do
- post :create, :scroll => @attr, :format => :json
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
- end
- it 'データがアレになっている' do
- post :create, :scroll => @attr, :format => :json
- json = JSON.parse response.body
- json["title"].should match(/normal/)
- json["visible"].should_not be_nil
- end
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ allow_save Scroll
+ post_save @attr
+ expect(assigns(:my_model_class)).to be Scroll
end
- end
- context 'ユーザ権限がないとき' do
- before do
- sign_out @user
+ it '@itemに新規アイテムを用意している' do
+ allow_save Scroll
+ post_save @attr
+ @item = assigns(:item)
+ expect(@item.is_a?(Scroll)).to be true
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, :scroll => @attr
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- post :create, :scroll => @attr
- response.body.should redirect_to '/users/sign_in'
+ it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
+ post_save @attr
+ expect(response.status).to eq(302)
+ expect(response).to redirect_to Scroll.last
end
end
context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- post :create, :scroll => @attr, :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- post :create, :scroll => @attr, :format => :json
- response.message.should match(/Unauthorized/)
+ it 'ステータスコード200 OKを返して, 作成されたアイテムをjsonデータで返す' do
+ post_save @attr.merge(:format => :json)
+ expect(response).to be_success
+ expect {JSON.parse(response.body)}.not_to raise_error
end
end
end
- context 'ユーザ権限はないが管理者権限があるとき' do
+ context '検証、保存に失敗したとき' do
before do
- sign_out @user
- sign_in @admin
+ sign_in @user_yas
+ reject_save Scroll
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, :scroll => @attr
- response.status.should eq 302
+ it 'ステータスコード200 OKを返して, formテンプレートを描画する' do
+ post_save @attr
+ expect(response).to be_success
+ expect(response).to render_template("templates/r/form/form")
end
- it 'サインインページへ遷移する' do
- post :create, :scroll => @attr
- response.body.should redirect_to '/users/sign_in'
+ it '@formに入力フォーム(Bucket)を取得している' do
+ post_save @attr
+ @item = assigns(:item)
+ expect(assigns(:form).item).to eq(@item)
+ expect(assigns(:form).mounted).to eq(true)
+ expect(assigns(:form).submit).to eq(true)
end
end
- end
- context 'ユーザだが作家登録していないとき' do
- before do
- @author.destroy
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- post :create, :scroll => @attr
- response.status.should eq 302
- end
- it '作家登録ページへ遷移する' do
- post :create, :scroll => @attr
- response.body.should redirect_to new_author_path
+ context 'json形式' do
+ it 'ステータスコード422 unprocessable_entityを返して, 応答メッセージUnprocessable Entityを返す' do
+ post_save @attr.merge(:format => :json)
+ expect(response.status).to eq(422)
+ expect(response.message).to match(/Unprocessable/)
end
end
end
- context '検証、保存に失敗した' do
+ context 'サインインの状態が例外的なとき' do
before do
- Scroll.any_instance.stub(:save).and_return(false)
+ allow_save Scroll
end
- it "未保存のスクロールを保持している" do
- post :create, :scroll => @attr
- assigns(:scroll).should be_a_new(Scroll)
+ it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+ sign_in @user_rom
+ post_save @attr
+ announce_regist_author_for_html
+ announce_regist_author_for_json :post, @attr
end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- post :create, :scroll => @attr
- response.status.should eq 200
- end
- it '新規ページを描画する' do
- post :create, :scroll => @attr
- response.should render_template("new")
- end
+ it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+ post_save @attr
+ announce_sign_in_for_html
+ post_save @attr.merge(:format => :json)
+ announce_sign_in_for_json
end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- post :create, :scroll => @attr, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- post :create, :scroll => @attr, :format => :json
- response.message.should match(/Unprocessable/)
- end
+ it 'ユーザではなく管理者でもサインインページに遷移する' do
+ sign_in @admin
+ post_save @attr
+ announce_sign_in_for_html
+ post_save @attr.merge(:format => :json)
+ announce_sign_in_for_json
end
end
end
describe '編集フォーム表示に於いて' do
before do
- @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
- sign_in @user
- Scroll.stub(:edit).and_return(@scroll)
+ @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
+ @item_id = @item.id
end
context '正常系の共通処理' do
- it 'ステータスコード200 OKを返す' do
- get :edit, :id => @scroll.id
- response.should be_success
+ before do
+ sign_in @user_yas
end
- it 'スクロールモデルに編集取得を問い合わせている' do
- Scroll.should_receive(:edit).exactly(1)
- get :edit, :id => @scroll.id
+ it '[html, json]でステータス OKを返す' do
+ return_ok_at_get :edit, id: @item_id
+ return_ok_at_get :edit, id: @item_id, format: :json
end
- it '@scrollにデータを用意している' do
- get :edit, :id => @scroll.id
- assigns(:scroll).should eq @scroll
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ get :edit, id: @item_id
+ expect(assigns(:my_model_class)).to be Scroll
end
- context 'html形式' do
- it 'editテンプレートを描画する' do
- get :edit, :id => @scroll.id
- response.should render_template("edit")
- end
+ it '@itemにリクエストしたスクロールを取得している' do
+ get :edit, id: @item_id
+ @item = assigns(:item)
+ expect(@item.is_a?(Scroll)).to be true
+ expect(@item.new_record?).not_to be true
end
- context 'js形式' do
- it 'edit.jsテンプレートを描画する' do
- get :edit, :id => @scroll.id, :format => :js
- response.should render_template("edit")
- end
+ it '@formに入力フォーム(Bucket)を取得している' do
+ get :edit, id: @item_id
+ @item = assigns(:item)
+ expect(assigns(:form).item).to eq(@item)
+ expect(assigns(:form).mounted).to eq(true)
+ expect(assigns(:form).submit).to eq(true)
end
- end
- context 'ユーザ権限がないとき' do
- before do
- sign_out @user
+ it 'スクロールモデルにデフォルト値補充とブーストを依頼している' do
+ allow_any_instance_of(Scroll).to receive(:boosts)
+ expect_any_instance_of(Scroll).to receive(:boosts)
+ get :edit, id: @item_id
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :edit, :id => @scroll.id
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- get :edit, :id => @scroll.id
- response.body.should redirect_to '/users/sign_in'
+ it 'formテンプレートを描画する' do
+ get :edit, id: @item_id
+ expect(response).to render_template("templates/r/form/form")
end
end
- context 'js形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- get :edit, :id => @scroll.id, :format => :js
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- get :edit, :id => @scroll.id, :format => :js
- response.message.should match(/Unauthorized/)
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :edit, id: @item_id, format: :json
+ expect {JSON.parse(response.body)}.not_to raise_error
end
end
end
- context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81¯ã\81ªã\81\84ã\81\8c管ç\90\86è\80\85権é\99\90ã\81\8cã\81\82ã\82\8bとき' do
+ context 'ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81®ç\8a¶æ\85\8bã\81\8cä¾\8bå¤\96ç\9a\84ã\81ªとき' do
before do
- sign_out @user
- sign_in @admin
+ allow_save Scroll
end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :edit, :id => @scroll.id
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- get :edit, :id => @scroll.id
- response.body.should redirect_to '/users/sign_in'
- end
+ it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+ sign_in @user_rom
+ get :edit, id: @item_id
+ expect(response.status).to eq(302)
+ expect(response).to redirect_to new_author_path
end
- end
- context 'ユーザだが作家登録していないとき' do
- before do
- @author.destroy
+ it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+ announce_sign_in_at_get :new
end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :edit, :id => @scroll.id
- response.status.should eq 302
- end
- it '作家登録ページへ遷移する' do
- get :edit, :id => @scroll.id
- response.body.should redirect_to new_author_path
- end
+ it 'ユーザではなく管理者でもサインインページに遷移する' do
+ sign_in @admin
+ announce_sign_in_at_get :new
end
end
end
describe '更新に於いて' do
before do
- @scroll = FactoryGirl.create :scroll, :author => @author
- @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'updated title', :visible => 0)
- sign_in @user
+ @item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
+ @item_id = @item.id
+ @attributes = FactoryGirl.attributes_for(:scroll_hidden, author_id: @author_yas.id)
+ @attr = {:id => @item_id, :scroll => @attributes}
end
- context '事前チェックしておく' do
- it 'スクロールモデルに編集取得を問い合わせている' do
- Scroll.stub(:edit).with(any_args()).and_return @scroll
- Scroll.should_receive(:edit).exactly(1)
- put :update, :id => @scroll.id, :scroll => @attr
- end
- it 'スクロールモデルにカラム値復元を依頼している' do
- Scroll.any_instance.should_receive(:attributes=).exactly(1)
- put :update, :id => @scroll.id, :scroll => @attr
- end
- it 'スクロールモデルに上書き補充を依頼している' do
- Scroll.any_instance.should_receive(:overwrite).exactly(1)
- put :update, :id => @scroll.id, :scroll => @attr
- end
- it 'モデルに更新を依頼する' do
- Scroll.any_instance.stub(:save).with(any_args).and_return true
- Scroll.any_instance.should_receive(:save).exactly(1)
- put :update, :id => @scroll.id, :scroll => @attr
+ context '正常系の共通処理' do
+ before do
+ sign_in @user_yas
end
- it '@scrollにアレを取得している' do
- put :update, :id => @scroll.id, :scroll => @attr
- assigns(:scroll).id.should eq(@scroll.id)
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ allow_save Scroll
+ put_save @attr
+ expect(assigns(:my_model_class)).to be Scroll
end
- end
- context '正常系の共通処理' do
- it '更新される' do
- put :update, :id => @scroll.id, :scroll => @attr
- Scroll.find(@scroll.id).visible.should eq 0
+ it '@itemにリクエストしたアイテムを取得して, 更新している' do
+ allow_save Scroll
+ put_save @attr
+ @item = assigns(:item)
+ expect(@item.is_a?(Scroll)).to be true
+ expect(@item.visible).to eq(0)
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
- put :update, :id => @scroll.id, :scroll => @attr
- response.status.should eq 302
- end
- it '更新されたスクロールの表示ページへ遷移する' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.should redirect_to(@scroll)
+ it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
+ put_save @attr
+ expect(response.status).to eq(302)
+ expect(response).to redirect_to @item
end
end
context 'json形式' do
- it 'ステータスコード200 OKを返す' do
- Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
- put :update, :id => @scroll.id, :scroll => @attr, :format => :json
- response.should be_success
- end
- it 'ページ本体は特に返さない' do
- Scroll.any_instance.stub(:save).with(any_args()).and_return(true)
- put :update, :id => @scroll.id, :scroll => @attr, :format => :json
- response.body.should match /./
+ it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
+ put_save @attr.merge(:format => :json)
+ expect(response).to be_success
+ expect(response.message).to match /./
end
end
end
- context 'ユーザ権限がないとき' do
+ context '検証、保存に失敗したとき' do
before do
- sign_out @user
+ sign_in @user_yas
+ reject_save Scroll
end
context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.status.should eq 302
+ it 'ステータスコード200 OKを返して, formテンプレートを描画する' do
+ put_save @attr
+ expect(response).to be_success
+ expect(response).to render_template("templates/r/form/form")
end
- it 'サインインページへ遷移する' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.body.should redirect_to '/users/sign_in'
+ it '@formに入力フォーム(Bucket)を取得している' do
+ put_save @attr
+ @item = assigns(:item)
+ expect(assigns(:form).item).to eq(@item)
+ expect(assigns(:form).mounted).to eq(true)
+ expect(assigns(:form).submit).to eq(true)
end
end
context 'json形式' do
- it '応答メッセージにUnauthorizedを返す' do
- put :update, :id => @scroll.id, :scroll => @attr, :format => :json
- response.message.should match(/Unauthorized/)
+ it 'ステータスコード422 unprocessable_entityを返して, 応答メッセージUnprocessable Entityを返す' do
+ put_save @attr.merge(:format => :json)
+ expect(response.status).to eq(422)
+ expect(response.message).to match(/Unprocessable/)
end
end
end
- context 'ユーザ権限はないが管理者権限があるとき' do
- before do
- sign_out @user
- sign_in @admin
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.body.should redirect_to '/users/sign_in'
- end
- end
- end
- context 'ユーザだが作家登録していないとき' do
+ context 'サインインの状態が例外的なとき' do
before do
- @author.destroy
+ allow_save Scroll
end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.status.should eq 302
- end
- it '作家登録ページへ遷移する' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.body.should redirect_to new_author_path
- end
- end
- end
- context '検証、保存に失敗したとき' do
- before do
- Scroll.any_instance.stub(:save).and_return(false)
+ it '創作活動してないROM専の読者には作家登録ページへ遷移する' do
+ sign_in @user_rom
+ put_save @attr
+ announce_regist_author_for_html
+ announce_regist_author_for_json :put, @attr
end
- context 'html形式' do
- it 'ステータスコード200 Okを返す' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.status.should eq 200
- end
- it '編集ページを描画する' do
- put :update, :id => @scroll.id, :scroll => @attr
- response.should render_template("edit")
- end
+ it 'ゲスト(サインインしていない)はサインインページに遷移する' do
+ put_save @attr
+ announce_sign_in_for_html
+ put_save @attr.merge(:format => :json)
+ announce_sign_in_for_json
end
- context 'json形式' do
- it 'ステータスコード422 unprocessable_entity を返す' do
- Scroll.any_instance.stub(:save).and_return(false)
- put :update, :id => @scroll.id, :scroll => @attr, :format => :json
- response.status.should eq 422
- end
- it '応答メッセージUnprocessable Entityを返す' do
- put :update, :id => @scroll.id, :scroll => @attr, :format => :json
- response.message.should match(/Unprocessable/)
- end
+ it 'ユーザではなく管理者でもサインインページに遷移する' do
+ sign_in @admin
+ put_save @attr
+ announce_sign_in_for_html
+ put_save @attr.merge(:format => :json)
+ announce_sign_in_for_json
end
end
end