+# -*- encoding: utf-8 -*-
+#ライセンスグループ
require 'spec_helper'
describe LicenseGroupsController do
+ before do
+ @admin = Factory :admin
+ @user = Factory( :user_yas)
+ @lg = Factory :license_group, :name => 'peta'
+ end
+
+ 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
+ it 'ライセンスモデルに一覧を問い合わせている' do
+ LicenseGroup.should_receive(:list).exactly(1)
+ get :index
+ end
+ it '@license_groupsにリストを取得している' do
+ get :index
+ assigns(:license_groups).should have_at_least(3).items
+ 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
+ it 'データがリスト構造になっている' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.should have_at_least(3).items
+ end
+ it 'リストの先頭くらいはライセンスグループっぽいものであって欲しい' do
+ get :index, :format => :json
+ json = JSON.parse response.body
+ json.first.has_key?("name").should be_true
+ json.first.has_key?("classname").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
+
+ 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
+ it 'ライセンスモデルに単体取得を問い合わせている' do
+ LicenseGroup.should_receive(:show).exactly(1)
+ get :show
+ end
+ it '@license_groupにアレを取得している' do
+ get :show, :id => @lg.id
+ assigns(:license_group).id.should eq(@lg.id)
+ 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
+ it 'データがアレになっている' do
+ get :show, :id => @lg.id, :format => :json
+ json = JSON.parse response.body
+ json["name"].should match(/peta/)
+ 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
+ end
+ end
+
end