@user_yas = FactoryGirl.create :user_yas_with_owner
@user_rom = FactoryGirl.create :user_rom
@author_yas = @user_yas.author
+
+ @my_model_class = Scroll
end
if Manifest.manifest.magic_numbers['run_mode'] == 1
describe '一覧表示に於いて' do
before do
factory_contents :scroll_hello, @author_yas
+ @query = { }
+ @query_format_json = @query.merge(:format => :json)
end
- context '正常系の共通処理' do
+ context '正常系' do
before do
sign_in @user_yas
end
- it 'ステータス OKを返して、ファイラーまたはjsonデータを返す。' do
- list_should_return_filer_or_json :index
- end
- it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
- get :index
- expect(assigns(:my_model_class)).to be Scroll
- end
- it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
- get :index
- expect(assigns(:list).item_name).to eq('scroll')
- expect(assigns(:list).list_name).to eq('public')
- end
- it '@itemsにリストを取得している' do
- get :index
- expect(assigns(:items).size).to be >= 3
+ context '共通処理' do
+ before do
+ get :index, @query
+ end
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ set_model? @my_model_class
+ end
+ it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+ set_list? 'scroll', 'public'
+ end
+ it '@itemsにリストを取得している' do
+ expect(assigns(:items).size).to be >= 3
+ end
end
context 'html形式' do
+ before do
+ get :index, @query
+ end
+ it 'ステータス OKを返して、ファイラーを描画している' do
+ return_ok?
+ render_filer?
+ end
it '@filerにファイラーを取得している' do
- get :index
- expect(assigns(:filer).class).to be Locmare::Filer
+ let_filer?
end
end
context 'json形式' do
+ before do
+ get :index, @query_format_json
+ end
+ it 'ステータス OKを返して、jsonデータを返している' do
+ return_ok?
+ render_json?
+ end
it '@filerにファイラーをセットしていない' do
- get :index, format: :json
expect(assigns(:filer)).to be nil
end
end
end
context '件数取得' do
- before do
- sign_in @user_yas
- end
- it 'ステータス OKを返す' do
- return_ok_at_get :count, format: :json
- end
context 'html形式' do
it '必要ないので実装していない' do
- get :count
+ sign_in @user_yas
+ get :count, @query
expect(response.status).to eq(406)
end
end
context 'json形式' do
- it 'jsonデータを返す' do
- get :count, format: :json
- expect {JSON.parse(response.body)}.not_to raise_error
+ it 'ステータス OKを返して、jsonデータを返している' do
+ sign_in @user_yas
+ get :count, @query_format_json
+ return_ok?
+ render_json?
+ end
+ end
+ context 'ゲスト(サインインしていない)' do
+ it '通常通り応答する' do
+ get :count, @query_format_json
+ return_ok?
+ render_json?
end
end
end
context 'サインインの状態が例外的なとき' do
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- return_ok_at_get :index
- return_ok_at_get :index, format: :json
+ get :index, @query
+ return_ok?
+ get :index, @query_format_json
+ render_json?
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' do
sign_in @user_rom
- return_ok_at_get :index
- return_ok_at_get :index, format: :json
+ get :index, @query
+ return_ok?
+ get :index, @query_format_json
+ render_json?
end
- it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :index
+ it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+ get :index, @query
+ redirect? sign_in_url
+ get :index, @query_format_json
+ render_unauthorized?
end
end
end
describe '作家フィルタ一覧及びカウント' do
before do
factory_contents :scroll_hello, @author_yas
+ @query = {:id => @author_yas.id}
+ @query_format_json = @query.merge(:format => :json)
end
- context '正常系の共通処理' do
+ 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, id: @author_yas.id
- expect(assigns(:items).size).to be >= 3
+ context '共通処理' do
+ before do
+ get :by_author, @query
+ end
+ it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
+ set_model? @my_model_class
+ end
+ it 'リストグループのマニフェストから新着リストの取得処理を@listに取得している' do
+ set_list? 'scroll', 'by_author'
+ end
+ it '@itemsにリストを取得している' do
+ expect(assigns(:items).size).to be >= 3
+ end
end
context 'html形式' do
+ before do
+ get :by_author, @query
+ end
+ it 'ステータス OKを返して、ファイラーを描画している' do
+ return_ok?
+ render_filer?
+ end
it '@filerにファイラーを取得している' do
- get :by_author, id: @author_yas.id
- expect(assigns(:filer).class).to be Locmare::Filer
+ let_filer?
end
end
context 'json形式' do
+ before do
+ get :by_author, @query_format_json
+ end
+ it 'ステータス OKを返して、jsonデータを返している' do
+ return_ok?
+ render_json?
+ end
it '@filerにファイラーをセットしていない' do
- get :by_author, id: @author_yas.id, format: :json
expect(assigns(:filer)).to be nil
end
end
end
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
+ sign_in @user_yas
+ get :count_by_author, @query
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
+ sign_in @user_yas
+ get :count_by_author, @query_format_json
+ return_ok?
+ render_json?
+ end
+ end
+ context 'ゲスト(サインインしていない)' do
+ it '通常通り応答している' do
+ get :count_by_author, @query_format_json
+ return_ok?
+ render_json?
end
end
end
context 'サインインの状態が例外的なとき' do
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' 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
+ get :by_author, @query
+ return_ok?
+ get :by_author, @query_format_json
+ render_json?
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' 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
+ return_ok?
+ get :by_author, @query_format_json
+ render_json?
end
- it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :by_author, id: @author_yas.id
+ it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+ get :by_author, @query
+ redirect? sign_in_url
+ get :by_author, @query_format_json
+ render_unauthorized?
end
end
end
before do
@item = FactoryGirl.create :scroll_hello, author: @author_yas
@item_id = @item.id
+ @query = {:id => @item_id}
+ @query_format_json = @query.merge(:format => :json)
+ @query_format_prof = @query.merge(:format => :prof)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
- it '[html, json, prof]でステータスコード200 OKを返す' do
- return_ok_at_get :show, id: @item_id
- return_ok_at_get :show, id: @item_id, format: :json
- return_ok_at_get :show, id: @item_id, format: :prof
- end
it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
- get :show, id: @item_id
- expect(assigns(:my_model_class)).to be Scroll
+ get :show, @query
+ set_model? @my_model_class
end
it '@itemにリクエストしたアイテムを取得している' do
- get :show, id: @item_id
+ get :show, @query
expect(assigns(:item)).to eq(@item)
end
context 'html形式' do
- it 'showテンプレートを描画する' do
- get :show, id: @item_id
+ it 'showテンプレートを描画している' do
+ get :show, @query
+ return_ok?
expect(response).to render_template("show")
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :show, id: @item_id, format: :json
- expect {JSON.parse(response.body)}.not_to raise_error
+ get :show, @query_format_json
+ return_ok?
+ render_json?
end
it 'プロファイラーは必要ないので@profilerに用意していない' do
- get :show, id: @item_id, format: :json
+ get :show, @query_format_json
expect(assigns(:profiler)).to be nil
end
end
context 'prof形式' do
- it 'プロファイラーテンプレートを描画する' do
- get :show, id: @item_id, format: :prof
- expect(response).to render_template("templates/r/profiler/profiler")
+ it 'プロファイラーテンプレートを描画している' do
+ get :show, @query_format_prof
+ return_ok?
+ render_profiler?
end
end
end
context 'サインインの状態が例外的なとき' do
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- return_ok_at_get :show, id: @item_id
- return_ok_at_get :show, id: @item_id, format: :json
+ get :show, @query
+ return_ok?
+ get :show, @query_format_json
+ render_json?
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' do
sign_in @user_rom
- return_ok_at_get :show, id: @item_id
- return_ok_at_get :show, id: @item_id, format: :json
+ get :show, @query
+ return_ok?
+ get :show, @query_format_json
+ render_json?
end
- it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :show, id: @item_id
+ it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+ get :show, @query
+ redirect? sign_in_url
+ get :show, @query_format_json
+ render_unauthorized?
end
end
end
before do
@item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
@item_id = @item.id
+ @query = {:id => @item_id}
+ @query_format_json = @query.merge(:format => :json)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
- it '[html, json]でステータス OKを返す' do
- return_ok_at_get :play, id: @item_id
- return_ok_at_get :play, id: @item_id, format: :json
- end
it 'コントローラのマニフェストからScrollPanelモデルを@my_model_classに取得している' do
# リクエストの対象はスクロールであるが、返されるのはスクコマのリストである。
# くれぐれも間違えないように。
- get :play, id: @item_id
- expect(assigns(:my_model_class)).to be ScrollPanel
+ get :play, @query
+ set_model? ScrollPanel
end
it '@itemにリクエストしたスクロールを取得している' do
- get :play, id: @item_id
+ get :play, @query
expect(assigns(:item)).to eq(@item)
end
it 'リストグループのマニフェストからプレイリストの取得処理を@listに取得している' do
- get :play, id: @item_id
- expect(assigns(:list).item_name).to eq('scroll_panel')
- expect(assigns(:list).list_name).to eq('play')
+ get :play, @query
+ set_list? 'scroll_panel', 'play'
end
it '@itemsにプレイリストを取得している' do
- get :play, id: @item_id
- expect(assigns(:items).size).to be >= 3
- expect(assigns(:count)).to be >= 3
- expect(assigns(:pager)).not_to be nil
+ get :play, @query
+ set_play_list?
end
context 'html形式' do
- it 'playテンプレートを描画する' do
- get :play, id: @item_id
+ it 'playテンプレートを描画している' do
+ get :play, @query
+ return_ok?
expect(response).to render_template("play")
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :play, id: @item_id, format: :json
- expect {JSON.parse(response.body)}.not_to raise_error
+ get :play, @query_format_json
+ return_ok?
+ render_json?
end
end
end
context 'サインインの状態が例外的なとき' do
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- return_ok_at_get :play, id: @item_id
- return_ok_at_get :play, id: @item_id, format: :json
+ get :play, @query
+ return_ok?
+ get :play, @query_format_json
+ render_json?
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\82\82é\80\9a常é\80\9aã\82\8aå¿\9cç\94ã\81\97ã\81¦ã\81\84る' do
sign_in @user_rom
- return_ok_at_get :play, id: @item_id
- return_ok_at_get :play, id: @item_id, format: :json
+ get :play, @query
+ return_ok?
+ get :play, @query_format_json
+ render_json?
end
- it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :play, id: @item_id
+ it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+ get :play, @query
+ redirect? sign_in_url
+ get :play, @query_format_json
+ render_unauthorized?
end
end
end
describe '新規作成フォーム表示に於いて' do
before do
+ @query = { }
+ @query_format_json = @query.merge(:format => :json)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
- it '[html, json]でステータス OKを返す' do
- return_ok_at_get :new
- return_ok_at_get :new, format: :json
- end
it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
- get :new
- expect(assigns(:my_model_class)).to be Scroll
+ get :new, @query
+ set_model? @my_model_class
end
it '@itemに新規データを用意している' do
- get :new
+ get :new, @query
@item = assigns(:item)
- expect(@item.is_a?(Scroll)).to be true
+ expect(@item.is_a?(@my_model_class)).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)
+ get :new, @query
+ set_bucket? assigns(:item)
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
+ allow_any_instance_of(@my_model_class).to receive(:supply_default)
+ allow_any_instance_of(@my_model_class).to receive(:boosts)
+ expect_any_instance_of(@my_model_class).to receive(:supply_default)
+ expect_any_instance_of(@my_model_class).to receive(:boosts)
+ get :new, @query
end
context 'html形式' do
- it 'formテンプレートを描画する' do
- get :new
- expect(response).to render_template("templates/r/form/form")
+ it 'formテンプレートを描画している' do
+ get :new, @query
+ return_ok?
+ render_form?
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :new, format: :json
- expect {JSON.parse(response.body)}.not_to raise_error
+ get :new, @query_format_json
+ return_ok?
+ render_json?
end
end
end
context 'サインインの状態が例外的なとき' do
before do
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\97ã\81¦ã\81\84ã\82\8b, ä¾\8bå¤\96ã\82\92ç\99ºç\94\9fã\81\95ã\81\9bã\81¦ã\81\84る' do
sign_in @user_rom
- get :new
- announce_regist_author_for_html
- announce_regist_author_for_json :get
+ get :new, @query
+ redirect? new_author_path
+ announce_regist_author_for_json :get, @query_format_json, :new
end
- it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :new
+ it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+ get :new, @query
+ redirect? sign_in_url
+ get :new, @query_format_json
+ render_unauthorized?
end
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- announce_sign_in_at_get :new
+ get :new, @query
+ redirect? sign_in_url
+ get :new, @query_format_json
+ render_unauthorized?
end
end
end
before do
@attributes = FactoryGirl.attributes_for(:scroll_hello, author_id: @author_yas.id)
@attr = {:scroll => @attributes}
+ @attr_format_json = @attr.merge(:format => :json)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
- allow_save Scroll
- post_save @attr
- expect(assigns(:my_model_class)).to be Scroll
+ allow_save @my_model_class
+ post :create, @attr
+ set_model? @my_model_class
end
it '@itemに新規アイテムを用意している' do
- allow_save Scroll
- post_save @attr
+ allow_save @my_model_class
+ post :create, @attr
@item = assigns(:item)
- expect(@item.is_a?(Scroll)).to be true
+ expect(@item.is_a?(@my_model_class)).to be true
+ end
+ it '作成されている' do
+ expect {
+ post :create, @attr
+ }.to change {@my_model_class.count}.by( 1)
end
context 'html形式' do
- it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
- post_save @attr
- expect(response.status).to eq(302)
- expect(response).to redirect_to Scroll.last
+ it '作成されたアイテムの表示ページへ遷移している' do
+ post :create, @attr
+ redirect? @my_model_class.last
end
end
context 'json形式' do
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
+ post :create, @attr_format_json
+ return_ok?
+ render_json?
end
end
end
context '検証、保存に失敗したとき' do
before do
sign_in @user_yas
- reject_save Scroll
+ reject_save @my_model_class
end
context 'html形式' do
- it 'ã\82¹ã\83\86ã\83¼ã\82¿ã\82¹ã\82³ã\83¼ã\83\89200 OKã\82\92è¿\94ã\81\97ã\81¦, formã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88ã\82\92æ\8f\8fç\94»ã\81\99る' do
- post_save @attr
- expect(response).to be_success
- expect(response).to render_template("templates/r/form/form")
+ it 'ã\82¹ã\83\86ã\83¼ã\82¿ã\82¹ã\82³ã\83¼ã\83\89200 OKã\82\92è¿\94ã\81\97ã\81¦, formã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88ã\82\92æ\8f\8fç\94»ã\81\97ã\81¦ã\81\84る' do
+ post :create, @attr
+ return_ok?
+ render_form?
end
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)
+ post :create, @attr
+ set_bucket? assigns(:item)
end
end
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/)
+ it '処理不能を返している' do
+ post :create, @attr_format_json
+ render_unprocessable?
end
end
end
context 'サインインの状態が例外的なとき' do
before do
- allow_save Scroll
+ allow_save @my_model_class
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\97ã\81¦ã\81\84ã\82\8b, ä¾\8bå¤\96ã\82\92ç\99ºç\94\9fã\81\95ã\81\9bã\81¦ã\81\84る' do
sign_in @user_rom
- post_save @attr
- announce_regist_author_for_html
- announce_regist_author_for_json :post, @attr
+ post :create, @attr
+ redirect? new_author_path
+ announce_regist_author_for_json :post, @attr_format_json, :create
end
- it 'ã\82²ã\82¹ã\83\88(ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81\97ã\81¦ã\81\84ã\81ªã\81\84)ã\81¯ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
- post_save @attr
- announce_sign_in_for_html
- post_save @attr.merge(:format => :json)
- announce_sign_in_for_json
+ it 'ã\82²ã\82¹ã\83\88(ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81\97ã\81¦ã\81\84ã\81ªã\81\84)ã\81¯ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
+ post :create, @attr
+ redirect? sign_in_url
+ post :create, @attr_format_json
+ render_unauthorized?
end
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- post_save @attr
- announce_sign_in_for_html
- post_save @attr.merge(:format => :json)
- announce_sign_in_for_json
+ post :create, @attr
+ redirect? sign_in_url
+ post :create, @attr_format_json
+ render_unauthorized?
end
end
end
before do
@item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
@item_id = @item.id
+ @query = {:id => @item_id}
+ @query_format_json = @query.merge(:format => :json)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
- 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モデルを@my_model_classに取得している' do
- get :edit, id: @item_id
- expect(assigns(:my_model_class)).to be Scroll
+ get :edit, @query
+ set_model? @my_model_class
end
- it '@itemã\81«ã\83ªã\82¯ã\82¨ã\82¹ã\83\88ã\81\97ã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«を取得している' do
- get :edit, id: @item_id
- expect(assigns(:item).is_a?(Scroll)).to be true
+ it '@itemã\81«ã\83ªã\82¯ã\82¨ã\82¹ã\83\88ã\81\97ã\81\9fã\82¢ã\82¤ã\83\86ã\83 を取得している' do
+ get :edit, @query
+ expect(assigns(:item).is_a?(@my_model_class)).to be true
expect(assigns(:item).new_record?).not_to be true
expect(assigns(:item)).to eq(@item)
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
it 'スクロールモデルにデフォルト値補充とブーストを依頼している' do
- allow_any_instance_of(Scroll).to receive(:boosts)
- expect_any_instance_of(Scroll).to receive(:boosts)
- get :edit, id: @item_id
+ allow_any_instance_of(@my_model_class).to receive(:boosts)
+ expect_any_instance_of(@my_model_class).to receive(:boosts)
+ get :edit, @query
end
context 'html形式' do
- it 'formテンプレートを描画する' do
- get :edit, id: @item_id
- expect(response).to render_template("templates/r/form/form")
+ it 'formテンプレートを描画している' do
+ get :edit, @query
+ return_ok?
+ render_form?
+ end
+ it '@formに入力フォーム(Bucket)を取得している' do
+ get :edit, @query
+ set_bucket? assigns(:item)
end
end
context 'json形式' do
it 'jsonデータを返す' do
- get :edit, id: @item_id, format: :json
- expect {JSON.parse(response.body)}.not_to raise_error
+ get :edit, @query_format_json
+ return_ok?
+ render_json?
end
end
end
context 'サインインの状態が例外的なとき' do
before do
- allow_save Scroll
+ allow_save @my_model_class
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\97ã\81¦ã\81\84ã\82\8b, ä¾\8bå¤\96ã\82\92ç\99ºç\94\9fã\81\95ã\81\9bã\81¦ã\81\84る' do
sign_in @user_rom
- get :edit, id: @item_id
- expect(response.status).to eq(302)
- expect(response).to redirect_to new_author_path
+ get :edit, @query
+ redirect? new_author_path
+ announce_regist_author_for_json :get, @query_format_json, :edit
end
- it 'ゲスト(サインインしていない)はサインインページに遷移する' do
- announce_sign_in_at_get :new
+ it 'ゲスト(サインインしていない)はサインインページに遷移している' do
+ post :edit, @query
+ redirect? sign_in_url
+ post :edit, @query_format_json
+ render_unauthorized?
end
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- announce_sign_in_at_get :new
+ post :edit, @query
+ redirect? sign_in_url
+ post :edit, @query_format_json
+ render_unauthorized?
end
end
end
@item_id = @item.id
@attributes = FactoryGirl.attributes_for(:scroll_hidden, author_id: @author_yas.id)
@attr = {:id => @item_id, :scroll => @attributes}
+ @attr_format_json = @attr.merge(:format => :json)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
- allow_save Scroll
- put_save @attr
- expect(assigns(:my_model_class)).to be Scroll
+ allow_save @my_model_class
+ put :update, @attr
+ set_model? @my_model_class
end
it '@itemにリクエストしたアイテムを取得して, 更新している' do
- allow_save Scroll
- put_save @attr
- expect(assigns(:item).is_a?(Scroll)).to be true
+ allow_save @my_model_class
+ put :update, @attr
+ expect(assigns(:item).is_a?(@my_model_class)).to be true
expect(assigns(:item).visible).to eq(0)
expect(assigns(:item)).to eq(@item)
end
context 'html形式' do
- it 'ステータスコード302 Foundを返して, 作成されたアイテムの表示ページへ遷移する' do
- put_save @attr
- expect(response.status).to eq(302)
- expect(response).to redirect_to @item
+ it '作成されたアイテムの表示ページへ遷移している' do
+ put :update, @attr
+ redirect? @item
end
end
context 'json形式' do
it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
- put_save @attr.merge(:format => :json)
- expect(response).to be_success
+ put :update, @attr_format_json
+ return_ok?
expect(response.message).to match /./
end
end
context '検証、保存に失敗したとき' do
before do
sign_in @user_yas
- reject_save Scroll
+ reject_save @my_model_class
end
context 'html形式' do
- it 'ã\82¹ã\83\86ã\83¼ã\82¿ã\82¹ã\82³ã\83¼ã\83\89200 OKã\82\92è¿\94ã\81\97ã\81¦, formã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88ã\82\92æ\8f\8fç\94»ã\81\99る' do
- put_save @attr
- expect(response).to be_success
- expect(response).to render_template("templates/r/form/form")
+ it 'ã\82¹ã\83\86ã\83¼ã\82¿ã\82¹ã\82³ã\83¼ã\83\89200 OKã\82\92è¿\94ã\81\97ã\81¦, formã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88ã\82\92æ\8f\8fç\94»ã\81\97ã\81¦ã\81\84る' do
+ put :update, @attr
+ return_ok?
+ render_form?
end
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)
+ put :update, @attr
+ set_bucket? assigns(:item)
end
end
context 'json形式' do
- 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/)
+ it '処理不能を返している' do
+ put :update, @attr_format_json
+ render_unprocessable?
end
end
end
context 'サインインの状態が例外的なとき' do
before do
- allow_save Scroll
+ allow_save @my_model_class
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\97ã\81¦ã\81\84ã\82\8b, ä¾\8bå¤\96ã\82\92ç\99ºç\94\9fã\81\95ã\81\9bã\81¦ã\81\84る' do
sign_in @user_rom
- put_save @attr
- announce_regist_author_for_html
- announce_regist_author_for_json :put, @attr
+ put :update, @attr
+ redirect? new_author_path
+ announce_regist_author_for_json :put, @attr_format_json, :update
end
- it 'ã\82²ã\82¹ã\83\88(ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81\97ã\81¦ã\81\84ã\81ªã\81\84)ã\81¯ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
- put_save @attr
- announce_sign_in_for_html
- put_save @attr.merge(:format => :json)
- announce_sign_in_for_json
+ it 'ã\82²ã\82¹ã\83\88(ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81\97ã\81¦ã\81\84ã\81ªã\81\84)ã\81¯ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
+ put :update, @attr
+ redirect? sign_in_url
+ put :update, @attr_format_json
+ render_unauthorized?
end
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- put_save @attr
- announce_sign_in_for_html
- put_save @attr.merge(:format => :json)
- announce_sign_in_for_json
+ put :update, @attr
+ redirect? sign_in_url
+ put :update, @attr_format_json
+ render_unauthorized?
end
end
end
@item = FactoryGirl.create :scroll_hello_with_scroll_panels, author: @author_yas
@item_id = @item.id
@attr = {:id => @item_id}
- @attr_with_json = @attr.merge(:format => :json)
+ @attr_format_json = @attr.merge(:format => :json)
end
context '正常系の共通処理' do
before do
sign_in @user_yas
end
it 'コントローラのマニフェストからScrollモデルを@my_model_classに取得している' do
- allow_destroy Scroll
- destroy_save @attr
- expect(assigns(:my_model_class)).to be Scroll
+ allow_destroy @my_model_class
+ delete :destroy, @attr
+ set_model? @my_model_class
end
it '@itemにリクエストしたアイテムを取得している' do
- allow_destroy Scroll
- destroy_save @attr
- expect(assigns(:item).is_a?(Scroll)).to be true
+ allow_destroy @my_model_class
+ delete :destroy, @attr
+ expect(assigns(:item).is_a?(@my_model_class)).to be true
expect(assigns(:item)).to eq(@item)
end
it '削除されている' do
- lambda {
- destroy_save @attr
- }.should change Scroll, :count
+ expect {
+ delete :destroy, @attr
+ }.to change {@my_model_class.count}.by(-1)
end
it 'ぶら下がるリーフも削除されている' do
- lambda {
- destroy_save @attr
- }.should change ScrollPanel, :count
+ expect {
+ delete :destroy, @attr
+ }.to change {ScrollPanel.count}.from(4).to(0)
end
context 'html形式' do
- it 'ステータスコード302 Foundを返して, マイスクロールの一覧ページへ遷移する' do
- destroy_save @attr
- expect(response.status).to eq(302)
- expect(response).to redirect_to '/home/scrolls'
+ it 'マイスクロールの一覧ページへ遷移している' do
+ delete :destroy, @attr
+ redirect? '/home/scrolls'
end
end
context 'json形式' do
it 'ステータスコード200 OKを返して, ページ本体は特に返さない' do
- destroy_save @attr_with_json
+ delete :destroy, @attr_format_json
expect(response).to be_success
expect(response.message).to match /./
end
context '検証、保存に失敗したとき' do
before do
sign_in @user_yas
- reject_destroy Scroll
+ reject_destroy @my_model_class
end
context 'html形式' do
- it 'ステータスコード302 Foundを返して, そのスクロールの詳細ページへ遷移する' do
- destroy_save @attr
- expect(response.status).to eq(302)
- expect(response).to redirect_to @item
+ it 'リクエストしたアイテムの詳細ページへ遷移している' do
+ delete :destroy, @attr
+ redirect? @item
end
end
context 'json形式' do
- it 'ステータスコード422 unprocessable_entityを返して, 応答メッセージUnprocessable Entityを返す' do
- destroy_save @attr_with_json
- expect(response.status).to eq(422)
- expect(response.message).to match(/Unprocessable/)
+ it '処理不能を返している' do
+ delete :destroy, @attr_format_json
+ render_unprocessable?
end
end
end
context 'サインインの状態が例外的なとき' do
before do
- allow_destroy Scroll
+ allow_destroy @my_model_class
end
- it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81«ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\99る' do
+ it 'å\89µä½\9cæ´»å\8b\95ã\81\97ã\81¦ã\81ªã\81\84ROMå°\82ã\81®èªè\80\85ã\81¯ä½\9c家ç\99»é\8c²ã\83\9aã\83¼ã\82¸ã\81¸é\81·ç§»ã\81\97ã\81¦ã\81\84ã\82\8b, ä¾\8bå¤\96ã\82\92ç\99ºç\94\9fã\81\95ã\81\9bã\81¦ã\81\84る' do
sign_in @user_rom
- destroy_save @attr
- announce_regist_author_for_html
- announce_regist_author_for_json :delete, @attr_with_json
+ delete :destroy, @attr
+ redirect? new_author_path
+ announce_regist_author_for_json :delete, @attr_format_json, :destroy
end
- it 'ã\82²ã\82¹ã\83\88(ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81\97ã\81¦ã\81\84ã\81ªã\81\84)ã\81¯ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
- destroy_save @attr
- announce_sign_in_for_html
- destroy_save @attr_with_json
- announce_sign_in_for_json
+ it 'ã\82²ã\82¹ã\83\88(ã\82µã\82¤ã\83³ã\82¤ã\83³ã\81\97ã\81¦ã\81\84ã\81ªã\81\84)ã\81¯ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
+ delete :destroy, @attr
+ redirect? sign_in_url
+ delete :destroy, @attr_format_json
+ render_unauthorized?
end
- it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\99る' do
+ it 'ã\83¦ã\83¼ã\82¶ã\81§ã\81¯ã\81ªã\81\8f管ç\90\86è\80\85ã\81§ã\82\82ã\82µã\82¤ã\83³ã\82¤ã\83³ã\83\9aã\83¼ã\82¸ã\81«é\81·ç§»ã\81\97ã\81¦ã\81\84る' do
sign_in @admin
- destroy_save id: @item_id
- announce_sign_in_for_html
- destroy_save @attr_with_json
- announce_sign_in_for_json
+ delete :destroy, @attr
+ redirect? sign_in_url
+ delete :destroy, @attr_format_json
+ render_unauthorized?
end
end
end