describe PicturesController do
before do
- FactoryGirl.create :admin
+ @admin = FactoryGirl.create :admin
+ @demand_user = FactoryGirl.create :demand_user
@sp = FactoryGirl.create :system_picture
@lg = FactoryGirl.create :license_group
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@user = FactoryGirl.create( :user_yas)
- @author = @user.author
+ @author = FactoryGirl.create :author, :user_id => @user.id
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
+if MagicNumber['run_mode'] == 1
describe '単体表示に於いて' do
before do
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
sign_in @user
- Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
end
context 'つつがなく終わるとき as json' do
it 'ステータスコード200 OKを返す' do
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @p.id
+ response.should be_success
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @p.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @p.id
+ response.should be_success
+ end
+ end
=begin
context '対象素材がないとき' do
before do
before do
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
sign_in @user
- Picture.stub(:show).with(@p.id.to_s, @author).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
end
context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
end
end
end
- context 'ä½\9c家権é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
+ context 'ã\83¦ã\83¼ã\82¶æ¨©é\99\90ã\81\8cã\81ªã\81\84ã\81¨ã\81\8d' do
before do
sign_out @user
end
end
end
end
+ context 'ユーザ権限はないが管理者権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @admin
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @p.id
+ response.should be_success
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @p.id
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @p.id
+ response.should be_success
+ end
+ end
=begin
context '対象素材がないとき' do
before do
=end
end
+ describe 'md5検索の一覧に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ sign_in @user
+ Picture.stub(:list_by_md5).with(any_args).and_return([@p, @p, @p])
+ end
+ context 'つつがなく終わるとき' do
+ it '実素材モデルにmd5検索を問い合わせている' do
+ Picture.should_receive(:list_by_md5).exactly(1)
+ get :search, :md5 => 'a'*32
+ end
+ it '@picturesにリストを取得している' do
+ get :search, :md5 => 'a'*32
+ assigns(:pictures).should have_at_least(3).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32
+ response.should be_success
+ end
+ it 'searchテンプレートを描画する' do
+ get :search, :md5 => 'a'*32
+ response.should render_template("search")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがリスト構造になっている' do
+ get :search, :md5 => 'a'*32, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいは実素材っぽいものであって欲しい' do
+ get :search, :md5 => 'a'*32, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("ext").should be_true
+ json.first.has_key?("md5").should be_true
+ json.first.has_key?("artist_id").should be_true
+ json.first.has_key?("width").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :search, :md5 => 'a'*32
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :search, :md5 => 'a'*32
+ response.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :search, :md5 => 'a'*32, :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 :search, :md5 => 'a'*32
+ response.should be_success
+ end
+ end
+ context 'ユーザ権限はないが借手権限があるとき' do
+ before do
+ sign_out @user
+ sign_in @demand_user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32
+ response.should be_success
+ end
+ end
+ context 'ユーザだが作家登録していないとき' do
+ before do
+ @author.destroy
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32
+ response.should be_success
+ end
+ end
+ end
+
+else
+ describe '単体表示に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ sign_in @user
+ Picture.stub(:show).with(@p.id.to_s, [nil, nil, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
+ end
+ context 'つつがなく終わるとき as json' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @p.id, :format => :json
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @p.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @p.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @p.id, :format => :json
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @p.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @p.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe 'クレジット表示に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ sign_in @user
+ Picture.stub(:show).with(@p.id.to_s, [nil, nil, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [@user, nil, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, @admin, nil]).and_return(@p)
+ Picture.stub(:show).with(@p.id.to_s, [nil, nil, @demand_user]).and_return(@p)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @p.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'creditテンプレートを描画する' do
+ get :credit, :id => @p.id
+ response.should render_template("credit")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :credit, :id => @p.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :credit, :id => @p.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'creditテンプレートを描画する' do
+ get :credit, :id => @p.id
+ response.should render_template("credit")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :credit, :id => @p.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe 'md5検索の一覧に於いて' do
+ before do
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+ sign_in @user
+ Picture.stub(:list_by_md5).with(any_args).and_return([@p, @p, @p])
+ end
+ context 'つつがなく終わるとき' do
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32
+ response.should be_success
+ end
+ it 'searchテンプレートを描画する' do
+ get :search, :md5 => 'a'*32
+ response.should render_template("search")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32
+ response.should be_success
+ end
+ it 'searchテンプレートを描画する' do
+ get :search, :md5 => 'a'*32
+ response.should render_template("search")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :search, :md5 => 'a'*32, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+end
end