@lg = FactoryGirl.create :license_group
@sp = FactoryGirl.create :system_picture
@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
end
+if MagicNumber['run_mode'] == 1
describe '一覧表示に於いて' do
before do
@l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
sign_in @user
License.stub(:list).and_return([@l, @l, @l])
end
- context 'つつがなく終わるとき' do
+ context 'つつがなく終わるとき' do
it 'ステータスコード200 OKを返す' do
get :index
response.should be_success
get :index, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it 'ライセンスモデルにjson一覧出力オプションを問い合わせている' do
+ License.should_receive(:list_json_opt).exactly(1)
+ get :index, :format => :json
+ end
it 'データがリスト構造になっている' do
get :index, :format => :json
json = JSON.parse response.body
it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
get :index, :format => :json
json = JSON.parse response.body
+ json.first.has_key?("name").should be_true
+ json.first.has_key?("caption").should be_true
json.first.has_key?("url").should be_true
end
end
get :show, :id => @l.id, :format => :json
lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
end
+ it 'ライセンスモデルにjson単体出力オプションを問い合わせている' do
+ License.should_receive(:show_json_opt).exactly(1)
+ get :show, :id => @l.id, :format => :json
+ end
it 'データがアレになっている' do
get :show, :id => @l.id, :format => :json
json = JSON.parse response.body
json["name"].should match(/peta/)
+ json["caption"].should_not be_nil
+ json["url"].should_not be_nil
end
end
end
end
end
+ describe '管理名検索の一覧に於いて' do
+ before do
+ @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ sign_in @user
+ License.stub(:list_by_name).with(any_args).and_return([@l])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ライセンスモデルに管理名検索を問い合わせている' do
+ License.should_receive(:list_by_name).exactly(1)
+ get :search, :name => @l.name
+ end
+ it '@licensesにリストを取得している' do
+ get :search, :name => @l.name
+ assigns(:licenses).should have_at_least(1).items
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :name => @l.name
+ response.should be_success
+ end
+ it 'searchテンプレートを描画する' do
+ get :search, :name => @l.name
+ response.should render_template("search")
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード200 OKを返す' do
+ get :search, :name => @l.name, :format => :json
+ response.should be_success
+ end
+ it 'jsonデータを返す' do
+ get :search, :name => @l.name, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ it 'データがリスト構造になっている' do
+ get :search, :name => @l.name, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(1).items
+ end
+ it 'リストの先頭くらいはライセンスっぽいものであって欲しい' do
+ get :search, :name => @l.name, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("name").should be_true
+ json.first.has_key?("caption").should be_true
+ json.first.has_key?("url").should be_true
+ end
+ end
+ end
+ context 'ユーザ権限がないとき' do
+ before do
+ sign_out @user
+ end
+ it 'ステータスコード200 okを返す' do
+ get :index
+ response.status.should eq 200
+ end
+ end
+ end
+
+else
+ describe '一覧表示に於いて' do
+ before do
+ @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ sign_in @user
+ License.stub(:list).and_return([@l, @l, @l])
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :index
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :index, :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 :index
+ response.status.should eq 200
+ end
+ context 'html形式' do
+ it 'indexテンプレートを描画する' do
+ get :index
+ response.should render_template("index")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :index, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+ describe '単体表示に於いて' do
+ before do
+ sign_in @user
+ @l = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ License.stub(:show).and_return(@l)
+ end
+ context 'つつがなく終わるとき' do
+ it 'ステータスコード200 OKを返す' do
+ get :show, :id => @l.id
+ response.should be_success
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @l.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @l.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 => @l.id
+ response.status.should eq 200
+ end
+ context 'html形式' do
+ it 'showテンプレートを描画する' do
+ get :show, :id => @l.id
+ response.should render_template("show")
+ end
+ end
+ context 'json形式' do
+ it 'jsonデータを返す' do
+ get :show, :id => @l.id, :format => :json
+ lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+ end
+ end
+ end
+ end
+
+end
end