context 'つつがなく終わるとき' do
it '実素材モデルにmd5検索を問い合わせている' do
Picture.should_receive(:list_by_md5).exactly(1)
- get :md5, :md5 => 'a'*32
+ get :search, :md5 => 'a'*32
end
it '@picturesにリストを取得している' do
- get :md5, :md5 => 'a'*32
+ get :search, :md5 => 'a'*32
assigns(:pictures).should have_at_least(3).items
end
context 'html形式' do
it 'ステータスコード200 OKを返す' do
- get :md5, :md5 => 'a'*32
+ get :search, :md5 => 'a'*32
response.should be_success
end
- it 'md5テンプレートを描画する' do
- get :md5, :md5 => 'a'*32
- response.should render_template("md5")
+ it 'searchテンプレートを描画する' do
+ get :search, :md5 => 'a'*32
+ response.should render_template("search")
end
end
context 'json形式' do
it 'ステータスコード200 OKを返す' do
- get :md5, :md5 => 'a'*32, :format => :json
+ get :search, :md5 => 'a'*32, :format => :json
response.should be_success
end
it 'jsonデータを返す' do
- get :md5, :md5 => 'a'*32, :format => :json
+ get :search, :md5 => 'a'*32, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
it 'データがリスト構造になっている' do
- get :md5, :md5 => 'a'*32, :format => :json
+ get :search, :md5 => 'a'*32, :format => :json
json = JSON.parse response.body
json.should have_at_least(3).items
end
it 'リストの先頭くらいは実素材っぽいものであって欲しい' do
- get :md5, :md5 => 'a'*32, :format => :json
+ 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
end
context 'html形式' do
it 'ステータスコード302 Foundを返す' do
- get :md5, :md5 => 'a'*32
+ get :search, :md5 => 'a'*32
response.status.should eq 302
end
it 'サインインページへ遷移する' do
- get :md5, :md5 => 'a'*32
+ get :search, :md5 => 'a'*32
response.should redirect_to '/users/sign_in'
end
end
context 'json形式' do
it 'ステータスコード401 Unauthorizedを返す' do
- get :md5, :md5 => 'a'*32, :format => :json
+ get :search, :md5 => 'a'*32, :format => :json
response.status.should eq 401
end
it '応答メッセージにUnauthorizedを返す' do
- get :md5, :md5 => 'a'*32, :format => :json
+ get :search, :md5 => 'a'*32, :format => :json
response.message.should match(/Unauthorized/)
end
end
end
- context '作家が絵師でないとき' do
- before do
- Author.any_instance.stub(:artist?).and_return(false)
- end
- context 'html形式' do
- it 'ステータスコード302 Foundを返す' do
- get :md5, :md5 => 'a'*32
- response.status.should eq 302
- end
- it '絵師登録ページへ遷移する' do
- get :md5, :md5 => 'a'*32
- response.should redirect_to new_artist_path
- end
- end
- context 'json形式' do
- it '例外403 forbiddenを返す' do
- lambda{
- get :md5, :md5 => 'a'*32, :format => :json
- }.should raise_error(ActiveRecord::Forbidden)
- end
- end
- end
end
end
end
end
- describe 'md5検索に於いて' do
- before do
- @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
- @p = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
- :original_picture_id => @op.id, :md5 => 'a' * 32
- @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
- @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
- @p2 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 0,
- :original_picture_id => @op2.id, :md5 => 'b' * 32
- @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
- end
- it 'リストを返す' do
- res = Picture.find_by_md5(@p.md5)
- res.is_a?(Array).should be_true
- end
- it 'md5が違えば含まない' do
- res = Picture.find_by_md5(@p.md5)
- res.include?(@p2).should be_false
- end
- it '更新日時順' do
- @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op2.id, :md5 => 'C' * 32
- @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
- res = Picture.find_by_md5(@p3.md5)
- res.should eq [@p4, @p3]
- end
- end
-
describe 'md5重複リストに於いて' do
before do
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id
:original_picture_id => @op2.id, :md5 => 'b' * 32
@op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id
end
- it 'リストを返す' do
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.is_a?(Array).should be_true
- end
- it 'md5が違えば含まない' do
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.include?(@p2).should be_false
- end
- it '同一原画は含まない' do
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.empty?.should be_true
- end
- it '同一原画は旧版でも含まない' do
- @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op.id, :md5 => 'a' * 32
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.empty?.should be_true
- end
- it '他所の原画なら含む' do
- @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op2.id, :md5 => 'a' * 32
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.should eq [@p3]
- end
- it '他所の原画でもmd5が違えば含まない' do
- @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op2.id, :md5 => 'c' * 32
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.empty?.should be_true
- end
- it '更新日時順' do
- @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op2.id, :md5 => 'a' * 32
- @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
- :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
- res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
- res.should eq [@p4, @p3]
+ context '除外する原画idで指定されていないとき' do
+ it 'リストを返す' do
+ res = Picture.list_by_md5(@p.md5)
+ res.is_a?(Array).should be_true
+ end
+ it 'md5が違えば含まない' do
+ res = Picture.list_by_md5(@p.md5)
+ res.include?(@p2).should be_false
+ end
+ it '更新日時順' do
+ @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op2.id, :md5 => 'C' * 32
+ @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op3.id, :md5 => @p3.md5, :updated_at => Time.now + 100
+ res = Picture.find_by_md5(@p3.md5)
+ res.should eq [@p4, @p3]
+ end
+ end
+ context '除外する原画idで指定されたとき' do
+ it 'リストを返す' do
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.is_a?(Array).should be_true
+ end
+ it 'md5が違えば含まない' do
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.include?(@p2).should be_false
+ end
+ it '同一原画は含まない' do
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.empty?.should be_true
+ end
+ it '同一原画は旧版でも含まない' do
+ @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op.id, :md5 => 'a' * 32
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.empty?.should be_true
+ end
+ it '他所の原画なら含む' do
+ @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op2.id, :md5 => 'a' * 32
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.should eq [@p3]
+ end
+ it '他所の原画でもmd5が違えば含まない' do
+ @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op2.id, :md5 => 'c' * 32
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.empty?.should be_true
+ end
+ it '更新日時順' do
+ @p3 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op2.id, :md5 => 'a' * 32
+ @p4 = FactoryGirl.create :picture, :artist_id => @artist.id, :license_id => @license.id, :revision => 1,
+ :original_picture_id => @op3.id, :md5 => 'a' * 32, :updated_at => Time.now + 100
+ res = Picture.list_by_md5(@p.md5, @p.original_picture_id)
+ res.should eq [@p4, @p3]
+ end
end
end