--- /dev/null
+module ControllerMacros
+ def list_should_return_filer_or_json action, params = {}
+ # html\8c`\8e®:
+ # \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+ # filer\83e\83\93\83v\83\8c\81[\83g\82ð\95`\89æ\82·\82é
+ get action, params
+ response.should be_success
+ response.should render_template("templates/r/filer/filer")
+ # json\8c`\8e®
+ # \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+ # json\83f\81[\83^\82ð\95Ô\82·
+ get action, params.merge(:format => :json)
+ response.should be_success
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+
+ def announce_sign_in_at_get action, params = {}
+ # html\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h302 Found\82ð\95Ô\82·
+ get action, params
+ response.status.should eq 302
+ response.should redirect_to '/users/sign_in'
+ # json\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h401 Unauthorized\82ð\95Ô\82·
+ get action, params.merge(:format => :json)
+ response.status.should eq 401
+ response.message.should match(/Unauthorized/)
+ end
+
+ def return_ok_at_get action, params = {}
+ # html\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+ get action, params
+ response.should be_success
+ # json\8c`\8e®: \83X\83e\81[\83^\83X\83R\81[\83h200 OK\82ð\95Ô\82·
+ get action, params.merge(:format => :json)
+ response.should be_success
+ end
+
+end
+
if Manifest.manifest.magic_numbers['run_mode'] == 1
describe '一覧表示に於いて' do
before do
- #@scroll = FactoryGirl.create :scroll_hello
- #@author_yas = @scroll.author
@author_yas = FactoryGirl.create :yas_with_scrolls
@user_yas = @author_yas.user
- sign_in @user_yas
end
+
context 'つつがなく終わるとき' do
- it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
+ before do
+ sign_in @user_yas
end
- it '@scrollsにリストを取得している' do
+ it '@itemsにリストを取得している' do
get :index
- assigns(:scrolls).should have_at_least(3).items
- end
- context 'html形式' do
- it 'indexテンプレートを描画する' do
- get :index
- response.should render_template("index")
- end
+ except(assigns(:items).size).to be >= 3
end
- context 'json形式' do
- it 'jsonデータを返す' do
- get :index, :format => :json
- lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
- end
+ it 'ステータスコード200 OKを返す' do
+ list_should_return_filer_or_json :index
end
end
- context 'ユーザ権限がないとき' do
- before do
- sign_out @user_yas
+ context '権限' do
+ it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+ sign_in @admin
+ return_ok_at_get :index
end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :index
- response.status.should eq 302
- end
- it 'サインインページへ遷移する' do
- get :index
- response.should redirect_to '/users/sign_in'
- end
+ it 'ユーザだが作家登録していないとき 200 OKを返す' do
+ @user_rom = FactoryGirl.create :user_rom
+ sign_in @user_rom
+ return_ok_at_get :index
end
- context 'json形式' do
- it 'ステータスコード401 Unauthorizedを返す' do
- get :index, :format => :json
- response.status.should eq 401
- end
- it '応答メッセージにUnauthorizedを返す' do
- get :index, :format => :json
- response.message.should match(/Unauthorized/)
- end
+ it 'sign_inを返す' do
+ announce_sign_in_at_get :index
end
end
- context 'ユーザ権限はないが管理者権限があるとき' do
+ end
+ describe '作家フィルタ一覧及びカウント' do
+ before do
+ @author_yas = FactoryGirl.create :yas_with_scrolls
+ @user_yas = @author_yas.user
+ @scroll = @author_yas.scrolls.first
+ end
+ context 'つつがなく終わるとき' do
before do
- sign_out @user_yas
- sign_in @admin
+ sign_in @user_yas
+ end
+ it '@itemsにリストを取得している' do
+ get :by_author
+ except(assigns(:items).size).to be >= 3
end
it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
+ list_should_return_filer_or_json :by_author, id: @author_yas.id
end
end
- context 'ユーザだが作家登録していないとき' do
- before do
- sign_out @user_yas
- @user_ghost = FactoryGirl.create :user_ghost
- sign_in @user_ghost
+ context '権限' do
+ it 'ユーザ権限はないが管理者権限があるとき 200 OKを返す' do
+ sign_in @admin
+ return_ok_at_get :by_author
end
- context 'html形式' do
- it 'ステータスコード200 OKを返す' do
- get :index
- response.should be_success
- end
+ it 'ユーザだが作家登録していないとき 200 OKを返す' do
+ @user_rom = FactoryGirl.create :user_rom, id: @author_yas.id
+ sign_in @user_rom
+ return_ok_at_get :by_author
+ end
+ it 'sign_inを返す' do
+ announce_sign_in_at_get :by_author, id: @author_yas.id
end
end
end
describe '単体表示に於いて' do
before do
- @scroll = FactoryGirl.create :scroll_hello
- @author_yas = @scroll.author
+ @author_yas = FactoryGirl.create :yas_with_scrolls
@user_yas = @author_yas.user
- Scroll.stub(:show).and_return(@scroll)
- sign_in @user
+ sign_in @user_yas
+ @scroll = @author_yas.scrolls.first
end
context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
get :show, :id => @scroll.id
response.should be_success
end
- it '@scrollにアレを取得している' do
+ it '@itemにアレを取得している' do
get :show, :id => @scroll.id
- assigns(:scroll).id.should eq(@scroll.id)
+ assigns(:item).id.should eq(@scroll.id)
end
context 'html形式' do
it 'showテンプレートを描画する' do
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
end
+ context 'prof形式' do
+ it 'profilerを描画する' do
+ get :show, :id => @scroll.id, :format => :prof
+ response.should render_template("templates/r/profiler/profiler")
+ end
+ end
end
context 'ユーザ権限がないとき' do
before do
ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
sign_in @user
end
- context 'パラメータチェックする' do
- it '与えられたoffsetがセットされている' do
- get :play, :id => @scroll.id, :offset => 5
- assigns(:offset).should eq 5
- end
- it '省略されると@offsetに0値が入る' do
- get :play, :id => @scroll.id
- assigns(:offset).should eq 0
- end
- it '与えられたcountがセットされている' do
- get :play, :id => @scroll.id, :count => 4
- assigns(:panel_count).should eq 4
- end
- it '省略されると@panel_countにデフォルト値が入る' do
- get :play, :id => @scroll.id
- assigns(:panel_count).should eq ScrollPanel.default_panel_size
- end
- it '最大を超えると@panel_countにデフォルト最大値が入る' do
- get :play, :id => @scroll.id, :count => 1500
- assigns(:panel_count).should eq ScrollPanel.max_panel_size
- end
- it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
- get :play, :id => @scroll.id, :count => -1
- assigns(:panel_count).should eq ScrollPanel.default_panel_size
- end
- end
- context '事前チェックする' do
- it 'スクロールモデルに単体取得を問い合わせている' do
- Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
- get :play, :id => @scroll.id
- end
- it 'スクコマモデルにプレイリスト取得を問い合わせている' do
- ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
- get :play, :id => @scroll.id
- end
- end
context 'つつがなく終わるとき' do
it '@scroll_panelsにリストを取得している' do
get :play, :id => @scroll.id
get :play, :id => @scroll.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
- ScrollPanel.should_receive(:list_as_json_text).exactly(1)
- get :play, :id => @scroll.id, :format => :json
- end
- it 'データがリスト構造になっている' do
- get :play, :id => @scroll.id, :format => :json
- json = JSON.parse response.body
- json.should have_at_least(3).items
- end
- it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
- get :play, :id => @scroll.id, :format => :json
- json = JSON.parse response.body
- json.first.has_key?("panel_id").should be_true
- json.first.has_key?("scroll_id").should be_true
- json.first.has_key?("author_id").should be_true
- end
end
end
context 'ユーザ権限がないとき' do