X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fcontrollers%2Flicense_groups_controller_spec.rb;h=377b05bbe54f8fe84106bb4b9ef6de6aa5364658;hb=0bdfae60dc58932c99849c31d36ee5d7715db782;hp=63e42f7a947c97e670cda3a80daab0ed5d759759;hpb=27e96fe0cd5c1f268182e17fe2d42d617b08b4f6;p=pettanr%2Fpettanr.git diff --git a/spec/controllers/license_groups_controller_spec.rb b/spec/controllers/license_groups_controller_spec.rb index 63e42f7a..377b05bb 100644 --- a/spec/controllers/license_groups_controller_spec.rb +++ b/spec/controllers/license_groups_controller_spec.rb @@ -6,11 +6,13 @@ describe LicenseGroupsController do before do @admin = FactoryGirl.create :admin @user = FactoryGirl.create( :user_yas) + @author = FactoryGirl.create :author, :user_id => @user.id @sp = FactoryGirl.create :system_picture @lg = FactoryGirl.create :license_group, :name => 'peta' @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id end +if MagicNumber['run_mode'] == 1 describe '一覧表示に於いて' do before do sign_in @user @@ -21,7 +23,7 @@ describe LicenseGroupsController do get :index response.should be_success end - it 'ライセンスモデルに一覧を問い合わせている' do + it 'ライセンスグループモデルに一覧を問い合わせている' do LicenseGroup.should_receive(:list).exactly(1) get :index end @@ -40,6 +42,10 @@ describe LicenseGroupsController do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ライセンスグループモデルにjson一覧出力オプションを問い合わせている' do + LicenseGroup.should_receive(:list_json_opt).exactly(1) + get :index, :format => :json + end it 'データがリスト構造になっている' do get :index, :format => :json json = JSON.parse response.body @@ -95,10 +101,17 @@ describe LicenseGroupsController do get :show, :id => @lg.id, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ライセンスグループモデルにjson単体出力オプションを問い合わせている' do + LicenseGroup.should_receive(:show_json_opt).exactly(1) + get :show, :id => @lg.id, :format => :json + end it 'データがアレになっている' do get :show, :id => @lg.id, :format => :json json = JSON.parse response.body json["name"].should match(/peta/) + json["classname"].should_not be_nil + json["caption"].should_not be_nil + json["url"].should_not be_nil end end end @@ -113,5 +126,98 @@ describe LicenseGroupsController do end end - +else + describe '一覧表示に於いて' do + before do + sign_in @user + LicenseGroup.stub(:list).and_return([@lg, @lg, @lg]) + 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 + LicenseGroup.stub(:show).and_return(@lg) + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @lg.id + response.should be_success + end + context 'html形式' do + it 'showテンプレートを描画する' do + get :show, :id => @lg.id + response.should render_template("show") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :show, :id => @lg.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 => @lg.id + response.status.should eq 200 + end + context 'html形式' do + it 'showテンプレートを描画する' do + get :show, :id => @lg.id + response.should render_template("show") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :show, :id => @lg.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + end + +end end