OSDN Git Service

repair test
authoryasushiito <yas@pen-chan.jp>
Sat, 30 Jun 2012 00:41:18 +0000 (09:41 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 30 Jun 2012 00:41:18 +0000 (09:41 +0900)
spec/controllers/comics_controller_spec.rb
spec/controllers/common_licenses_controller_spec.rb
spec/controllers/original_licenses_controller_spec.rb
spec/controllers/panels_controller_spec.rb
spec/controllers/speech_balloon_templates_controller_spec.rb
spec/models/artist_spec.rb
spec/models/common_license_spec.rb
spec/models/original_license_spec.rb
spec/models/panel_spec.rb

index 07156f0..20dfcc3 100644 (file)
@@ -4,7 +4,9 @@ require 'spec_helper'
 describe ComicsController do
   before do
     Factory :admin
-    @license = Factory :license
+    @sp = Factory :system_picture
+    @lg = Factory :license_group
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = Factory :user_yas\r
     @author = @user.author    #ユーザ作成時に連動して作成される
   end
index 5dcdf25..e69de29 100644 (file)
@@ -1,338 +0,0 @@
-# -*- encoding: utf-8 -*-
-#コモンライセンス
-require 'spec_helper'
-
-describe CommonLicensesController do
-  before do
-    @admin = Factory :admin
-    @lc = Factory :license
-    @cl = Factory :common_license, :license_id => @lc.id
-    @user = Factory( :user_yas)
-    @author = @user.author
-    @artist = Factory :artist_yas, :author_id => @author.id
-  end
-=begin
-  describe '一覧表示に於いて' do
-    before do
-      sign_in @admin
-      sign_in @user
-      CommonLicense.stub(:list).and_return([@cl, @cl, @cl])
-    end
-    context 'パラメータpageについて' do
-      it '@pageに値が入る' do
-        get :index, :page => 5
-        assigns(:page).should eq 5
-      end
-      it '省略されると@pageに1値が入る' do
-        get :index
-        assigns(:page).should eq 1
-      end
-      it '与えられたpage_sizeがセットされている' do
-        get :index, :page_size => 15
-        assigns(:page_size).should eq 15
-      end
-      it '省略されると@page_sizeにデフォルト値が入る' do
-        get :index
-        assigns(:page_size).should eq CommonLicense.default_page_size
-      end
-      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
-        get :index, :page_size => 1500
-        assigns(:page_size).should eq CommonLicense.max_page_size
-      end
-      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
-        get :index, :page_size => 0
-        assigns(:page_size).should eq CommonLicense.default_page_size
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :index
-        response.should be_success 
-      end
-      it 'コモンライセンスモデルに一覧を問い合わせている' do
-        CommonLicense.should_receive(:list).exactly(1)
-        get :index
-      end
-      it '@common_licensesにリストを取得している' do
-        get :index
-        assigns(:common_licenses).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?("url").should be_true
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :index
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :index
-          response.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :index, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :index, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :index
-          response.should be_success 
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :index, :format => :json
-          response.should be_success 
-        end
-      end
-    end
-  end
-  
-  describe '単体表示に於いて' do
-    before do
-      sign_in @admin
-      sign_in @user
-      CommonLicense.stub(:show).and_return(@cl)
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :show, :id => @cl.id
-        response.should be_success
-      end
-      it 'コモンライセンスモデルに単体取得を問い合わせている' do
-        CommonLicense.should_receive(:show).exactly(1)
-        get :show
-      end
-      it '@common_licenseにアレを取得している' do
-        get :show, :id => @cl.id
-        assigns(:common_license).id.should eq(@cl.id)
-      end
-      context 'html形式' do
-        it 'showテンプレートを描画する' do
-          get :show, :id => @cl.id
-          response.should render_template("show")
-        end
-      end
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :show, :id => @cl.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          get :show, :id => @cl.id, :format => :json
-          json = JSON.parse response.body
-          json["name"].should match(/peta/)
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :show, :id => @cl.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :show, :id => @cl.id
-          response.body.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :show, :id => @cl.id, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :show, :id => @cl.id, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :show, :id => @cl.id
-          response.should be_success
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :show, :id => @cl.id, :format => :json
-          response.should be_success
-        end
-      end
-    end
-  end
-=end
-  
-  describe 'インポートに於いて' do
-    before do
-      sign_in @admin
-      sign_in @user
-      #テストデータを用意してね
-      @f = Rails.root + 'spec/json/common_license.json'
-      @t = File.open(@f, 'r').read
-      @j = JSON.parse @t
-      @fs = Rails.root + 'spec/json/common_licenses.json'
-      @ts = File.open(@fs, 'r').read
-      @js = JSON.parse @ts
-      @fes = Rails.root + 'spec/json/invalid_common_licenses.json'
-      @tes = File.open(@fes, 'r').read
-      @jes = JSON.parse @tes
-    end
-    context '事前チェックしておく' do
-      before do
-        #異常な行を返すから、正常の意味で空を返す
-        CommonLicense.stub(:import).with(any_args()).and_return([])
-      end
-      it "@dataに渡したデータを保持している" do
-        post :import, :file => @t
-        assigns(:data).should_not be_nil
-      end
-      it 'モデルにインポート依頼する' do
-        CommonLicense.should_receive(:import).with(any_args()).exactly(1)
-        post :import, :file => @t
-      end
-      it "@errorsに結果を保持している" do
-        post :import, :file => @t
-        assigns(:errors).should eq []
-      end
-    end
-    context 'つつがなく終わるとき' do
-      before do
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :import, :file => @t
-          response.status.should eq 302
-        end
-        it '管理者向けコモンライセンス一覧ページへ遷移する' do
-          post :import, :file => @t
-          response.should redirect_to('/common_licenses/list')
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :import, :file => @t, :format => :json
-          response.should be_success 
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :import, :file => @t
-          response.status.should eq 302
-        end
-        it '管理者サインインページへ遷移する' do
-          post :import, :file => @t
-          response.body.should redirect_to '/admins/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          post :import, :file => @t, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          post :import, :file => @t, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      #必要なのは管理者権限であって作家権限ではない。成功を見届ける
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :import, :file => @t
-          response.status.should eq 302
-        end
-        it '管理者向けコモンライセンス一覧ページへ遷移する' do
-          post :import, :file => @t
-          response.should redirect_to('/common_licenses/list')
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :import, :file => @t, :format => :json
-          response.should be_success 
-        end
-      end
-    end
-    context '検証、保存に失敗した' do
-      before do
-        #異常な行を返す
-        CommonLicense.stub(:import).with(any_args()).and_return(
-          [CommonLicense.new(Factory.attributes_for(:common_license))]
-        )
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :import, :file => @t
-          response.status.should eq 200
-        end
-        it 'resultページを描画する' do
-          post :import, :file => @t
-          response.should render_template("result")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          post :import, :file => @t, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          post :import, :file => @t, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-end
index 4c5df40..e69de29 100644 (file)
@@ -1,588 +0,0 @@
-# -*- encoding: utf-8 -*-
-#オリジナルライセンス
-require 'spec_helper'
-
-describe OriginalLicensesController do
-  before do
-    @admin = Factory :admin
-    @lc = Factory :license
-    @user = Factory( :user_yas)
-    @author = @user.author
-    @artist = Factory :artist_yas, :author_id => @author.id
-  end
-  describe '一覧表示に於いて' do
-    before do
-      sign_in @user
-      @ol = Factory :original_license, :license_id => @lc.id
-      OriginalLicense.stub(:list).and_return([@ol, @ol, @ol])
-    end
-    context 'パラメータpageについて' do
-      it '@pageに値が入る' do
-        get :index, :page => 5
-        assigns(:page).should eq 5
-      end
-      it '省略されると@pageに1値が入る' do
-        get :index
-        assigns(:page).should eq 1
-      end
-      it '与えられたpage_sizeがセットされている' do
-        get :index, :page_size => 15
-        assigns(:page_size).should eq 15
-      end
-      it '省略されると@page_sizeにデフォルト値が入る' do
-        get :index
-        assigns(:page_size).should eq OriginalLicense.default_page_size
-      end
-      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
-        get :index, :page_size => 1500
-        assigns(:page_size).should eq OriginalLicense.max_page_size
-      end
-      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
-        get :index, :page_size => 0
-        assigns(:page_size).should eq OriginalLicense.default_page_size
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :index
-        response.should be_success 
-      end
-      it 'ライセンスモデルに一覧を問い合わせている' do
-        OriginalLicense.should_receive(:list).exactly(1)
-        get :index
-      end
-      it '@original_licensesにリストを取得している' do
-        get :index
-        assigns(:original_licenses).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?("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
-      @ol = Factory :original_license, :license_id => @lc.id
-      OriginalLicense.stub(:show).and_return(@ol)
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :show, :id => @ol.id
-        response.should be_success
-      end
-      it 'ライセンスモデルに単体取得を問い合わせている' do
-        OriginalLicense.should_receive(:show).exactly(1)
-        get :show
-      end
-      it '@original_licenseにアレを取得している' do
-        get :show, :id => @ol.id
-        assigns(:original_license).id.should eq(@ol.id)
-      end
-      context 'html形式' do
-        it 'showテンプレートを描画する' do
-          get :show, :id => @ol.id
-          response.should render_template("show")
-        end
-      end
-      context 'json形式' do
-        it 'jsonデータを返す' do
-          get :show, :id => @ol.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          get :show, :id => @ol.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 => @ol.id
-        response.status.should eq 200
-      end
-    end
-  end
-  
-  describe '新規作成フォーム表示に於いて' do
-    before do
-      sign_in @admin
-      sign_in @user
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :new
-        response.should be_success 
-      end
-      it '@original_licenseに新規データを用意している' do
-        get :new
-        assigns(:original_license).should be_a_new(OriginalLicense)
-      end
-      it 'オリジナルライセンスモデルにデフォルト値補充を依頼している' do
-        OriginalLicense.any_instance.should_receive(:supply_default).exactly(1)
-        get :new
-      end
-      context 'html形式' do
-        it 'newテンプレートを描画する' do
-          get :new
-          response.should render_template("new")
-        end
-      end
-      context 'js形式' do
-        it 'new.jsテンプレートを描画する' do
-          get :new, :format => :js
-          response.should render_template("new")
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :new
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :new
-          response.body.should redirect_to '/admins/sign_in'
-        end
-      end
-      context 'js形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :new, :format => :js
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :new, :format => :js
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-  end
-
-  describe '新規作成に於いて' do
-    before do
-      sign_in @admin
-      sign_in @user
-    end
-    context 'つつがなく終わるとき' do
-      it 'モデルに保存依頼する' do
-        OriginalLicense.any_instance.should_receive(:store).exactly(1)
-        post :create, :original_license => Factory.attributes_for(:original_license)
-      end
-      it "@original_licenseに作成されたオリジナルライセンスを保持していて、それがDBにある" do
-        post :create, :original_license => Factory.attributes_for(:original_license)
-        assigns(:original_license).should be_a(OriginalLicense)
-        assigns(:original_license).should be_persisted
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          OriginalLicense.any_instance.stub(:store).and_return(true)
-          post :create, :original_license => Factory.attributes_for(:original_license)
-          response.status.should eq 302
-        end
-        it '作成されたオリジナルライセンスの表示ページへ遷移する' do
-#          OriginalLicense.any_instance.stub(:save).and_return(true)
-          post :create, :original_license => Factory.attributes_for(:original_license)
-          response.should redirect_to(OriginalLicense.last)
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-#          OriginalLicense.any_instance.stub(:save).and_return(true)
-          post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
-          response.should be_success 
-        end
-        it '作成されたオリジナルライセンスをjsonデータで返す' do
-          post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'データがアレになっている' do
-          post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
-          json = JSON.parse response.body
-          json["name"].should match(/peta/)
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :create, :original_license => Factory.attributes_for(:original_license)
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          post :create, :original_license => Factory.attributes_for(:original_license)
-          response.body.should redirect_to '/admins/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          post :create, :original_license => Factory.attributes_for(:original_license), :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '検証、保存に失敗した' do
-      before do
-        OriginalLicense.any_instance.stub(:save).and_return(false)
-      end
-      it "未保存のオリジナルライセンスを保持している" do
-        post :create, :original_license => {}
-        assigns(:original_license).should be_a_new(OriginalLicense)
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :create, :original_license => {}
-          response.status.should eq 200
-        end
-        it '新規ページを描画する' do
-          post :create, :original_license => {}
-          response.should render_template("new")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          post :create, :original_license => {}, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          post :create, :original_license => {}, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-
-  describe '編集フォーム表示に於いて' do
-    before do
-      @ol = Factory :original_license, :license_id => @lc.id
-      sign_in @admin
-      sign_in @user
-      OriginalLicense.stub(:show).and_return(@ol)
-    end
-    context 'つつがなく終わるとき' do
-      it 'ステータスコード200 OKを返す' do
-        get :edit, :id => @ol.id
-        response.should be_success 
-      end
-      it 'オリジナルライセンスモデルに単体取得を問い合わせている' do
-        OriginalLicense.should_receive(:show).exactly(1)
-        get :edit, :id => @ol.id
-      end
-      it '@original_licenseにデータを用意している' do
-        get :edit, :id => @ol.id
-        assigns(:original_license).should eq @ol
-      end
-      context 'html形式' do
-        it 'editテンプレートを描画する' do
-          get :edit, :id => @ol.id
-          response.should render_template("edit")
-        end
-      end
-      context 'js形式' do
-        it 'edit.jsテンプレートを描画する' do
-          get :edit, :id => @ol.id, :format => :js
-          response.should render_template("edit")
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :edit, :id => @ol.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :edit, :id => @ol.id
-          response.body.should redirect_to '/admins/sign_in'
-        end
-      end
-      context 'js形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :edit, :id => @ol.id, :format => :js
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :edit, :id => @ol.id, :format => :js
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-  end
-
-  describe '更新に於いて' do
-    before do
-      @ol = Factory :original_license, :license_id => @lc.id
-      sign_in @admin
-      sign_in @user
-      @attr = Factory.attributes_for(:original_license, :name => 'new lc')
-    end
-    context '事前チェックしておく' do
-      it 'オリジナルライセンスモデルに単体取得を問い合わせている' do
-        OriginalLicense.stub(:show).with(any_args()).and_return @ol
-        OriginalLicense.should_receive(:show).exactly(1)
-        put :update, :id => @ol.id, :original_license => @attr
-      end
-      it 'モデルに更新を依頼する' do
-        OriginalLicense.any_instance.should_receive(:store).with(any_args)
-        put :update, :id => @ol.id, :original_license => @attr
-      end
-      it '@original_licenseにアレを取得している' do
-        put :update, :id => @ol.id, :original_license => @attr
-        assigns(:original_license).id.should eq(@ol.id)
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it '更新される' do
-        put :update, :id => @ol.id, :original_license => @attr
-        OriginalLicense.find(@ol.id).name.should eq 'new lc'
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          OriginalLicense.any_instance.stub(:store).with(any_args()).and_return(true)
-          put :update, :id => @ol.id, :original_license => @attr
-          response.status.should eq 302
-        end
-        it '更新されたオリジナルライセンスの表示ページへ遷移する' do
-          put :update, :id => @ol.id, :original_license => @attr
-          response.should redirect_to(@ol)
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          OriginalLicense.any_instance.stub(:store).with(any_args()).and_return(true)
-          put :update, :id => @ol.id, :original_license => @attr, :format => :json
-          response.should be_success 
-        end
-        it 'ページ本体は特に返さない' do
-          OriginalLicense.any_instance.stub(:store).with(any_args()).and_return(true)
-          put :update, :id => @ol.id, :original_license => @attr, :format => :json
-          response.body.should match /./
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      it 'ステータスコード302 Foundを返す' do
-        put :update, :id => @ol.id, :original_license => @attr
-        response.status.should eq 302
-      end
-      context 'html形式' do
-        it 'サインインページへ遷移する' do
-          put :update, :id => @ol.id, :original_license => @attr
-          response.body.should redirect_to '/admins/sign_in'
-        end
-      end
-      context 'json形式' do
-        it '応答メッセージにUnauthorizedを返す' do
-          put :update, :id => @ol.id, :original_license => @attr, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '検証、保存に失敗したとき' do
-      before do
-        OriginalLicense.any_instance.stub(:store).and_return(false)
-      end
-      context 'html形式' do
-        it 'ステータスコード200 Okを返す' do
-          put :update, :id => @ol.id, :original_license => @attr
-          response.status.should eq 200
-        end
-        it '編集ページを描画する' do
-          put :update, :id => @ol.id, :original_license => @attr
-          response.should render_template("edit")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          OriginalLicense.any_instance.stub(:store).and_return(false)
-          put :update, :id => @ol.id, :original_license => @attr, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          put :update, :id => @ol.id, :original_license => @attr, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-
-  describe 'インポートに於いて' do
-    before do
-      sign_in @admin
-      sign_in @user
-      #テストデータを用意してね
-      @f = Rails.root + 'spec/json/original_license.json'
-      @t = File.open(@f, 'r').read
-      @j = JSON.parse @t
-      @fs = Rails.root + 'spec/json/original_licenses.json'
-      @ts = File.open(@fs, 'r').read
-      @js = JSON.parse @ts
-      @fes = Rails.root + 'spec/json/invalid_original_licenses.json'
-      @tes = File.open(@fes, 'r').read
-      @jes = JSON.parse @tes
-    end
-    context '事前チェックしておく' do
-      before do
-        #異常な行を返すから、正常の意味で空を返す
-        OriginalLicense.stub(:import).with(any_args()).and_return([])
-      end
-      it "@dataに渡したデータを保持している" do
-        post :import, :file => @t
-        assigns(:data).should_not be_nil
-      end
-      it 'モデルにインポート依頼する' do
-        OriginalLicense.should_receive(:import).with(any_args()).exactly(1)
-        post :import, :file => @t
-      end
-      it "@errorsに結果を保持している" do
-        post :import, :file => @t
-        assigns(:errors).should eq []
-      end
-    end
-    context 'つつがなく終わるとき' do
-      before do
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :import, :file => @t
-          response.status.should eq 302
-        end
-        it '管理者向けオリジナルライセンス一覧ページへ遷移する' do
-          post :import, :file => @t
-          response.should redirect_to('/original_licenses/list')
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :import, :file => @t, :format => :json
-          response.should be_success 
-        end
-      end
-    end
-    context '管理者権限がないとき' do
-      before do
-        sign_out @admin
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :import, :file => @t
-          response.status.should eq 302
-        end
-        it '管理者サインインページへ遷移する' do
-          post :import, :file => @t
-          response.body.should redirect_to '/admins/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          post :import, :file => @t, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          post :import, :file => @t, :format => :json
-          response.message.should match(/Unauthorized/)
-        end
-      end
-    end
-    context '作家権限がないとき' do
-      #必要なのは管理者権限であって作家権限ではない。成功を見届ける
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          post :import, :file => @t
-          response.status.should eq 302
-        end
-        it '管理者向けオリジナルライセンス一覧ページへ遷移する' do
-          post :import, :file => @t
-          response.should redirect_to('/original_licenses/list')
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :import, :file => @t, :format => :json
-          response.should be_success 
-        end
-      end
-    end
-    context '検証、保存に失敗した' do
-      before do
-        #異常な行を返す
-        OriginalLicense.stub(:import).with(any_args()).and_return(
-          [OriginalLicense.new(Factory.attributes_for(:original_license))]
-        )
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          post :import, :file => @t
-          response.status.should eq 200
-        end
-        it 'resultページを描画する' do
-          post :import, :file => @t
-          response.should render_template("result")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード422 unprocessable_entity を返す' do
-          post :import, :file => @t, :format => :json
-          response.status.should eq 422
-        end
-        it '応答メッセージUnprocessable Entityを返す' do
-          post :import, :file => @t, :format => :json
-          response.message.should match(/Unprocessable/)
-        end
-      end
-    end
-  end
-  
-end
index e7c058e..cabdf60 100644 (file)
@@ -4,7 +4,9 @@ require 'spec_helper'
 describe PanelsController do\r
   before do\r
     Factory :admin\r
-    @license = Factory :license
+    @sp = Factory :system_picture
+    @lg = Factory :license_group
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = Factory :user_yas\r
     @author = @user.author    #ユーザ作成時に連動して作成される\r
     @comic = Factory :comic, :author_id => @author.id\r
index aac1bd3..3a215b2 100644 (file)
@@ -5,7 +5,9 @@ describe SpeechBalloonTemplatesController do
 
   before do
     @admin = Factory :admin
-    @sbt = Factory :license
+    @sp = Factory :system_picture
+    @lg = Factory :license_group
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = Factory( :user_yas)
     @author = @user.author
     @sbt = Factory :speech_balloon_template
index 42bb737..4a4b83c 100644 (file)
@@ -7,7 +7,9 @@ describe Artist do
     Factory :admin
     @user = Factory( :user_yas)
     @author = @user.author
-    @license = Factory :license
+    @sp = Factory :system_picture
+    @lg = Factory :license_group
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
   end
 
   describe '検証に於いて' do
index 70d2031..e69de29 100644 (file)
@@ -1,562 +0,0 @@
-# -*- encoding: utf-8 -*-
-#コモンライセンス
-require 'spec_helper'
-
-describe CommonLicense do
-  before do
-    #テストデータを用意してね
-    @f = Rails.root + 'spec/json/common_license.json'
-    @t = File.open(@f, 'r').read
-    @j = JSON.parse @t
-    @fs = Rails.root + 'spec/json/common_licenses.json'
-    @ts = File.open(@fs, 'r').read
-    @js = JSON.parse @ts
-    @fes = Rails.root + 'spec/json/invalid_common_licenses.json'
-    @tes = File.open(@fes, 'r').read
-    @jes = JSON.parse @tes
-  end
-  describe '検証に於いて' do
-    before do
-      @l = Factory :license
-    end
-    
-    it 'オーソドックスなデータなら通る' do
-      @cl = Factory.build :common_license, :license_id => @l.id
-      @cl.should be_valid
-    end
-    
-    context 'nameを検証するとき' do
-      before do
-        @cl = Factory.build :common_license, :license_id => @l.id
-      end
-      it 'テストデータの確認' do
-        @cl.name = 'CC by'
-        @cl.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @cl.name = ''
-        @cl.should_not be_valid
-      end
-      it '51文字以上なら失敗する' do
-        @cl.name = 'a'*51
-        @cl.should_not be_valid
-      end
-    end
-    context 'urlを検証するとき' do
-      before do
-        @cl = Factory.build :common_license, :license_id => @l.id
-      end
-      it 'テストデータの確認' do
-        @cl.url = 'CC by'
-        @cl.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @cl.url = ''
-        @cl.should_not be_valid
-      end
-      it '201文字以上なら失敗する' do
-        @cl.url = 'a'*201
-        @cl.should_not be_valid
-      end
-      it '重複していたら失敗する' do
-        cl = Factory :common_license, :license_id => @l.id
-        @cl.should_not be_valid
-      end
-      it 'url形式でなら失敗する' do
-        @cl.url = ''
-        pending
-      end
-    end
-    context 'license_idを検証するとき' do
-      before do
-        @cl = Factory.build :common_license
-      end
-      it 'テストデータの確認' do
-        @cl.license_id = @l.id
-        @cl.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @cl.license_id = nil
-        @cl.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @cl.license_id = 'a'
-        @cl.should_not be_valid
-      end
-      it '存在するlicenseでなければ失敗する' do
-        @cl.license_id = 0
-        @cl.should_not be_valid
-      end
-    end
-  end
-  
-  describe '対象コモンライセンスの取得に於いて' do
-    before do
-      @lc = Factory :license
-      @cl = Factory :common_license, :license_id => @lc.id
-    end
-    context 'urlが一致するコモンライセンスがないとき' do
-      it '新規コモンライセンスを準備して返す' do
-        r = CommonLicense.update_common_license Factory.attributes_for(:common_license, :url => 'http://domain.no')
-        r.should be_a_new CommonLicense
-      end
-    end
-    context 'urlが一致するコモンライセンスがあるとき' do
-      it '該当コモンライセンスを返す' do
-        prm = Factory.attributes_for(:common_license)
-        r = CommonLicense.update_common_license prm
-        r.is_a?(CommonLicense).should be_true
-        r.should_not be_a_new CommonLicense
-        r[:url].should eq prm[:url]
-      end
-    end
-  end
-  
-  describe 'コモンライセンス更新に於いて' do
-    before do
-      @lc = Factory :license
-      @cl = Factory :common_license, :license_id => @lc.id
-      @attr = Factory.attributes_for(:common_license, :name => 'exist case')
-      @newattr = Factory.attributes_for(:common_license, :url => 'http://domain.no')
-    end
-    context 'つつがなく終わるとき' do
-      it '対象コモンライセンスを問い合わせている' do
-        CommonLicense.stub(:update_common_license).with(any_args).and_return(CommonLicense.new(@attr))
-        CommonLicense.should_receive(:update_common_license).exactly(1)
-        CommonLicense.store @attr
-      end
-      context '新規のとき' do
-        it 'コモンライセンスを保存しようとしている' do
-          CommonLicense.any_instance.should_receive(:save).exactly(1)
-          CommonLicense.store @newattr
-        end
-        it 'コモンライセンスが作成されている' do
-          lambda {
-            CommonLicense.store @newattr
-          }.should change CommonLicense, :count
-        end
-        context 'ライセンスとの連動' do
-          it 'ライセンスが作成されている' do
-            lambda {
-              CommonLicense.store @newattr
-            }.should change License, :count
-          end
-          it '両者がリンクされている' do
-            r = CommonLicense.store @newattr
-            l = License.find(r.license_id)
-            l.should be_true
-          end
-          it '属性が一致している' do
-            r = CommonLicense.store @newattr
-            l = License.find(r.license_id)
-            l.url.should eq r.url
-            l.name.should eq r.name
-          end
-        end
-      end
-      context '更新のとき' do
-        it 'コモンライセンスを保存しようとしている' do
-          CommonLicense.any_instance.should_receive(:save).exactly(1)
-          CommonLicense.store @attr
-        end
-        it 'コモンライセンスの数に変化がない' do
-          lambda {
-            CommonLicense.store @attr
-          }.should_not change CommonLicense, :count
-        end
-        context 'ライセンスとの連動' do
-          it 'ライセンスの数に変化がない' do
-            lambda {
-              CommonLicense.store @attr
-            }.should_not change License, :count
-          end
-          it '両者がリンクされている' do
-            r = CommonLicense.store @attr
-            l = License.find(r.license_id)
-            l.should be_true
-          end
-          it '属性が一致している' do
-            r = CommonLicense.store @attr
-            l = License.find(r.license_id)
-            l.url.should eq r.url
-            l.name.should eq r.name
-          end
-        end
-      end
-      it '属性が一致している' do
-        r = CommonLicense.store @newattr
-        r.url.should eq @newattr[:url]
-        r.name.should eq @newattr[:name]
-      end
-      it '保存されたCommonLicenseオブジェクトを返す' do
-        r = CommonLicense.store @newattr
-        r.should_not be_a_new CommonLicense
-      end
-    end
-    context 'ライセンスの作成に失敗するとき' do
-      before do
-        License.any_instance.stub(:save).with(any_args).and_return(false)
-      end
-      context '新規のとき' do
-        it 'ライセンスに変化がない' do
-          lambda {
-            r = CommonLicense.store @newattr
-          }.should_not change License, :count
-        end
-        it 'コモンライセンスに変化がない' do
-          lambda {
-            r = CommonLicense.store @newattr
-          }.should_not change CommonLicense, :count
-        end
-      end
-      context '更新のとき' do
-        it 'コモンライセンス属性に変化がない' do
-          lambda {
-            r = CommonLicense.store @attr
-          }.should_not change License.find(@cl.id), :name
-        end
-        it 'ライセンス属性に変化がない' do
-          lambda {
-            r = CommonLicense.store @attr
-          }.should_not change License.find(@lc.id), :name
-        end
-      end
-    end
-    context 'コモンライセンスの作成に失敗するとき' do
-      before do
-        CommonLicense.any_instance.stub(:save).with(any_args).and_return(false)
-      end
-      context '新規のとき' do
-        it 'ライセンスに変化がない' do
-          lambda {
-            r = CommonLicense.store @newattr
-          }.should_not change License, :count
-        end
-        it 'コモンライセンスに変化がない' do
-          lambda {
-            r = CommonLicense.store @newattr
-          }.should_not change CommonLicense, :count
-        end
-      end
-      context '更新のとき' do
-        it 'コモンライセンス属性に変化がない' do
-          lambda {
-            r = CommonLicense.store @attr
-          }.should_not change License.find(@cl.id), :name
-        end
-        it 'ライセンス属性に変化がない' do
-          lambda {
-            r = CommonLicense.store @attr
-          }.should_not change License.find(@lc.id), :name
-        end
-      end
-    end
-  end
-=begin  
-  describe '単体取得に於いて' do
-    before do
-      @cl = Factory.build :common_license
-      @cl.store
-    end
-    it '指定のライセンスを返す' do
-      l = CommonLicense.show @cl.id
-      l.should eq @cl
-    end
-    context '関連テーブルオプションがないとき' do
-      it 'ライセンスだけを含んでいる' do
-        r = CommonLicense.show_include_opt
-        r.should eq [:license]
-      end
-    end
-    context '関連テーブルオプションでコマを含ませたとき' do
-      it 'ライセンスと作家を含んでいる' do
-        r = CommonLicense.show_include_opt(:include => :author)
-        r.should eq [:license, :author]
-      end
-    end
-  end
-  describe '一覧取得に於いて' do
-    before do
-      @cl = Factory.build :common_license
-      @cl.store
-    end
-    context 'page補正について' do
-      it '文字列から数値に変換される' do
-        CommonLicense.page('8').should eq 8
-      end
-      it 'nilの場合は1になる' do
-        CommonLicense.page().should eq 1
-      end
-      it '0以下の場合は1になる' do
-        CommonLicense.page('0').should eq 1
-      end
-    end
-    context 'page_size補正について' do
-      it '文字列から数値に変換される' do
-        CommonLicense.page_size('7').should eq 7
-      end
-      it 'nilの場合はCommonLicense.default_page_sizeになる' do
-        CommonLicense.page_size().should eq CommonLicense.default_page_size
-      end
-      it '0以下の場合はCommonLicense.default_page_sizeになる' do
-        CommonLicense.page_size('0').should eq CommonLicense.default_page_size
-      end
-      it 'CommonLicense.max_page_sizeを超えた場合はCommonLicense.max_page_sizeになる' do
-        CommonLicense.page_size('1000').should eq CommonLicense.max_page_size
-      end
-    end
-    it 'リストを返す' do
-      l = CommonLicense.list
-      l.should eq [@cl]
-    end
-    it '名前順で並んでいる' do
-      n = Factory.build :common_license, :url => 'tes.to', :name => 'peta2.2'
-      n.store
-      l = CommonLicense.list
-      l.should eq [@cl, n]
-    end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @license2 = Factory.build :common_license, :url => 'tes.to2', :name => 'peta2.2'
-        @license2.store
-        @license3 = Factory.build :common_license, :url => 'tes.to3', :name => 'peta2.3'
-        @license3.store
-        @license4 = Factory.build :common_license, :url => 'tes.to4', :name => 'peta2.4'
-        @license4.store
-        @license5 = Factory.build :common_license, :url => 'tes.to5', :name => 'peta2.5'
-        @license5.store
-        CommonLicense.stub(:default_page_size).and_return(2)
-      end
-      it '通常は2件を返す' do
-        l = CommonLicense.list
-        l.should have(2).items 
-      end
-      it 'page=1なら末尾2件を返す' do
-        #時系列で並んでいる
-        l = CommonLicense.list({}, 1)
-        l.should eq [@cl, @license2]
-      end
-      it 'page=2なら中間2件を返す' do
-        l = CommonLicense.list({}, 2)
-        l.should eq [@license3, @license4]
-      end
-      it 'page=3なら先頭1件を返す' do
-        l = CommonLicense.list({}, 3)
-        l.should eq [@license5]
-      end
-    end
-  end
-=end
-  
-  describe 'Json解析に於いて' do
-    before do
-    end
-    context 'テキストを渡されたとき' do
-      it 'Json解析している' do
-        JSON.should_receive(:parse).with(@t).exactly(1)
-        r = CommonLicense.parse @t
-      end
-      it '単数データならHashで返す' do
-        r = CommonLicense.parse @t
-        r.is_a?(Hash).should be_true
-      end
-      it '複数データならArrayで返す' do
-        r = CommonLicense.parse @ts
-        r.is_a?(Array).should be_true
-      end
-    end
-    context 'パース失敗したとき' do
-      it 'Falseを返す' do
-        JSON.should_receive(:parse).with(any_args).and_raise('StandardError')
-        r = CommonLicense.parse @t
-        r.should be_false
-      end
-    end
-  end
-  
-  describe 'Jsonの繰り返し処理に於いて' do
-    before do
-    end
-    context '単体データを渡されたとき' do
-      it '一回処理' do
-        r = []
-        CommonLicense.each_license @j do |i|
-          r << i
-        end
-        r.size.should eq 1
-      end
-    end
-    context '複数を渡されたとき' do
-      it '二回処理' do
-        r = []
-        CommonLicense.each_license @js do |i|
-          r << i
-        end
-        r.size.should eq 2
-      end
-    end
-  end
-  
-  describe 'テキスト取り込みに於いて' do
-    #成功でTrue、パース失敗でFalse、失敗は保存エラーのモデルを配列で返す
-    #Licenseとの連動が完成していること
-    before do
-    end
-    context 'つつがなく終わるとき' do
-      it 'Json解析を依頼する' do
-        CommonLicense.should_receive(:parse).with(any_args).exactly(1)
-        CommonLicense.stub(:parse).with(any_args).and_return(@j)
-        CommonLicense.import(@t)
-      end
-      it '繰り返し処理を依頼する' do
-        CommonLicense.should_receive(:each_license).with(any_args).exactly(1)
-        CommonLicense.import(@t)
-      end
-      it 'ライセンス更新を一回依頼する' do
-        CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
-        CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
-        CommonLicense.should_receive(:store).with(any_args).exactly(1)
-        CommonLicense.import(@t)
-      end
-      it 'コモンライセンスが追加される' do
-        lambda {
-          CommonLicense.import(@t)
-        }.should change CommonLicense, :count
-      end
-      it '[]を返す' do
-        CommonLicense.import(@t).should eq []
-      end
-    end
-    context '複数データがつつがなく終わるとき' do
-      it 'ライセンス更新を二回依頼する' do
-        CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
-        CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
-        CommonLicense.should_receive(:store).with(any_args).exactly(2)
-        CommonLicense.import(@ts)
-      end
-      it 'コモンライセンスが二個追加される' do
-        lambda {
-          CommonLicense.import(@ts)
-        }.should change(CommonLicense, :count).by 2
-      end
-      it '[]を返す' do
-        CommonLicense.import(@ts).should eq []
-      end
-    end
-    #例外ケース
-    context 'Json解析に失敗したとき' do
-      before do
-        CommonLicense.stub(:parse).with(any_args).and_return(false)
-      end
-      it 'コモンライセンスの数に変化がない' do
-        lambda {
-          CommonLicense.import(@t)
-        }.should_not change CommonLicense, :count
-      end
-      it 'Falseを返す' do
-        CommonLicense.import(@t).should be_false
-      end
-    end
-    context 'コモンライセンス作成に失敗したとき' do
-      before do
-        CommonLicense.any_instance.stub(:save).with(any_args).and_return(false)
-        CommonLicense.any_instance.stub(:valid?).with(any_args).and_return(false)
-      end
-      it 'コモンライセンスの数に変化がない' do
-        lambda {
-          CommonLicense.import(@t)
-        }.should_not change CommonLicense, :count
-      end
-      it '配列を返す' do
-        r = CommonLicense.import(@t)
-        r.is_a?(Array).should be_true
-      end
-      it '配列の中身は一件' do
-        r = CommonLicense.import(@t)
-        r.should have(1).items
-      end
-      it 'コモンライセンスオブジェクトが入っている' do
-        r = CommonLicense.import(@t)
-        r.first.is_a?(CommonLicense).should be_true
-      end
-    end
-    context '複数のコモンライセンス作成に失敗したとき' do
-      #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
-      it 'コモンライセンスの数に変化がない' do
-        lambda {
-          CommonLicense.import(@tes)
-        }.should_not change CommonLicense, :count
-      end
-      it '途中で保存に失敗しても全件更新依頼する' do
-        CommonLicense.stub(:store).with(any_args).and_return(CommonLicense.new)
-        CommonLicense.should_receive(:store).with(any_args).exactly(3)
-        CommonLicense.import(@tes)
-      end
-      it '配列を返す' do
-        r = CommonLicense.import(@tes)
-        r.is_a?(Array).should be_true
-      end
-      it '配列の中身は2件' do
-        r = CommonLicense.import(@tes)
-        r.should have(2).items
-      end
-      it '配列の中身は失敗したコモンライセンスオブジェクトが入っている' do
-        r = CommonLicense.import(@tes)
-        r[0].is_a?(CommonLicense).should be_true
-        r[0]["name"].should eq 'fail1'
-        r[1].is_a?(CommonLicense).should be_true
-        r[1]["name"].should eq 'fail2'
-      end
-    end
-  end
-  
-  describe 'インポートエラーの表示に於いて' do
-  end
-  
-  describe 'ファイル取り込みに於いて' do
-    before do
-      CommonLicense.stub(:import).with(any_args).and_return(true)
-    end
-    context 'つつがなく終わるとき' do
-      before do
-        CommonLicense.stub(:import).with(any_args).and_return(true)
-      end
-      it 'ファイルを開いてテキストを読む' do
-        File.should_receive(:open).with(@f, 'r').exactly(1)
-        CommonLicense.import_file(@f)
-      end
-      it 'テキスト取り込みを依頼する' do
-        CommonLicense.should_receive(:import).with(any_args).exactly(1)
-        CommonLicense.import_file(@f)
-      end
-      #テキスト取り込み成功でTrueが返る
-      it 'Trueを返す' do
-        CommonLicense.import_file(@f).should be_true
-      end
-    end
-    context 'ファイルが開けないとき' do
-      before do
-        File.stub(:open).with(any_args).and_raise('StandardError')
-      end
-      it 'ファイルエラーのメッセージを出力する' do
-        pending
-      end
-      it 'Falseを返す' do
-        CommonLicense.import_file(@f).should be_false
-      end
-    end
-    #失敗したときは、失敗したライセンスが配列で返る
-    context 'テキスト取り込みが失敗したとき' do
-      before do
-        CommonLicense.stub(:import).with(any_args).and_return(false)
-      end
-      it '各コモンライセンスのエラーメッセージを出力する' do
-        pending
-      end
-      it 'Falseを返す' do
-        CommonLicense.import_file(@f).should be_false
-      end
-    end
-  end
-  
-end
index d8f3010..e69de29 100644 (file)
@@ -1,558 +0,0 @@
-# -*- encoding: utf-8 -*-
-#オリジナルライセンス
-require 'spec_helper'
-
-describe OriginalLicense do
-  before do
-    #テストデータを用意してね
-    @f = Rails.root + 'spec/json/original_license.json'
-    @t = File.open(@f, 'r').read
-    @j = JSON.parse @t
-    @fs = Rails.root + 'spec/json/original_licenses.json'
-    @ts = File.open(@fs, 'r').read
-    @js = JSON.parse @ts
-    @fes = Rails.root + 'spec/json/invalid_original_licenses.json'
-    @tes = File.open(@fes, 'r').read
-    @jes = JSON.parse @tes
-  end
-  describe '検証に於いて' do
-    before do
-      @l = Factory :license
-    end
-    
-    it 'オーソドックスなデータなら通る' do
-      @ol = Factory.build :original_license, :license_id => @l.id
-      @ol.should be_valid
-    end
-    
-    context 'nameを検証するとき' do
-      before do
-        @ol = Factory.build :original_license, :license_id => @l.id
-      end
-      it 'テストデータの確認' do
-        @ol.name = 'CC by'
-        @ol.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @ol.name = ''
-        @ol.should_not be_valid
-      end
-      it '51文字以上なら失敗する' do
-        @ol.name = 'a'*51
-        @ol.should_not be_valid
-      end
-    end
-    context 'urlを検証するとき' do
-      before do
-        @ol = Factory.build :original_license, :license_id => @l.id
-      end
-      it 'テストデータの確認' do
-        @ol.url = 'CC by'
-        @ol.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @ol.url = ''
-        @ol.should_not be_valid
-      end
-      it '201文字以上なら失敗する' do
-        @ol.url = 'a'*201
-        @ol.should_not be_valid
-      end
-      it '重複していたら失敗する' do
-        cl = Factory :original_license, :license_id => @l.id
-        @ol.should_not be_valid
-      end
-      it 'url形式でなら失敗する' do
-        @ol.url = ''
-        pending
-      end
-    end
-    context 'license_idを検証するとき' do
-      before do
-        @ol = Factory.build :original_license
-      end
-      it 'テストデータの確認' do
-        @ol.license_id = @l.id
-        @ol.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @ol.license_id = nil
-        @ol.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @ol.license_id = 'a'
-        @ol.should_not be_valid
-      end
-      it '存在するlicenseでなければ失敗する' do
-        @ol.license_id = 0
-        @ol.should_not be_valid
-      end
-    end
-  end
-  
-  describe '対象オリジナルライセンスの取得に於いて' do
-    before do
-      @lc = Factory :license
-      @ol = Factory :original_license, :license_id => @lc.id
-    end
-    context 'urlが一致するオリジナルライセンスがないとき' do
-      it '新規オリジナルライセンスを準備して返す' do
-        r = OriginalLicense.update_original_license Factory.attributes_for(:original_license, :url => 'http://domain.no')
-        r.should be_a_new OriginalLicense
-      end
-    end
-    context 'urlが一致するオリジナルライセンスがあるとき' do
-      it '該当オリジナルライセンスを返す' do
-        prm = Factory.attributes_for(:original_license)
-        r = OriginalLicense.update_original_license prm
-        r.is_a?(OriginalLicense).should be_true
-        r.should_not be_a_new OriginalLicense
-        r[:url].should eq prm[:url]
-      end
-    end
-  end
-  
-  describe 'オリジナルライセンス更新に於いて' do
-    before do
-      @lc = Factory :license
-      @ol = Factory :original_license, :license_id => @lc.id, :url => @lc.url
-      @attr = Factory.attributes_for(:original_license, :name => 'exist case', :url => @lc.url)
-      @newattr = Factory.attributes_for(:original_license, :url => 'http://domain.no')
-    end
-    context 'つつがなく終わるとき' do
-      it '対象オリジナルライセンスを問い合わせている' do
-        OriginalLicense.stub(:update_original_license).with(any_args).and_return(OriginalLicense.new(@attr))
-        OriginalLicense.should_receive(:update_original_license).exactly(1)
-        OriginalLicense.store @attr
-      end
-      context '新規のとき' do
-        it 'オリジナルライセンスを保存しようとしている' do
-          OriginalLicense.any_instance.should_receive(:save).exactly(1)
-          OriginalLicense.store @newattr
-        end
-        it 'オリジナルライセンスが作成されている' do
-          lambda {
-            OriginalLicense.store @newattr
-          }.should change OriginalLicense, :count
-        end
-        context 'ライセンスとの連動' do
-          it 'ライセンスが作成されている' do
-            lambda {
-              OriginalLicense.store @newattr
-            }.should change License, :count
-          end
-          it '両者がリンクされている' do
-            r = OriginalLicense.store @newattr
-            l = License.find(r.license_id)
-            l.should be_true
-          end
-          it '属性が一致している' do
-            r = OriginalLicense.store @newattr
-            l = License.find(r.license_id)
-            l.url.should eq r.url
-            l.name.should eq r.name
-          end
-        end
-      end
-      context '更新のとき' do
-        it 'オリジナルライセンスを保存しようとしている' do
-          OriginalLicense.any_instance.should_receive(:save).exactly(1)
-          OriginalLicense.store @attr
-        end
-        it 'オリジナルライセンスの数に変化がない' do
-          lambda {
-            OriginalLicense.store @attr
-          }.should_not change OriginalLicense, :count
-        end
-        context 'ライセンスとの連動' do
-          it 'ライセンスの数に変化がない' do
-            lambda {
-              OriginalLicense.store @attr
-            }.should_not change License, :count
-          end
-          it '両者がリンクされている' do
-            r = OriginalLicense.store @attr
-            l = License.find(r.license_id)
-            l.should be_true
-          end
-          it '属性が一致している' do
-            r = OriginalLicense.store @attr
-            l = License.find(r.license_id)
-            l.url.should eq r.url
-            l.name.should eq r.name
-          end
-        end
-      end
-      it '属性が一致している' do
-        r = OriginalLicense.store @newattr
-        r.url.should eq @newattr[:url]
-        r.name.should eq @newattr[:name]
-      end
-      it '保存されたOriginalLicenseオブジェクトを返す' do
-        r = OriginalLicense.store @newattr
-        r.should_not be_a_new OriginalLicense
-      end
-    end
-    context 'ライセンスの作成に失敗するとき' do
-      before do
-        License.any_instance.stub(:save).with(any_args).and_return(false)
-      end
-      context '新規のとき' do
-        it 'ライセンスに変化がない' do
-          lambda {
-            r = OriginalLicense.store @newattr
-          }.should_not change License, :count
-        end
-        it 'オリジナルライセンスに変化がない' do
-          lambda {
-            r = OriginalLicense.store @newattr
-          }.should_not change OriginalLicense, :count
-        end
-      end
-      context '更新のとき' do
-        it 'オリジナルライセンス属性に変化がない' do
-          lambda {
-            r = OriginalLicense.store @attr
-          }.should_not change License.find(@ol.id), :name
-        end
-        it 'ライセンス属性に変化がない' do
-          lambda {
-            r = OriginalLicense.store @attr
-          }.should_not change License.find(@lc.id), :name
-        end
-      end
-    end
-    context 'オリジナルライセンスの作成に失敗するとき' do
-      before do
-        OriginalLicense.any_instance.stub(:save).with(any_args).and_return(false)
-      end
-      context '新規のとき' do
-        it 'ライセンスに変化がない' do
-          lambda {
-            r = OriginalLicense.store @newattr
-          }.should_not change License, :count
-        end
-        it 'オリジナルライセンスに変化がない' do
-          lambda {
-            r = OriginalLicense.store @newattr
-          }.should_not change OriginalLicense, :count
-        end
-      end
-      context '更新のとき' do
-        it 'オリジナルライセンス属性に変化がない' do
-          lambda {
-            r = OriginalLicense.store @attr
-          }.should_not change License.find(@ol.id), :name
-        end
-        it 'ライセンス属性に変化がない' do
-          lambda {
-            r = OriginalLicense.store @attr
-          }.should_not change License.find(@lc.id), :name
-        end
-      end
-    end
-  end
-  
-  describe '単体取得に於いて' do
-    before do
-      @ol = Factory.build :original_license
-      @ol.store
-    end
-    it '指定のライセンスを返す' do
-      l = OriginalLicense.show @ol.id
-      l.should eq @ol
-    end
-    context '関連テーブルオプションがないとき' do
-      it 'ライセンスだけを含んでいる' do
-        r = OriginalLicense.show_include_opt
-        r.should eq [:license]
-      end
-    end
-    context '関連テーブルオプションで作家を含ませたとき' do
-      it 'ライセンスと作家を含んでいる' do
-        r = OriginalLicense.show_include_opt(:include => :author)
-        r.should eq [:license, :author]
-      end
-    end
-  end
-  describe '一覧取得に於いて' do
-    before do
-      @ol = Factory.build :original_license
-      @ol.store
-    end
-    context 'page補正について' do
-      it '文字列から数値に変換される' do
-        OriginalLicense.page('8').should eq 8
-      end
-      it 'nilの場合は1になる' do
-        OriginalLicense.page().should eq 1
-      end
-      it '0以下の場合は1になる' do
-        OriginalLicense.page('0').should eq 1
-      end
-    end
-    context 'page_size補正について' do
-      it '文字列から数値に変換される' do
-        OriginalLicense.page_size('7').should eq 7
-      end
-      it 'nilの場合はOriginalLicense.default_page_sizeになる' do
-        OriginalLicense.page_size().should eq OriginalLicense.default_page_size
-      end
-      it '0以下の場合はOriginalLicense.default_page_sizeになる' do
-        OriginalLicense.page_size('0').should eq OriginalLicense.default_page_size
-      end
-      it 'OriginalLicense.max_page_sizeを超えた場合はOriginalLicense.max_page_sizeになる' do
-        OriginalLicense.page_size('1000').should eq OriginalLicense.max_page_size
-      end
-    end
-    it 'リストを返す' do
-      l = OriginalLicense.list
-      l.should eq [@ol]
-    end
-    it '名前順で並んでいる' do
-      n = Factory.build :original_license, :url => 'http://tes.to', :name => 'peta2.2'
-      n.store
-      l = OriginalLicense.list
-      l.should eq [@ol, n]
-    end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @license2 = Factory.build :original_license, :url => 'http://tes.to2', :name => 'peta2.2'
-        @license2.store
-        @license3 = Factory.build :original_license, :url => 'http://tes.to3', :name => 'peta2.3'
-        @license3.store
-        @license4 = Factory.build :original_license, :url => 'http://tes.to4', :name => 'peta2.4'
-        @license4.store
-        @license5 = Factory.build :original_license, :url => 'http://tes.to5', :name => 'peta2.5'
-        @license5.store
-        OriginalLicense.stub(:default_page_size).and_return(2)
-      end
-      it '通常は2件を返す' do
-        l = OriginalLicense.list
-        l.should have(2).items 
-      end
-      it 'page=1なら末尾2件を返す' do
-        #時系列で並んでいる
-        l = OriginalLicense.list({}, 1)
-        l.should eq [@ol, @license2]
-      end
-      it 'page=2なら中間2件を返す' do
-        l = OriginalLicense.list({}, 2)
-        l.should eq [@license3, @license4]
-      end
-      it 'page=3なら先頭1件を返す' do
-        l = OriginalLicense.list({}, 3)
-        l.should eq [@license5]
-      end
-    end
-  end
-  
-  describe 'Json解析に於いて' do
-    before do
-    end
-    context 'テキストを渡されたとき' do
-      it 'Json解析している' do
-        JSON.should_receive(:parse).with(@t).exactly(1)
-        r = OriginalLicense.parse @t
-      end
-      it '単数データならHashで返す' do
-        r = OriginalLicense.parse @t
-        r.is_a?(Hash).should be_true
-      end
-      it '複数データならArrayで返す' do
-        r = OriginalLicense.parse @ts
-        r.is_a?(Array).should be_true
-      end
-    end
-    context 'パース失敗したとき' do
-      it 'Falseを返す' do
-        JSON.should_receive(:parse).with(any_args).and_raise('StandardError')
-        r = OriginalLicense.parse @t
-        r.should be_false
-      end
-    end
-  end
-  
-  describe 'Jsonの繰り返し処理に於いて' do
-    before do
-    end
-    context '単体データを渡されたとき' do
-      it '一回処理' do
-        r = []
-        OriginalLicense.each_license @j do |i|
-          r << i
-        end
-        r.size.should eq 1
-      end
-    end
-    context '複数を渡されたとき' do
-      it '二回処理' do
-        r = []
-        OriginalLicense.each_license @js do |i|
-          r << i
-        end
-        r.size.should eq 2
-      end
-    end
-  end
-  
-  describe 'テキスト取り込みに於いて' do
-    #成功でTrue、パース失敗でFalse、失敗は保存エラーのモデルを配列で返す
-    #Licenseとの連動が完成していること
-    before do
-    end
-    context 'つつがなく終わるとき' do
-      it 'Json解析を依頼する' do
-        OriginalLicense.should_receive(:parse).with(any_args).exactly(1)
-        OriginalLicense.stub(:parse).with(any_args).and_return(@j)
-        OriginalLicense.import(@t)
-      end
-      it '繰り返し処理を依頼する' do
-        OriginalLicense.should_receive(:each_license).with(any_args).exactly(1)
-        OriginalLicense.import(@t)
-      end
-      it 'ライセンス更新を一回依頼する' do
-        OriginalLicense.stub(:store).with(any_args).and_return(OriginalLicense.new)
-        OriginalLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
-        OriginalLicense.should_receive(:store).with(any_args).exactly(1)
-        OriginalLicense.import(@t)
-      end
-      it 'オリジナルライセンスが追加される' do
-        lambda {
-          OriginalLicense.import(@t)
-        }.should change OriginalLicense, :count
-      end
-      it '[]を返す' do
-        OriginalLicense.import(@t).should eq []
-      end
-    end
-    context '複数データがつつがなく終わるとき' do
-      it 'ライセンス更新を二回依頼する' do
-        OriginalLicense.stub(:store).with(any_args).and_return(OriginalLicense.new)
-        OriginalLicense.any_instance.stub(:valid?).with(any_args).and_return(true)
-        OriginalLicense.should_receive(:store).with(any_args).exactly(2)
-        OriginalLicense.import(@ts)
-      end
-      it 'オリジナルライセンスが二個追加される' do
-        lambda {
-          OriginalLicense.import(@ts)
-        }.should change(OriginalLicense, :count).by 2
-      end
-      it '[]を返す' do
-        OriginalLicense.import(@ts).should eq []
-      end
-    end
-    #例外ケース
-    context 'Json解析に失敗したとき' do
-      before do
-        OriginalLicense.stub(:parse).with(any_args).and_return(false)
-      end
-      it 'オリジナルライセンスの数に変化がない' do
-        lambda {
-          OriginalLicense.import(@t)
-        }.should_not change OriginalLicense, :count
-      end
-      it 'Falseを返す' do
-        OriginalLicense.import(@t).should be_false
-      end
-    end
-    context 'オリジナルライセンス作成に失敗したとき' do
-      before do
-        OriginalLicense.any_instance.stub(:save).with(any_args).and_return(false)
-        OriginalLicense.any_instance.stub(:valid?).with(any_args).and_return(false)
-      end
-      it 'オリジナルライセンスの数に変化がない' do
-        lambda {
-          OriginalLicense.import(@t)
-        }.should_not change OriginalLicense, :count
-      end
-      it '配列を返す' do
-        r = OriginalLicense.import(@t)
-        r.is_a?(Array).should be_true
-      end
-      it '配列の中身は一件' do
-        r = OriginalLicense.import(@t)
-        r.should have(1).items
-      end
-      it 'オリジナルライセンスオブジェクトが入っている' do
-        r = OriginalLicense.import(@t)
-        r.first.is_a?(OriginalLicense).should be_true
-      end
-    end
-    context '複数のオリジナルライセンス作成に失敗したとき' do
-      #三件中、二件の失敗、一件を成功させ、成功データは戻り値に含まないことを確認する
-      it 'オリジナルライセンスの数に変化がない' do
-        lambda {
-          OriginalLicense.import(@tes)
-        }.should_not change OriginalLicense, :count
-      end
-      it '途中で保存に失敗しても全件更新依頼する' do
-        OriginalLicense.stub(:store).with(any_args).and_return(OriginalLicense.new)
-        OriginalLicense.should_receive(:store).with(any_args).exactly(3)
-        OriginalLicense.import(@tes)
-      end
-      it '配列を返す' do
-        r = OriginalLicense.import(@tes)
-        r.is_a?(Array).should be_true
-      end
-      it '配列の中身は2件' do
-        r = OriginalLicense.import(@tes)
-        r.should have(2).items
-      end
-      it '配列の中身は失敗したオリジナルライセンスオブジェクトが入っている' do
-        r = OriginalLicense.import(@tes)
-        r[0].is_a?(OriginalLicense).should be_true
-        r[0]["name"].should eq 'fail1'
-        r[1].is_a?(OriginalLicense).should be_true
-        r[1]["name"].should eq 'fail2'
-      end
-    end
-  end
-  
-  describe 'ファイル取り込みに於いて' do
-    before do
-      OriginalLicense.stub(:import).with(any_args).and_return(true)
-    end
-    context 'つつがなく終わるとき' do
-      before do
-        OriginalLicense.stub(:import).with(any_args).and_return(true)
-      end
-      it 'ファイルを開いてテキストを読む' do
-        File.should_receive(:open).with(@f, 'r').exactly(1)
-        OriginalLicense.import_file(@f)
-      end
-      it 'テキスト取り込みを依頼する' do
-        OriginalLicense.should_receive(:import).with(any_args).exactly(1)
-        OriginalLicense.import_file(@f)
-      end
-      #テキスト取り込み成功でTrueが返る
-      it 'Trueを返す' do
-        OriginalLicense.import_file(@f).should be_true
-      end
-    end
-    context 'ファイルが開けないとき' do
-      before do
-        File.stub(:open).with(any_args).and_raise('StandardError')
-      end
-      it 'ファイルエラーのメッセージを出力する' do
-        pending
-      end
-      it 'Falseを返す' do
-        OriginalLicense.import_file(@f).should be_false
-      end
-    end
-    #失敗したときは、失敗したライセンスが配列で返る
-    context 'テキスト取り込みが失敗したとき' do
-      before do
-        OriginalLicense.stub(:import).with(any_args).and_return(false)
-      end
-      it '各オリジナルライセンスのエラーメッセージを出力する' do
-        pending
-      end
-      it 'Falseを返す' do
-        OriginalLicense.import_file(@f).should be_false
-      end
-    end
-  end
-  
-end
index 0ec0e91..09d08b0 100644 (file)
@@ -4,7 +4,9 @@ require 'spec_helper'
 describe Panel do\r
   before do\r
     Factory :admin\r
-    @license = Factory :license\r
+    @sp = Factory :system_picture
+    @lg = Factory :license_group
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
     @user = Factory( :user_yas)\r
     @author = @user.author\r
     @artist = Factory :artist_yas, :author_id => @author.id\r