# -*- encoding: utf-8 -*-
require 'spec_helper'
-#ã\82³ã\83\9fã\83\83ã\82¯
+#ã\82¹ã\82¯ã\83ã\83¼ã\83«
describe ScrollsController do
before do
@admin =FactoryGirl.create :admin
get :index
response.should be_success
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに一覧を問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに一覧を問い合わせている' do
Scroll.should_receive(:list).exactly(1)
get :index
end
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson一覧出力オプションを問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにjson一覧出力オプションを問い合わせている' do
Scroll.should_receive(:list_json_opt).exactly(1)
get :index, :format => :json
end
json = JSON.parse response.body
json.should have_at_least(3).items
end
- it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯ã\82³ã\83\9fã\83\83ã\82¯っぽいものであって欲しい' do
+ it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ã\81\8fã\82\89ã\81\84ã\81¯ã\82¹ã\82¯ã\83ã\83¼ã\83«っぽいものであって欲しい' do
get :index, :format => :json
json = JSON.parse response.body
json.first.has_key?("title").should be_true
get :show, :id => @scroll.id
response.should be_success
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに単体取得を問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに単体取得を問い合わせている' do
Scroll.should_receive(:show).exactly(1)
get :show
end
get :show, :id => @scroll.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson単体出力オプションを問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにjson単体出力オプションを問い合わせている' do
Scroll.should_receive(:show_json_opt).exactly(1)
get :show, :id => @scroll.id, :format => :json
end
end
end
=begin
- context '対象ã\82³ã\83\9fã\83\83ã\82¯がないとき' do
+ context '対象ã\82¹ã\82¯ã\83ã\83¼ã\83«がないとき' do
context 'html形式' do
it '例外404 not_foundを返す' do
lambda{
end
end
end
- context 'é\9d\9eå\85¬é\96\8bã\82³ã\83\9fã\83\83ã\82¯を見ようとしたとき' do
+ context 'é\9d\9eå\85¬é\96\8bã\82¹ã\82¯ã\83ã\83¼ã\83«を見ようとしたとき' do
context 'html形式' do
it '例外403 forbiddenを返す' do
Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
end
=end
end
- describe 'コミック数取得に於いて' do
+
+ describe '閲覧に於いて' do
+ before do
+ @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+ Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
+ Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
+ ScrollPanel.stub(:count).and_return(10)
+ 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
+ assigns(:scroll_panels).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id
+ response.should be_success
+ end
+ it 'scrollテンプレートを描画する' do
+ get :play, :id => @scroll.id
+ response.should render_template("scroll")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ 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
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :play, :id => @scroll.id
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :play, :id => @scroll.id
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :play, :id => @scroll.id, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :play, :id => @scroll.id, :format => :json
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :play, :id => @scroll.id
+ response.should be_success
+ end
+ end
+ end
+
+ describe 'スクロール数取得に於いて' do
before do
Scroll.should_receive(:visible_count).and_return(3)
# sign_in @user
get :count, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'ã\83\87ã\83¼ã\82¿ã\81\8cHashæ§\8bé\80 ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\81¦ã\82³ã\83\9fã\83\83ã\82¯数が1である' do
+ it 'ã\83\87ã\83¼ã\82¿ã\81\8cHashæ§\8bé\80 ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\81¦ã\82¹ã\82¯ã\83ã\83¼ã\83«数が1である' do
get :count, :format => :json
json = JSON.parse response.body
json["count"].should == 3
get :new
assigns(:scroll).should be_a_new(Scroll)
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにデフォルト値補充を依頼している' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにデフォルト値補充を依頼している' do
Scroll.any_instance.should_receive(:supply_default).exactly(1)
get :new
end
get :new, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson単体出力オプションを問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにjson単体出力オプションを問い合わせている' do
Scroll.should_receive(:show_json_opt).exactly(1)
get :new, :format => :json
end
@attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
end
context '事前チェックしておく' do
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにデフォルト値補充を依頼している' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにデフォルト値補充を依頼している' do
Scroll.any_instance.should_receive(:supply_default).exactly(1)
post :create, :scroll => @attr
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにカラム値復元を依頼している' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにカラム値復元を依頼している' do
Scroll.any_instance.should_receive(:attributes=).exactly(1)
post :create, :scroll => @attr
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに上書き補充を依頼している' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに上書き補充を依頼している' do
Scroll.any_instance.should_receive(:overwrite).exactly(1)
post :create, :scroll => @attr
end
end
end
context 'つつがなく終わるとき' do
- it "@scrollã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯を保持していて、それがDBにある" do
+ it "@scrollã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«を保持していて、それがDBにある" do
post :create, :scroll => @attr
assigns(:scroll).should be_a(Scroll)
assigns(:scroll).should be_persisted
post :create, :scroll => @attr
response.status.should eq 302
end
- it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+ it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«の表示ページへ遷移する' do
# Scroll.any_instance.stub(:save).and_return(true)
post :create, :scroll => @attr
response.should redirect_to(Scroll.last)
post :create, :scroll => @attr, :format => :json
response.should be_success
end
- it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯をjsonデータで返す' do
+ it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«をjsonデータで返す' do
post :create, :scroll => @attr, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
before do
Scroll.any_instance.stub(:save).and_return(false)
end
- it "æ\9cªä¿\9då\98ã\81®ã\82³ã\83\9fã\83\83ã\82¯を保持している" do
+ it "æ\9cªä¿\9då\98ã\81®ã\82¹ã\82¯ã\83ã\83¼ã\83«を保持している" do
post :create, :scroll => @attr
assigns(:scroll).should be_a_new(Scroll)
end
get :edit, :id => @scroll.id
response.should be_success
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに編集取得を問い合わせている' do
Scroll.should_receive(:edit).exactly(1)
get :edit, :id => @scroll.id
end
sign_in @user
end
context '事前チェックしておく' do
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに編集取得を問い合わせている' 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 'ã\82³ã\83\9fã\83\83ã\82¯モデルにカラム値復元を依頼している' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルにカラム値復元を依頼している' do
Scroll.any_instance.should_receive(:attributes=).exactly(1)
put :update, :id => @scroll.id, :scroll => @attr
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに上書き補充を依頼している' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに上書き補充を依頼している' do
Scroll.any_instance.should_receive(:overwrite).exactly(1)
put :update, :id => @scroll.id, :scroll => @attr
end
put :update, :id => @scroll.id, :scroll => @attr
response.status.should eq 302
end
- it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+ it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«の表示ページへ遷移する' do
put :update, :id => @scroll.id, :scroll => @attr
response.should redirect_to(@scroll)
end
Scroll.stub(:edit).with(any_args()).and_return @scroll
Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
end
- it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+ it 'ã\82¹ã\82¯ã\83ã\83¼ã\83«モデルに編集取得を問い合わせている' do
Scroll.should_receive(:edit).exactly(1)
delete :destroy, :id => @scroll.id
end
delete :destroy, :id => @scroll.id
response.status.should eq 302
end
- it 'ã\83\9eã\82¤ã\82³ã\83\9fã\83\83ã\82¯の一覧ページへ遷移する' do
+ it 'ã\83\9eã\82¤ã\82¹ã\82¯ã\83ã\83¼ã\83«の一覧ページへ遷移する' do
delete :destroy, :id => @scroll.id
response.should redirect_to('/home/scrolls')
end
delete :destroy, :id => @scroll.id
response.status.should eq 302
end
- it 'ã\81\9dã\81®ã\82³ã\83\9fã\83\83ã\82¯の詳細ページへ遷移する' do
+ it 'ã\81\9dã\81®ã\82¹ã\82¯ã\83ã\83¼ã\83«の詳細ページへ遷移する' do
delete :destroy, :id => @scroll.id
response.should redirect_to(scroll_path(@scroll))
end
end
end
end
- describe 'ã\82³ã\83\9fã\83\83ã\82¯数取得に於いて' do
+ describe 'ã\82¹ã\82¯ã\83ã\83¼ã\83«数取得に於いて' do
before do
Scroll.should_receive(:visible_count).and_return(3)
sign_out @user
post :create, :scroll => @attr
response.status.should eq 302
end
- it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+ it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«の表示ページへ遷移する' do
# Scroll.any_instance.stub(:save).and_return(true)
post :create, :scroll => @attr
response.should redirect_to(Scroll.last)
post :create, :scroll => @attr, :format => :json
response.should be_success
end
- it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯をjsonデータで返す' do
+ it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«をjsonデータで返す' do
post :create, :scroll => @attr, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
put :update, :id => @scroll.id, :scroll => @attr
response.status.should eq 302
end
- it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+ it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83ã\83¼ã\83«の表示ページへ遷移する' do
put :update, :id => @scroll.id, :scroll => @attr
response.should redirect_to(@scroll)
end
delete :destroy, :id => @scroll.id
response.status.should eq 302
end
- it 'ã\83\9eã\82¤ã\82³ã\83\9fã\83\83ã\82¯の一覧ページへ遷移する' do
+ it 'ã\83\9eã\82¤ã\82¹ã\82¯ã\83ã\83¼ã\83«の一覧ページへ遷移する' do
delete :destroy, :id => @scroll.id
response.should redirect_to('/home/scroll')
end