OSDN Git Service

build pictures
authoryasushiito <yas@pen-chan.jp>
Fri, 20 Jul 2012 10:50:17 +0000 (19:50 +0900)
committeryasushiito <yas@pen-chan.jp>
Fri, 20 Jul 2012 10:50:17 +0000 (19:50 +0900)
26 files changed:
app/controllers/panel_pictures_controller.rb
app/controllers/pictures_controller.rb [new file with mode: 0644]
app/controllers/resource_pictures_controller.rb
app/controllers/standard_licenses_controller.rb
app/helpers/pictures_helper.rb [new file with mode: 0644]
app/models/panel_picture.rb
app/models/picture.rb
app/models/resource_picture.rb
app/models/standard_license.rb
app/views/pictures/credit.html.erb [new file with mode: 0644]
app/views/resource_pictures/_form.html.erb
app/views/resource_pictures/credit.html.erb [new file with mode: 0644]
app/views/resource_pictures/index.html.erb
app/views/resource_pictures/show.html.erb
app/views/standard_licenses/_confirm.html.erb
app/views/standard_licenses/_credit.html.erb
db/migrate/20120713230519_add_credit_data.rb [new file with mode: 0644]
spec/controllers/panel_pictures_controller_spec.rb
spec/controllers/panels_controller_spec.rb
spec/controllers/pictures_controller_spec.rb [new file with mode: 0644]
spec/factories.rb
spec/helpers/pictures_helper_spec.rb [new file with mode: 0644]
spec/models/panel_picture_spec.rb
spec/models/picture_spec.rb
spec/models/resource_picture_spec.rb
spec/models/standard_license_spec.rb

index 94ebf94..d73715e 100644 (file)
@@ -1,4 +1,5 @@
 class PanelPicturesController < ApplicationController
+  layout 'test' if Pettanr::TestLayout
   before_filter :authenticate_user!, :only => [:index, :show]
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
diff --git a/app/controllers/pictures_controller.rb b/app/controllers/pictures_controller.rb
new file mode 100644 (file)
index 0000000..5aea247
--- /dev/null
@@ -0,0 +1,12 @@
+class PicturesController < ApplicationController
+  layout 'test' if Pettanr::TestLayout
+  def credit
+    @picture = Picture.show(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render :json => @picture.to_json(Picture.list_json_opt)}
+    end
+  end
+  
+end
index e7af0ea..55184fd 100644 (file)
@@ -1,5 +1,6 @@
 class ResourcePicturesController < ApplicationController
-  before_filter :authenticate_user!, :only => [:index, :show, :new, :create]
+  layout 'test' if Pettanr::TestLayout
+  before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :update]
   before_filter :authenticate_admin!, :only => [:list, :browse]
 
   # GET /resource_pictures
@@ -30,11 +31,20 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
+  def credit
+    @resource_picture = ResourcePicture.show(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render :json => @resource_picture.to_json(ResourcePicture.list_json_opt)}
+    end
+  end
+  
   def new
     @original_picture = OriginalPicture.show params[:original_picture_id], @artist
     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
-    @resource_picture = ResourcePicture.new params[:resource_picture]
+    @resource_picture = @original_picture.resource_picture || ResourcePicture.new(params[:resource_picture])
     @license = @resource_picture.license
     
     respond_to do |format|
@@ -47,19 +57,39 @@ class ResourcePicturesController < ApplicationController
     @original_picture = OriginalPicture.show params[:original_picture_id], @artist
     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
-    @resource_picture = ResourcePicture.new params[:resource_picture]
+    @resource_picture = ResourcePicture.new(params[:resource_picture])
     @license = @resource_picture.license
 
     respond_to do |format|
       if @resource_picture.store
-        format.html { render :template => "resource_pictures/new" }
-        format.js { render :template => "resource_pictures/new" }
+        format.html { redirect_to @resource_picture }
+        format.js { render json: @resource_picture, status: :created, location: @resource_picture }
       else
         format.html { render action: "new" }
         format.js { render action: "new" }
       end
     end
   end
+  
+  def update
+    @original_picture = OriginalPicture.show params[:original_picture_id], @artist
+    @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
+    @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
+    @resource_picture = @original_picture.resource_picture
+    @resource_picture.attributes =  params[:resource_picture]
+    @license = @resource_picture.license
+
+    respond_to do |format|
+      if @resource_picture.store
+        format.html { redirect_to @resource_picture }
+        format.js { render json: @resource_picture, status: :created, location: @resource_picture }
+      else
+        format.html { render action: "new" }
+        format.js { render action: "new" }
+      end
+    end
+  end
+  
   def count
     @resource_picture = {:count => ResourcePicture.visible_count}
     respond_to do |format|
index 993e210..1b106b9 100644 (file)
@@ -45,10 +45,12 @@ class StandardLicensesController < ApplicationController
     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
     @standard_license = StandardLicense.new params[:standard_license]
     @license = License.show @standard_license.license_id
-    @resource_picture = ResourcePicture.new :original_picture_id => @original_picture.id, 
-      :license_id => @license.id, :artist_name => @standard_license.artist_name, 
+    @resource_picture = @original_picture.resource_picture || ResourcePicture.new
+    @resource_picture.attributes = {
+      :original_picture_id => @original_picture.id, :license_id => @license.id, 
+      :artist_name => @standard_license.artist_name, :classname => @license_group.classname, 
       :credit => @standard_license.credit, :settings => @license.settings
-
+    }
     respond_to do |format|
       if @standard_license.valid?
         format.html { render :template => "resource_pictures/new" }
diff --git a/app/helpers/pictures_helper.rb b/app/helpers/pictures_helper.rb
new file mode 100644 (file)
index 0000000..f1a9d9c
--- /dev/null
@@ -0,0 +1,2 @@
+module PicturesHelper
+end
index eab88aa..8b8c515 100644 (file)
@@ -2,8 +2,7 @@ class PanelPicture < ActiveRecord::Base
   belongs_to :panel
   belongs_to :resource_picture
   
-  validates :panel_id, :numericality => {:allow_blank => true}
-  validates :resource_picture_id, :presence => true, :numericality => true, :existence => true
+  validates :panel_id, :presence => true, :numericality => true, :existence => true
   validates :link, :length => {:maximum => 200}
   validates :x, :presence => true, :numericality => true
   validates :y, :presence => true, :numericality => true
index 214b1c8..ed212f4 100644 (file)
@@ -1,3 +1,4 @@
+#実素材
 class Picture < ActiveRecord::Base
   belongs_to :original_picture
   belongs_to :license
@@ -6,13 +7,14 @@ class Picture < ActiveRecord::Base
   
   validates :original_picture_id, :presence => true, :numericality => true, :existence => true
   validates :revision, :presence => true, :numericality => true
-  validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}\r
+  validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
   validates :width, :presence => true, :numericality => true, :natural_number => true
   validates :height, :presence => true, :numericality => true, :natural_number => true
   validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
   validates :license_id, :presence => true, :numericality => true, :existence => true
   validates :artist_id, :presence => true, :numericality => true, :existence => true
   validates :artist_name, :presence => true
+  validates :classname, :presence => true, :length => {:maximum => 50}
   
   def dext
     self.ext.downcase
@@ -65,7 +67,7 @@ class Picture < ActiveRecord::Base
   def copy_data(rp)
     attr = {:width => rp.width, :height => rp.height, :ext => rp.ext, :filesize => rp.filesize, 
       :original_picture_id => rp.original_picture_id, :license_id => rp.license_id, :artist_id => rp.artist_id, 
-      :artist_name => rp.artist_name, :credit => rp.credit, :settings => rp.settings
+      :artist_name => rp.artist_name, :classname => rp.classname, :credit => rp.credit, :settings => rp.settings
     }
     self.attributes = attr
   end
@@ -101,6 +103,18 @@ class Picture < ActiveRecord::Base
     PictureIO.resource_picture_io.get self.filename, subdir
   end
   
+  def credit_template
+    "#{self.classname.tableize}/credit"
+  end
+  
+  def credit_data
+    begin
+      @credit_data = JSON.parse(self.credit) unless @credit_data
+    rescue 
+    end
+    @credit_data
+  end
+  
   def flags
     begin
       @flags = JSON.parse(self.settings) unless @flags
index 2735db6..13a83fe 100644 (file)
@@ -1,3 +1,4 @@
+#素材
 class ResourcePicture < ActiveRecord::Base
   belongs_to :artist
   belongs_to :license
@@ -5,7 +6,7 @@ class ResourcePicture < ActiveRecord::Base
   has_many :panel_pictures
   belongs_to :original_picture
   
-  validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}\r
+  validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
   validates :width, :presence => true, :numericality => true, :natural_number => true
   validates :height, :presence => true, :numericality => true, :natural_number => true
   validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
@@ -13,6 +14,7 @@ class ResourcePicture < ActiveRecord::Base
   validates :license_id, :presence => true, :numericality => true, :existence => true
   validates :original_picture_id, :presence => true, :numericality => true, :existence => true
   validates :artist_name, :presence => true
+  validates :classname, :presence => true, :length => {:maximum => 50}
   validates :picture_id, :presence => true, :numericality => true, :existence => true
   
   before_destroy :destroy_with_file
@@ -230,6 +232,18 @@ class ResourcePicture < ActiveRecord::Base
     ResourcePicture.count
   end
   
+  def credit_template
+    "#{self.classname.tableize}/credit"
+  end
+  
+  def credit_data
+    begin
+      @credit_data = JSON.parse(self.credit) unless @credit_data
+    rescue 
+    end
+    @credit_data
+  end
+  
   def flags
     begin
       @flags = JSON.parse(self.settings) unless @flags
index 4c50d04..e359c6c 100644 (file)
@@ -9,7 +9,9 @@ class StandardLicense < ActiveRecord::Base
   end
   
   def credit
-    nil
+    {
+      :system_picture_id => self.license.system_picture_id
+    }.to_json.to_s
   end
   
 end
diff --git a/app/views/pictures/credit.html.erb b/app/views/pictures/credit.html.erb
new file mode 100644 (file)
index 0000000..558fc61
--- /dev/null
@@ -0,0 +1 @@
+<%= render @picture.credit_template %>
index ccbe94e..809410c 100644 (file)
@@ -8,6 +8,7 @@
   <%= f.hidden_field :original_picture_id %>
   <%= f.hidden_field :license_id %>
   <%= f.hidden_field :artist_name %>
+  <%= f.hidden_field :classname %>
   <%= f.hidden_field :credit %>
   <%= f.hidden_field :settings %>
 
@@ -19,7 +20,7 @@
     artist name:<%= @resource_picture.artist_name %>
   </div>
 
-  <%= render @license_group.classname.tableize + '/confirm' %>
+  <%= render @resource_picture.classname.tableize + '/confirm' %>
 
   <div class="actions">
     <%= f.submit %>
diff --git a/app/views/resource_pictures/credit.html.erb b/app/views/resource_pictures/credit.html.erb
new file mode 100644 (file)
index 0000000..0d5f816
--- /dev/null
@@ -0,0 +1 @@
+<%= render @resource_picture.credit_template %>
index 4c3d464..211045d 100644 (file)
@@ -1,10 +1,11 @@
 <h1>Listing resource_pictures</h1>
 <% @resource_pictures.each do |resource_picture| %>
+  <% @resource_picture = resource_picture %>
   <div>
-    <%= resource_picture.filename %>
+    <%= link_to resource_picture.filename, resource_picture_path(resource_picture) %>
     <img src="<%= resource_picture.url('thumbnail') -%>">
     <%= resource_picture.width %>x<%= resource_picture.height %>
     <%= resource_picture.filesize %>bytes
-    画:<%= h resource_picture.original_picture.artist.name %>
+    <%= render resource_picture.credit_template %>
   </div>
 <% end %>
index 03474a2..6e10930 100644 (file)
@@ -1,23 +1,11 @@
 <p id="notice"><%= notice %></p>
-
+<%= render @resource_picture.classname.tableize + '/credit' %>
 <p>
   <a href="<%= @resource_picture.url %>">ノーマル</a> 
   <img src="<%= @resource_picture.url -%>">
 </p>
 <p>
-  <a href="<%= @resource_picture.url :v %>">垂直反転</a> 
-  <img src="<%= @resource_picture.url :v -%>">
-</p>
-<p>
-  <a href="<%= @resource_picture.url :h %>">水平反転</a> 
-  <img src="<%= @resource_picture.url :h -%>">
-</p>
-<p>
-  <a href="<%= @resource_picture.url :vh%>">垂直水平反転</a> 
-  <img src="<%= @resource_picture.url :vh -%>">
-</p>
-<p>
   <a href="<%= @resource_picture.url :thumbnail%>">サムネ</a> 
-  <img src="<%= @resource_picture.url :thumbnail -%>">
+  <img src="<%= @resource_picture.url :full -%>">
 </p>
 <%= link_to 'Back', resource_pictures_path %>
index e69de29..9d0eb30 100644 (file)
@@ -0,0 +1,5 @@
+<% @sp = SystemPicture.find(@resource_picture.credit_data["system_picture_id"]) %>
+<%= content_tag(:a, 
+  tag(:img, :src => @sp.url, :alt => h(@license_group.caption.to_s + '[' + @license.caption.to_s + ']')), 
+  :href => @license.url )
+%>
index ce7986f..1b5316f 100644 (file)
@@ -1,7 +1,7 @@
 <div>
 <%= content_tag(:a, 
-  tag(:img, :src => @picture.license.system_picture.url, :alt => h(@picture.license_group.caption.to_s + '[' + @picture.license.caption.to_s + ']')
-  , :href => @picture.license.url )
+  tag(:img, :src => @resource_picture.license.system_picture.url, :alt => h(@resource_picture.license.license_group.caption.to_s + '[' + @resource_picture.license.caption.to_s + ']')), 
+  :href => @resource_picture.license.url )
 %>
 </div>
-著作者:<%= link_to h(@picture.artist_name), :controller => 'artists', :action => :show, :id => @picture.artist.id %>
+著作者:<%= link_to h(@resource_picture.artist_name), :controller => 'artists', :action => :show, :id => @resource_picture.artist.id %>
diff --git a/db/migrate/20120713230519_add_credit_data.rb b/db/migrate/20120713230519_add_credit_data.rb
new file mode 100644 (file)
index 0000000..f382197
--- /dev/null
@@ -0,0 +1,11 @@
+class AddCreditData < ActiveRecord::Migration
+  def up
+    add_column :resource_pictures, :classname, :string, :null => false, :limit => 50, :default => 'StandardLicense'
+    add_column :pictures, :classname, :string, :null => false, :limit => 50, :default => 'StandardLicense'
+  end
+
+  def down
+    remove__column :resource_pictures, :classname
+    remove__column :pictures, :classname
+  end
+end
index 2a1f8b3..53a448c 100644 (file)
@@ -14,11 +14,13 @@ describe PanelPicturesController do
     @op = Factory :original_picture, :artist_id => @artist.id
     @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
     @rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
+    @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id
+    @attr = {:resource_picture_id => @rp.id, :panel_id => @panel}
   end
 
   describe '一覧表示に於いて' do
     before do
-      @pp = Factory :panel_picture, :resource_picture_id => @rp.id
+      @pp = Factory :panel_picture, @attr
       sign_in @user
       PanelPicture.stub(:list).and_return([@pp, @pp, @pp])
     end
@@ -111,4 +113,89 @@ describe PanelPicturesController do
     end
   end
   
+  describe 'クレジット表示に於いて' do
+    before do
+      @pp = Factory :panel_picture, @attr
+      sign_in @user
+      Picture.stub(:show).and_return(@pp)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @pp.id
+        response.should be_success
+      end
+      it '素材モデルに単体取得を問い合わせている' do
+        ResourcePicture.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@resource_pictureにアレを取得している' do
+        get :show, :id => @pic.id
+        assigns(:resource_picture).id.should eq(@pic.id)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @pic.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @pic.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @pic.id, :format => :json
+          json = JSON.parse response.body
+          json["ext"].should match(/png/)
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @pic.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @pic.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @pic.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @pic.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+=begin
+    context '対象素材がないとき' do
+      before do
+        ResourcePicture.unstub(:show)
+      end
+      context 'html形式' do
+        it '例外404 not_foundを返す' do
+          lambda{
+            get :show, :id => 0
+          }.should raise_error(ActiveRecord::RecordNotFound)
+        end
+      end
+      context 'json形式' do
+        it '例外404 not_foundを返す' do
+          lambda{ 
+            get :show, :id => 0, :format => :json
+          }.should raise_error(ActiveRecord::RecordNotFound)
+        end
+      end
+    end
+=end
+  end
+
 end
index cabdf60..2b3f17f 100644 (file)
@@ -14,7 +14,7 @@ describe PanelsController do
   \r
   describe '一覧表示に於いて' do\r
     before do\r
-      @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
+      @panel = Factory :panel, :author_id => @author.id\r
       Panel.stub(:list).and_return([@panel, @panel, @panel])\r
       sign_in @user\r
     end\r
diff --git a/spec/controllers/pictures_controller_spec.rb b/spec/controllers/pictures_controller_spec.rb
new file mode 100644 (file)
index 0000000..d0335da
--- /dev/null
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe PicturesController do
+
+end
index 474d012..7617410 100644 (file)
@@ -144,6 +144,7 @@ Factory.define :resource_picture, :class => ResourcePicture do |rp|
   rp.filesize 100000
   rp.artist_id 1
   rp.license_id 1
+  rp.classname 'StandardLicense'
   rp.original_picture_id 1
 end
 
@@ -157,6 +158,7 @@ Factory.define :picture, :class => Picture do |p|
   p.artist_id 1
   p.license_id 1
   p.artist_name 'no name'
+  p.classname 'StandardLicense'
   p.credit ''
   p.settings ''
 end
diff --git a/spec/helpers/pictures_helper_spec.rb b/spec/helpers/pictures_helper_spec.rb
new file mode 100644 (file)
index 0000000..d0a47d3
--- /dev/null
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the PicturesHelper. For example:
+#
+# describe PicturesHelper do
+#   describe "string concat" do
+#     it "concats two strings with spaces" do
+#       helper.concat_strings("this","that").should == "this that"
+#     end
+#   end
+# end
+describe PicturesHelper do
+  pending "add some examples to (or delete) #{__FILE__}"
+end
index 3f593f9..e393f67 100644 (file)
@@ -37,25 +37,8 @@ describe PanelPicture do
         @pp.panel_id = 'a'
         @pp.should_not be_valid
       end
-    end
-    context 'resource_picture_idを検証するとき' do
-      before do
-        @pp = Factory.build :panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id
-      end
-      it 'テストデータの確認' do
-        @pp.resource_picture_id = @rp.id
-        @pp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @pp.resource_picture_id = nil
-        @pp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @pp.resource_picture_id = 'a'
-        @pp.should_not be_valid
-      end
-      it '存在するフキダシテンプレートでなければ失敗する' do
-        @pp.resource_picture_id = 0
+      it '存在するコマでなければ失敗する' do
+        @pp.panel_id = 0
         @pp.should_not be_valid
       end
     end
index bb5bf3d..fbf287b 100644 (file)
@@ -215,6 +215,23 @@ describe Picture do
         @p.should_not be_valid
       end
     end
+    context 'classnameを検証するとき' do
+      before do
+        @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
+      end
+      it 'テストデータの確認' do
+        @p.classname = 'a'*50
+        @p.should be_valid
+      end
+      it 'nullなら失敗する' do
+        @p.classname = ''
+        @p.should_not be_valid
+      end
+      it '51文字以上なら失敗する' do
+        @p.classname = 'a'*51
+        @p.should_not be_valid
+      end
+    end
     context 'creditを検証するとき' do
       before do
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
@@ -266,27 +283,28 @@ describe Picture do
     end
   end
   describe '素材からのコピーデータセットに於いて' do
-    before do\r
+    before do
       @op = Factory :original_picture, :artist_id => @artist.id
       attr = {:ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, 
         :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, 
-        :artist_name => 'tester', :credit => {:title => 'cap'}.to_json.to_s, :settings => {:set => 1}.to_json.to_s}\r
+        :artist_name => 'tester', :classname => 'Tester', :credit => {:title => 'cap'}.to_json.to_s, :settings => {:set => 1}.to_json.to_s}
       @rp = Factory.build :resource_picture, attr
       @p = Factory.build :picture
     end
     it '素材オブジェクトから属性を取り出して対象実素材にセットしている' do
-      res = @p.copy_data(@rp)\r
-      @p.ext.should eq 'jpeg'\r
-      @p.width.should eq 264\r
-      @p.height.should eq 265\r
-      @p.filesize.should eq 266\r
-      @p.artist_id.should eq @artist.id\r
-      @p.license_id.should eq @license.id\r
-      @p.original_picture_id.should eq @op.id\r
-      @p.artist_name.should eq 'tester'\r
-      @p.credit.should match /title/\r
-      @p.settings.should match /set/\r
-    end\r
+      res = @p.copy_data(@rp)
+      @p.ext.should eq 'jpeg'
+      @p.width.should eq 264
+      @p.height.should eq 265
+      @p.filesize.should eq 266
+      @p.artist_id.should eq @artist.id
+      @p.license_id.should eq @license.id
+      @p.original_picture_id.should eq @op.id
+      @p.artist_name.should eq 'tester'
+      @p.classname.should eq 'Tester'
+      @p.credit.should match /title/
+      @p.settings.should match /set/
+    end
   end
   
   describe '作成に於いて' do
@@ -307,152 +325,152 @@ describe Picture do
       before do
         #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
         #それで外部のメソッド呼び出しだけに着目してテストする。
-        Picture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
-        @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
+        Picture.any_instance.stub(:save).with(any_args).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
+        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
+        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために
+        @gifmgk = GifMgk.new      #パラメータを二種類用意する。
         Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it '最新Revisionを取得している' do
         Picture.any_instance.should_receive(:new_revision).with(any_args).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
+        res = @p.store(Mgk.new)
+      end
       it '自身を保存している' do
         Picture.any_instance.should_receive(:save).with(any_args).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
-      it '画像ファイルの作成機能で画像を保存している' do\r
+        res = @p.store(Mgk.new)
+      end
+      it '画像ファイルの作成機能で画像を保存している' do
         mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
         Picture.any_instance.should_receive(:store_picture).with(mgk).exactly(1)
-        res = @p.store(mgk)\r
-      end\r
+        res = @p.store(mgk)
+      end
       it '自身にgifフォーマット変換対象かを問い合わせている' do
         Picture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
+        res = @p.store(Mgk.new)
+      end
       it '自身にGifフォーマット変換を依頼している' do
         Picture.should_receive(:png_to_gif).with(any_args).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
-      it '画像ファイルの作成機能でgif画像を保存している' do\r
+        res = @p.store(Mgk.new)
+      end
+      it '画像ファイルの作成機能でgif画像を保存している' do
         #二回目の保存はgif変換の結果を渡す。
         Picture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
+        res = @p.store(Mgk.new)
+      end
     end
     context 'つつがなく終わるとき' do
       before do
         #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-#        Picture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
-        @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
+#        Picture.any_instance.stub(:save).with(any_args).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
+        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
+        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために
+        @gifmgk = GifMgk.new      #パラメータを二種類用意する。
         Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
         @p = Factory.build :picture, :revision => nil, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Trueを返す' do
-        res = @p.store(Mgk.new)\r
-        res.should be_true\r
-      end\r
+        res = @p.store(Mgk.new)
+        res.should be_true
+      end
       it 'Revisionに最新Revisionセット' do
-        res = @p.store(Mgk.new)\r
-        @p.revision.should eq 1\r
-      end\r
-      it '自身が保存されている' do\r
+        res = @p.store(Mgk.new)
+        @p.revision.should eq 1
+      end
+      it '自身が保存されている' do
         lambda {
-          res = @p.store(Mgk.new)\r
-        }.should change Picture, :count\r
-      end\r
+          res = @p.store(Mgk.new)
+        }.should change Picture, :count
+      end
     end
     context 'gif変換なしで、つつがなく終わるとき' do
       before do
         #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        Picture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
+        Picture.any_instance.stub(:save).with(any_args).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
+        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(false)
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Trueを返す' do
-        res = @p.store(Mgk.new)\r
-        res.should be_true\r
-      end\r
+        res = @p.store(Mgk.new)
+        res.should be_true
+      end
       it 'gif保存は呼ばれていない' do
-        #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。\r
+        #二回目の画像作成が呼び出されないで1回こっきりならgif保存は呼ばれていないんだろう。
         Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
+        res = @p.store(Mgk.new)
+      end
     end
     #以下から例外ケース。処理先頭から失敗させていく
     context '自身の保存に失敗したとき' do
       before do
-        Picture.any_instance.stub(:save).with(any_args).and_return(false)\r
+        Picture.any_instance.stub(:save).with(any_args).and_return(false)
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Falseを返す' do
-        res = @p.store(Mgk.new)\r
-        res.should be_false\r
-      end\r
+        res = @p.store(Mgk.new)
+        res.should be_false
+      end
       it '更新されていない' do
         @p.store(Mgk.new)
-        @p.should be_a_new Picture\r
+        @p.should be_a_new Picture
       end
     end
     context '画像の保存に失敗したとき' do
       before do
-        Picture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
+        Picture.any_instance.stub(:save).with(any_args).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(any_args).and_return(false)
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Falseを返す' do
-        res = @p.store(Mgk.new)\r
-        res.should be_false\r
-      end\r
-      it 'gif変換判定は呼ばれていない' do\r
+        res = @p.store(Mgk.new)
+        res.should be_false
+      end
+      it 'gif変換判定は呼ばれていない' do
         Picture.any_instance.should_not_receive(:to_gif?).with(any_args)
-        res = @p.store(Mgk.new)\r
-      end\r
+        res = @p.store(Mgk.new)
+      end
     end
     context 'gif変換に失敗したとき' do
       before do
-        Picture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
+        Picture.any_instance.stub(:save).with(any_args).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(any_args).and_return(true)
+        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
         Picture.stub(:png_to_gif).with(any_args).and_return(false)
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Falseを返す' do
-        res = @p.store(Mgk.new)\r
-        res.should be_false\r
-      end\r
-      it 'gif画像の保存は呼ばれていない' do\r
-        #本画像の保存があるので、一度は呼ばれる\r
+        res = @p.store(Mgk.new)
+        res.should be_false
+      end
+      it 'gif画像の保存は呼ばれていない' do
+        #本画像の保存があるので、一度は呼ばれる
         Picture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
-        res = @p.store(Mgk.new)\r
-      end\r
+        res = @p.store(Mgk.new)
+      end
     end
     context 'gif画像の保存に失敗したとき' do
-      before do\r
+      before do
         @mgk = Mgk.new
-        Picture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        Picture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
-        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
-        @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
+        Picture.any_instance.stub(:save).with(any_args).and_return(true)
+        Picture.any_instance.stub(:store_picture).with(@mgk).and_return(true)
+        Picture.any_instance.stub(:to_gif?).with(any_args).and_return(true)
+        class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために
+        @gifmgk = GifMgk.new      #パラメータを二種類用意する。
         Picture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-        Picture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
+        Picture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)
         @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
       end
       it 'Falseを返す' do
-        res = @p.store(@mgk)\r
-        res.should be_false\r
-      end\r
+        res = @p.store(@mgk)
+        res.should be_false
+      end
     end
-  end\r
+  end
   
-  describe '反転画像の保存先に於いて' do\r
+  describe '反転画像の保存先に於いて' do
     before do
       @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id
     end
@@ -460,30 +478,30 @@ describe Picture do
       it 'ベースディレクトリだけを返す' do
         Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(-1)
         r = @p.subdirs
-        r.should have(1).item \r
-      end\r
+        r.should have(1).item 
+      end
       it 'ベースディレクトリだけを返す' do
         Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(-1)
         r = @p.subdirs
-        r.first.should eq ''\r
-      end\r
-    end\r
+        r.first.should eq ''
+      end
+    end
     context '許可のとき' do
       it 'ベースディレクトリと反転3種を返す' do
         Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(1)
         r = @p.subdirs
-        r.should have(4).item \r
-      end\r
+        r.should have(4).item 
+      end
       it 'ベースディレクトリと反転3種を返す' do
         Picture.any_instance.should_receive(:flag_reverse).with(any_args).and_return(1)
         r = @p.subdirs
-        r.last.should eq 'vh'\r
-      end\r
-    end\r
-  end\r
+        r.last.should eq 'vh'
+      end
+    end
+  end
   
-  describe '画像ファイルの作成に於いて' do\r
-    #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。\r
+  describe '画像ファイルの作成に於いて' do
+    #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。
     before do
       #RMagickのスタブをおいておく
       class Mgk ; class Image ; end ; end
@@ -497,7 +515,7 @@ describe Picture do
       #原画ファイル削除だけは必ず成功するものとしておく
       PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
       
-      Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])\r
+      Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])
       Picture.any_instance.stub(:h).with(any_args).and_return('data')
       Picture.any_instance.stub(:v).with(any_args).and_return('data')
       Picture.any_instance.stub(:vh).with(any_args).and_return('data')
@@ -508,57 +526,57 @@ describe Picture do
         #すべての処理を正常パターンで通過させ、保存機能をチェックする。
         PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
       end
-      it '画像ファイルの保存が4回呼ばれる' do\r
+      it '画像ファイルの保存が4回呼ばれる' do
         PictureIO.picture_io.should_receive(:put).with(any_args).exactly(4)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '画像ファイルのベースへの保存が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '画像ファイルのベースへの保存が1回呼ばれる' do
         PictureIO.picture_io.should_receive(:put).with('data', @p.filename, '').exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '画像ファイルの垂直反転への保存が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '画像ファイルの垂直反転への保存が1回呼ばれる' do
         PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'v').exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '画像ファイルの水平反転への保存が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '画像ファイルの水平反転への保存が1回呼ばれる' do
         PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'h').exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '画像ファイルの垂直水平反転への保存が1回呼ばれる' do
         PictureIO.picture_io.should_receive(:put).with('data', @p.filename, 'vh').exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '垂直反転が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '垂直反転が1回呼ばれる' do
         Picture.any_instance.should_receive(:v).with(any_args).exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '水平反転が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '水平反転が1回呼ばれる' do
         Picture.any_instance.should_receive(:h).with(any_args).exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
-      it '垂直水平反転が1回呼ばれる' do\r
+        res = @p.store_picture(Mgk.new)
+      end
+      it '垂直水平反転が1回呼ばれる' do
         Picture.any_instance.should_receive(:vh).with(any_args).exactly(1)
-        res = @p.store_picture(Mgk.new)\r
-      end\r
+        res = @p.store_picture(Mgk.new)
+      end
     end
     context 'つつがなく終わるとき' do
       before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
         PictureIO.picture_io.stub(:put).with(any_args).and_return(true)
       end
       it 'Trueを返す' do
-        res = @p.store_picture(Mgk.new)\r
-        res.should be_true\r
-      end\r
+        res = @p.store_picture(Mgk.new)
+        res.should be_true
+      end
     end
     context '例外ケース' do
       before do
         PictureIO.picture_io.stub(:put).with(any_args).and_return(false)
       end
       it 'Falseを返す' do
-        res = @p.store_picture(Mgk.new)\r
-        res.should be_false\r
-      end\r
+        res = @p.store_picture(Mgk.new)
+        res.should be_false
+      end
     end
     
   end
@@ -721,5 +739,16 @@ describe Picture do
       end
     end
   end
-\r
+
+  describe 'クレジットデータに於いて' do
+    before do
+      @op = Factory :original_picture, :artist_id => @artist.id
+      @p = Factory.build :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id, :credit => '{"system_picture_id": 2}'
+    end
+    it 'system_picture_idが入っている' do
+      res = @p.credit_data
+      res["system_picture_id"].should eq 2
+    end
+  end
+  
 end
index 820a630..35ef376 100644 (file)
 # -*- encoding: utf-8 -*-\r
-require 'spec_helper'
-
-describe ResourcePicture do
-  before do
-    Factory :admin
-    @user = Factory( :user_yas)
-    @author = @user.author
+#素材\r
+require 'spec_helper'\r
+\r
+describe ResourcePicture do\r
+  before do\r
+    Factory :admin\r
+    @user = Factory( :user_yas)\r
+    @author = @user.author\r
     @artist = Factory :artist_yas, :author_id => @author.id\r
-    @other_user = Factory( :user_yas)
-    @other_author = @other_user.author
-    @other_artist = Factory :artist_yas, :author_id => @other_author.id
-    @sp = Factory :system_picture
-    @lg = Factory :license_group
-    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @other_user = Factory( :user_yas)\r
+    @other_author = @other_user.author\r
+    @other_artist = Factory :artist_yas, :author_id => @other_author.id\r
+    @sp = Factory :system_picture\r
+    @lg = Factory :license_group\r
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
     @original_picture = Factory :original_picture, :artist_id => @artist.id\r
-    
-    class Mgk ; class Image ; end ; end
-    Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
-    Mgk.any_instance.stub(:format).with(any_args).and_return('png')
-    Mgk.any_instance.stub(:format=).with(any_args)
-    Mgk.any_instance.stub(:rows).with(any_args).and_return(200)
-    Mgk.any_instance.stub(:columns).with(any_args).and_return(100)
-    Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)
-    Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')
-    #原画ファイル削除だけは必ず成功するものとしておく
-    PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)
+    \r
+    class Mgk ; class Image ; end ; end\r
+    Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
+    Mgk.any_instance.stub(:format).with(any_args).and_return('png')\r
+    Mgk.any_instance.stub(:format=).with(any_args)\r
+    Mgk.any_instance.stub(:rows).with(any_args).and_return(200)\r
+    Mgk.any_instance.stub(:columns).with(any_args).and_return(100)\r
+    Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)\r
+    Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')\r
+    #原画ファイル削除だけは必ず成功するものとしておく\r
+    PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)\r
     Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])\r
-    Picture.any_instance.stub(:h).with(any_args).and_return('data')
-    Picture.any_instance.stub(:v).with(any_args).and_return('data')
-    Picture.any_instance.stub(:vh).with(any_args).and_return('data')
+    Picture.any_instance.stub(:h).with(any_args).and_return('data')\r
+    Picture.any_instance.stub(:v).with(any_args).and_return('data')\r
+    Picture.any_instance.stub(:vh).with(any_args).and_return('data')\r
+  end\r
+  \r
+  describe '検証に於いて' do\r
+    before do\r
+      @p = Factory :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    \r
+    it 'オーソドックスなデータなら通る' do\r
+      @rp.should be_valid\r
+    end\r
+    \r
+    context 'extを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.ext = 'jpeg'\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.ext = ''\r
+        @rp.should_not be_valid\r
+      end\r
+      it '5文字以上なら失敗する' do\r
+        @rp.ext = 'a'*5\r
+        @rp.should_not be_valid\r
+      end\r
+      it 'png,gif,jpeg以外なら失敗する' do\r
+        @rp.ext = 'bmp'\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'widthを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.width = 1\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.width = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.width = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '0なら失敗する' do\r
+        @rp.width = '0'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '負でも失敗する' do\r
+        @rp.width = -1\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'heightを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.height = '1'\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.height = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.height = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '0なら失敗する' do\r
+        @rp.height = '0'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '負でも失敗する' do\r
+        @rp.height = -1\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'filesizeを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.filesize = '1'\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.filesize = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.filesize = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '負なら失敗する' do\r
+        @rp.filesize = '-1'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '2MB以上なら失敗する' do\r
+        @rp.filesize = 2000000+1\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'artist_idを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.artist_id = @artist.id\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.artist_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.artist_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する絵師でなければ失敗する' do\r
+        @rp.artist_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'license_idを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.license_id = @license.id\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.license_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.license_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する絵師でなければ失敗する' do\r
+        @rp.license_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'original_picture_idを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.original_picture_id = @original_picture.id\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.original_picture_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.original_picture_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する原画でなければ失敗する' do\r
+        @rp.original_picture_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'artist_nameを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.artist_name = 'a'\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.artist_name = nil\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'classnameを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.classname = 'a'*50\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.classname = ''\r
+        @rp.should_not be_valid\r
+      end\r
+      it '51文字以上なら失敗する' do\r
+        @rp.classname = 'a'*51\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+    context 'creditを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.credit = 'a'\r
+        @rp.should be_valid\r
+      end\r
+    end\r
+    context 'settingsを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.settings = 'a'\r
+        @rp.should be_valid\r
+      end\r
+    end\r
+    context 'picture_idを検証するとき' do\r
+      it 'テストデータの確認' do\r
+        @rp.picture_id = @p.id\r
+        @rp.should be_valid\r
+      end\r
+      it 'nullなら失敗する' do\r
+        @rp.picture_id = nil\r
+        @rp.should_not be_valid\r
+      end\r
+      it '数値でなければ失敗する' do\r
+        @rp.picture_id = 'a'\r
+        @rp.should_not be_valid\r
+      end\r
+      it '存在する実素材でなければ失敗する' do\r
+        @rp.picture_id = 0\r
+        @rp.should_not be_valid\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe 'データ補充に於いて' do\r
+    before do\r
+    end\r
+    \r
+  end\r
+  \r
+  describe '単体取得に於いて' do\r
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    it '指定の素材を返す' do\r
+      pic = ResourcePicture.show @rp.id\r
+      pic.should eq @rp\r
+    end\r
+    context '関連テーブルオプションがないとき' do\r
+      it 'ライセンスと絵師を含んでいる' do\r
+        r = ResourcePicture.show_include_opt\r
+        r.should eq [:license, :artist]\r
+      end\r
+    end\r
+    context '関連テーブルオプションで原画を含ませたとき' do\r
+      it 'ライセンスと絵師と原画データを含んでいる' do\r
+        r = ResourcePicture.show_include_opt(:include => :original_picture)\r
+        r.should eq [:license, :artist, :original_picture]\r
+      end\r
+    end\r
+    context '存在しない素材を開こうとしたとき' do\r
+      it '404RecordNotFound例外を返す' do\r
+        lambda{\r
+          pic = ResourcePicture.show 0\r
+        }.should raise_error(ActiveRecord::RecordNotFound)\r
+      end\r
+    end\r
+  end\r
+  describe 'json単体出力オプションに於いて' do\r
+    it 'includeキーがライセンスと絵師を含んでいる' do\r
+      r = ResourcePicture.show_json_include_opt\r
+      r[:include].should eq [:license, :artist]\r
+    end\r
   end\r
-  
-  describe '検証に於いて' do
+  describe '一覧取得に於いて' do\r
     before do\r
-      @p = Factory :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = Factory.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id
-    end
-    
-    it 'オーソドックスなデータなら通る' do
-      @rp.should be_valid
-    end
-    
-    context 'extを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.ext = 'jpeg'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.ext = ''
-        @rp.should_not be_valid
-      end
-      it '5文字以上なら失敗する' do
-        @rp.ext = 'a'*5
-        @rp.should_not be_valid
-      end
-      it 'png,gif,jpeg以外なら失敗する' do
-        @rp.ext = 'bmp'
-        @rp.should_not be_valid
-      end
-    end
-    context 'widthを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.width = 1
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.width = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.width = 'a'
-        @rp.should_not be_valid
-      end
-      it '0なら失敗する' do
-        @rp.width = '0'
-        @rp.should_not be_valid
-      end
-      it '負でも失敗する' do
-        @rp.width = -1
-        @rp.should_not be_valid
-      end
-    end
-    context 'heightを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.height = '1'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.height = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.height = 'a'
-        @rp.should_not be_valid
-      end
-      it '0なら失敗する' do
-        @rp.height = '0'
-        @rp.should_not be_valid
-      end
-      it '負でも失敗する' do
-        @rp.height = -1
-        @rp.should_not be_valid
-      end
-    end
-    context 'filesizeを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.filesize = '1'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.filesize = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.filesize = 'a'
-        @rp.should_not be_valid
-      end
-      it '負なら失敗する' do
-        @rp.filesize = '-1'
-        @rp.should_not be_valid
-      end
-      it '2MB以上なら失敗する' do
-        @rp.filesize = 2000000+1
-        @rp.should_not be_valid
-      end
-    end
-    context 'artist_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.artist_id = @artist.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.artist_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.artist_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する絵師でなければ失敗する' do
-        @rp.artist_id = 0
-        @rp.should_not be_valid
-      end
-    end
-    context 'license_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.license_id = @license.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.license_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.license_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する絵師でなければ失敗する' do
-        @rp.license_id = 0
-        @rp.should_not be_valid
-      end
-    end
-    context 'original_picture_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.original_picture_id = @original_picture.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.original_picture_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.original_picture_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する原画でなければ失敗する' do
-        @rp.original_picture_id = 0
-        @rp.should_not be_valid
-      end
-    end
-    context 'artist_nameを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.artist_name = 'a'
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.artist_name = nil
-        @rp.should_not be_valid
-      end
-    end
-    context 'creditを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.credit = 'a'
-        @rp.should be_valid
-      end
-    end
-    context 'settingsを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.settings = 'a'
-        @rp.should be_valid
-      end
-    end
-    context 'picture_idを検証するとき' do
-      it 'テストデータの確認' do
-        @rp.picture_id = @p.id
-        @rp.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @rp.picture_id = nil
-        @rp.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @rp.picture_id = 'a'
-        @rp.should_not be_valid
-      end
-      it '存在する実素材でなければ失敗する' do
-        @rp.picture_id = 0
-        @rp.should_not be_valid
-      end
-    end
-  end
-  
-  describe 'データ補充に於いて' do
-    before do
-    end
-    
-  end
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    context 'page補正について' do\r
+      it '文字列から数値に変換される' do\r
+        ResourcePicture.page('8').should eq 8\r
+      end\r
+      it 'nilの場合は1になる' do\r
+        ResourcePicture.page().should eq 1\r
+      end\r
+      it '0以下の場合は1になる' do\r
+        ResourcePicture.page('0').should eq 1\r
+      end\r
+    end\r
+    context 'page_size補正について' do\r
+      it '文字列から数値に変換される' do\r
+        ResourcePicture.page_size('7').should eq 7\r
+      end\r
+      it 'nilの場合はResourcePicture.default_page_sizeになる' do\r
+        ResourcePicture.page_size().should eq ResourcePicture.default_page_size\r
+      end\r
+      it '0以下の場合はResourcePicture.default_page_sizeになる' do\r
+        ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size\r
+      end\r
+      it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do\r
+        ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size\r
+      end\r
+    end\r
+    it 'リストを返す' do\r
+      pic = ResourcePicture.list\r
+      pic.should eq [@rp]\r
+    end\r
+    it '時系列で並んでいる' do\r
+      nop = Factory :original_picture, :artist_id => @artist.id\r
+      nrp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+      pic = ResourcePicture.list\r
+      pic.should eq [nrp, @rp]\r
+    end\r
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+      before do\r
+        nop2 = Factory :original_picture, :artist_id => @artist.id\r
+        @nrp2 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+        nop3 = Factory :original_picture, :artist_id => @artist.id\r
+        @nrp3 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+        nop4 = Factory :original_picture, :artist_id => @artist.id\r
+        @nrp4 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+        nop5 = Factory :original_picture, :artist_id => @artist.id\r
+        @nrp5 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
+        ResourcePicture.stub(:default_page_size).and_return(2)\r
+      end\r
+      it '通常は2件を返す' do\r
+        pic = ResourcePicture.list\r
+        pic.should have(2).items \r
+      end\r
+      it 'page=1なら末尾2件を返す' do\r
+        #時系列で並んでいる\r
+        pic = ResourcePicture.list({}, 1)\r
+        pic.should eq [@nrp5, @nrp4]\r
+      end\r
+      it 'page=2なら中間2件を返す' do\r
+        pic = ResourcePicture.list({}, 2)\r
+        pic.should eq [@nrp3, @nrp2]\r
+      end\r
+      it 'page=3なら先頭1件を返す' do\r
+        pic = ResourcePicture.list({}, 3)\r
+        pic.should eq [@rp]\r
+      end\r
+    end\r
+  end\r
+  describe 'json一覧出力オプションに於いて' do\r
+    it 'includeキーがライセンスと絵師を含んでいる' do\r
+      r = ResourcePicture.list_json_opt\r
+      r[:include].should eq [:license, :artist]\r
+    end\r
+  end\r
   \r
-  describe '単体取得に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
-    end
-    it '指定の素材を返す' do
-      pic = ResourcePicture.show @rp.id
-      pic.should eq @rp
-    end
-    context '関連テーブルオプションがないとき' do
-      it 'ライセンスと絵師を含んでいる' do
-        r = ResourcePicture.show_include_opt
-        r.should eq [:license, :artist]
-      end
-    end
-    context '関連テーブルオプションで原画を含ませたとき' do
-      it 'ライセンスと絵師と原画データを含んでいる' do
-        r = ResourcePicture.show_include_opt(:include => :original_picture)
-        r.should eq [:license, :artist, :original_picture]
-      end
-    end
-    context '存在しない素材を開こうとしたとき' do
-      it '404RecordNotFound例外を返す' do
-        lambda{
-          pic = ResourcePicture.show 0
-        }.should raise_error(ActiveRecord::RecordNotFound)
-      end
-    end
-  end
-  describe 'json単体出力オプションに於いて' do
-    it 'includeキーがライセンスと絵師を含んでいる' do
-      r = ResourcePicture.show_json_include_opt
-      r[:include].should eq [:license, :artist]
-    end
-  end
-  describe '一覧取得に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      @rp = Factory :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id
-    end
-    context 'page補正について' do
-      it '文字列から数値に変換される' do
-        ResourcePicture.page('8').should eq 8
-      end
-      it 'nilの場合は1になる' do
-        ResourcePicture.page().should eq 1
-      end
-      it '0以下の場合は1になる' do
-        ResourcePicture.page('0').should eq 1
-      end
-    end
-    context 'page_size補正について' do
-      it '文字列から数値に変換される' do
-        ResourcePicture.page_size('7').should eq 7
-      end
-      it 'nilの場合はResourcePicture.default_page_sizeになる' do
-        ResourcePicture.page_size().should eq ResourcePicture.default_page_size
-      end
-      it '0以下の場合はResourcePicture.default_page_sizeになる' do
-        ResourcePicture.page_size('0').should eq ResourcePicture.default_page_size
-      end
-      it 'ResourcePicture.max_page_sizeを超えた場合はResourcePicture.max_page_sizeになる' do
-        ResourcePicture.page_size('1000').should eq ResourcePicture.max_page_size
-      end
-    end
-    it 'リストを返す' do
-      pic = ResourcePicture.list
-      pic.should eq [@rp]
-    end
-    it '時系列で並んでいる' do
-      nop = Factory :original_picture, :artist_id => @artist.id
-      nrp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100
-      pic = ResourcePicture.list
-      pic.should eq [nrp, @rp]
-    end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        nop2 = Factory :original_picture, :artist_id => @artist.id
-        @nrp2 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100
-        nop3 = Factory :original_picture, :artist_id => @artist.id
-        @nrp3 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200
-        nop4 = Factory :original_picture, :artist_id => @artist.id
-        @nrp4 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300
-        nop5 = Factory :original_picture, :artist_id => @artist.id
-        @nrp5 = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400
-        ResourcePicture.stub(:default_page_size).and_return(2)
-      end
-      it '通常は2件を返す' do
-        pic = ResourcePicture.list
-        pic.should have(2).items 
-      end
-      it 'page=1なら末尾2件を返す' do
-        #時系列で並んでいる
-        pic = ResourcePicture.list({}, 1)
-        pic.should eq [@nrp5, @nrp4]
-      end
-      it 'page=2なら中間2件を返す' do
-        pic = ResourcePicture.list({}, 2)
-        pic.should eq [@nrp3, @nrp2]
-      end
-      it 'page=3なら先頭1件を返す' do
-        pic = ResourcePicture.list({}, 3)
-        pic.should eq [@rp]
-      end
-    end
-  end
-  describe 'json一覧出力オプションに於いて' do
-    it 'includeキーがライセンスと絵師を含んでいる' do
-      r = ResourcePicture.list_json_opt
-      r[:include].should eq [:license, :artist]
-    end
+  describe 'サイズの調整に於いて' do\r
+    before do\r
+    end\r
+    \r
+    it 'サイズに収まるときはそのまま使う' do\r
+      ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]\r
+    end\r
+    it '小さくても拡大しない' do\r
+      ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]\r
+    end\r
+    it '縦長のときは縦に合わせて縮小' do\r
+      ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]\r
+    end\r
+    it '横長のときは横に合わせて縮小' do\r
+      ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]\r
+    end\r
   end\r
-  
-  describe 'サイズの調整に於いて' do
-    before do
-    end
-    
-    it 'サイズに収まるときはそのまま使う' do
-      ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]
-    end
-    it '小さくても拡大しない' do
-      ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]
-    end
-    it '縦長のときは縦に合わせて縮小' do
-      ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]
-    end
-    it '横長のときは横に合わせて縮小' do
-      ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]
-    end
-  end
   \r
-  describe 'フォーマット変換対象判定に於いて' do
-    before do
+  describe 'フォーマット変換対象判定に於いて' do\r
+    before do\r
       @rp = Factory.build :resource_picture, \r
-        :artist_id => @artist.id, :license_id => @license.id
-    end
+        :artist_id => @artist.id, :license_id => @license.id\r
+    end\r
     context '変換するケース' do\r
       it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
-        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
+        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
         @rp.ext = 'png'\r
-        @rp.to_gif?.should be_true
-      end
-    end
-    context '変換しないケース' do
+        @rp.to_gif?.should be_true\r
+      end\r
+    end\r
+    context '変換しないケース' do\r
       it '画像フォーマットがでない' do\r
-        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)
+        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
         @rp.ext = 'gif'\r
-        @rp.to_gif?.should be_false
-      end
+        @rp.to_gif?.should be_false\r
+      end\r
       it '変換禁止フラグが無効' do\r
-        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)
+        ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)\r
         @rp.ext = 'png'\r
-        @rp.to_gif?.should be_false
-      end
-    end
-  end
-  
-  describe 'Gifフォーマット変換に於いて' do
-    before do
-      Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])
-    end
-    context 'つつがなく終わるとき' do
-      it 'Mgkオブジェクトが返る' do
+        @rp.to_gif?.should be_false\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe 'Gifフォーマット変換に於いて' do\r
+    before do\r
+      Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'Mgkオブジェクトが返る' do\r
         mgk = ResourcePicture.png_to_gif('mgkbin')\r
-        mgk.is_a?(Mgk).should be_true
-      end
+        mgk.is_a?(Mgk).should be_true\r
+      end\r
       it 'Mgkオブジェクトはgif変換されている' do\r
-        #スタブばかりで変換できないので代入されているかでチェックする
-        Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)
+        #スタブばかりで変換できないので代入されているかでチェックする\r
+        Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)\r
         ResourcePicture.png_to_gif('mgkbin')\r
-      end
-    end
-    context 'RMagick変換が失敗したとき' do
-      before do
-        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
-      end
-      it 'falseを返す' do
+      end\r
+    end\r
+    context 'RMagick変換が失敗したとき' do\r
+      before do\r
+        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
+      end\r
+      it 'falseを返す' do\r
         res = ResourcePicture.png_to_gif('mgkbin')\r
         res.should be_false\r
-      end
-    end
-  end
-  
-  describe '原画からのコピーデータセットに於いて' do
+      end\r
+    end\r
+  end\r
+  \r
+  describe '原画からのコピーデータセットに於いて' do\r
     before do\r
       @op = Factory :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
-        :artist_id => @artist.id
+        :artist_id => @artist.id\r
       @rp = Factory.build :resource_picture, \r
-        :artist_id => @artist.id
-    end
-    it '原画オブジェクトから属性を取り出して対象素材にセットしている' do
+        :artist_id => @artist.id\r
+    end\r
+    it '原画オブジェクトから属性を取り出して対象素材にセットしている' do\r
       res = @rp.copy_data(@op)\r
       @rp.ext.should eq 'jpeg'\r
       @rp.width.should eq 264\r
@@ -427,95 +442,95 @@ describe ResourcePicture do
       @rp.filesize.should eq 266\r
       @rp.artist_id.should eq @artist.id\r
     end\r
-  end
-  
-  describe 'RMagick変換に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+  end\r
+  \r
+  describe 'RMagick変換に於いて' do\r
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-    end
-    context 'つつがなく終わるとき' do
-      it '画像データをオブジェクト化している' do
-        Magick::Image.stub(:from_blob).and_return(['mgkobj'])
-        @rp.data_to_mgk('mgkbin').should eq 'mgkobj'
-      end
-    end
-    context '失敗するとき' do
-      it 'Falseを返す' do
-        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
-        @rp.data_to_mgk('mgkbin').should be_false
-      end
-      it '全体エラーがセットされている' do
-        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')
-        lambda {
-          @rp.data_to_mgk('mgkbin')
-        }.should change(@rp.errors[:base], :count)
-      end
-    end
-  end
-  describe '画像オブジェクトの取得に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+      @rp = Factory.build :resource_picture, attr\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '画像データをオブジェクト化している' do\r
+        Magick::Image.stub(:from_blob).and_return(['mgkobj'])\r
+        @rp.data_to_mgk('mgkbin').should eq 'mgkobj'\r
+      end\r
+    end\r
+    context '失敗するとき' do\r
+      it 'Falseを返す' do\r
+        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
+        @rp.data_to_mgk('mgkbin').should be_false\r
+      end\r
+      it '全体エラーがセットされている' do\r
+        Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
+        lambda {\r
+          @rp.data_to_mgk('mgkbin')\r
+        }.should change(@rp.errors[:base], :count)\r
+      end\r
+    end\r
+  end\r
+  describe '画像オブジェクトの取得に於いて' do\r
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-    end
-    context '事前チェック' do
-      before do
+      @rp = Factory.build :resource_picture, attr\r
+    end\r
+    context '事前チェック' do\r
+      before do\r
         OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
-        ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
-      end
-      it '原画から画像データを取得している' do
-        OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)
+        ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)\r
+      end\r
+      it '原画から画像データを取得している' do\r
+        OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)\r
         res = @rp.op_mgk\r
       end\r
-      it '素材に原画データのRMagick変換を依頼している' do
-        ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)
+      it '素材に原画データのRMagick変換を依頼している' do\r
+        ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)\r
         res = @rp.op_mgk\r
       end\r
     end\r
-    context 'つつがなく終わるとき' do
+    context 'つつがなく終わるとき' do\r
       #原画から画像データを取得する。\r
       #素材に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
-      before do
+      before do\r
         @mgk = Mgk.new\r
         OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
-        ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)
-      end
-      it '画像オブジェクトを返す' do
+        ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)\r
+      end\r
+      it '画像オブジェクトを返す' do\r
         res = @rp.op_mgk\r
         res.should eq @mgk\r
       end\r
     end\r
-  end
-  
-  describe '新規実素材の取得に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+  end\r
+  \r
+  describe '新規実素材の取得に於いて' do\r
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', \r
         :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-      @mgk = Mgk.new
-    end
-    context '事前チェック' do
-      before do
+      @rp = Factory.build :resource_picture, attr\r
+      @mgk = Mgk.new\r
+    end\r
+    context '事前チェック' do\r
+      before do\r
         Picture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
         Picture.any_instance.stub(:store).with(any_args).and_return(true)\r
-      end
-      it '実素材に原画からのコピーデータを依頼している' do
-        Picture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)
+      end\r
+      it '実素材に原画からのコピーデータを依頼している' do\r
+        Picture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)\r
         res = @rp.new_picture @mgk\r
       end\r
-      it '実素材を保存している' do
-        Picture.any_instance.should_receive(:store).with(any_args).exactly(1)
+      it '実素材を保存している' do\r
+        Picture.any_instance.should_receive(:store).with(any_args).exactly(1)\r
         res = @rp.new_picture @mgk\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      it '実素材に原画からのコピーデータをセットしている' do
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '実素材に原画からのコピーデータをセットしている' do\r
         res = @rp.new_picture @mgk\r
         @rp.ext.should eq @op.ext\r
         @rp.width.should eq @op.width\r
@@ -524,321 +539,334 @@ describe ResourcePicture do
         @rp.artist_id.should eq @op.artist_id\r
         @rp.original_picture_id.should eq @op.id\r
       end\r
-      it '実素材を返す' do
+      it '実素材を返す' do\r
         res = @rp.new_picture @mgk\r
         res.is_a?(Picture).should be_true\r
       end\r
-    end
-  end
-  
-  describe '作成・更新に於いて' do
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
-      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-    end
-    context '事前チェック' do
-      before do
-        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
-        #それで外部のメソッド呼び出しだけに着目してテストする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+  end\r
+  \r
+  describe '作成・更新に於いて' do\r
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}\r
+      @rp = Factory.build :resource_picture, attr\r
+    end\r
+    context '事前チェック' do\r
+      before do\r
+        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
+        #それで外部のメソッド呼び出しだけに着目してテストする。\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
-      end
-      it '素材に原画からのコピーデータをセットしている' do
+      end\r
+      it '素材に原画からのコピーデータをセットしている' do\r
         ResourcePicture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
-        ResourcePicture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)
+        ResourcePicture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)\r
         res = @rp.store\r
       end\r
-      it '画像オブジェクトの取得を依頼している' do
-        ResourcePicture.any_instance.should_receive(:op_mgk).with(any_args).exactly(1)
+      it '画像オブジェクトの取得を依頼している' do\r
+        ResourcePicture.any_instance.should_receive(:op_mgk).with(any_args).exactly(1)\r
         res = @rp.store\r
       end\r
-      it '新規実素材の取得を依頼している' do
-        ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)
+      it '新規実素材の取得を依頼している' do\r
+        ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)\r
         res = @rp.store\r
       end\r
-      it '自身を保存している' do
-        ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)
+      it '自身を保存している' do\r
+        ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)\r
         res = @rp.store\r
       end\r
       it '画像ファイルの作成・更新機能で画像を保存している' do\r
-        ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@mgk).exactly(1)
+        ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@mgk).exactly(1)\r
         res = @rp.store\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
-      end
-      it 'Trueを返す' do
+      end\r
+      it 'Trueを返す' do\r
         res = @rp.store\r
         res.should be_true\r
       end\r
-      it '実素材idをセットしている' do
+      it '実素材idをセットしている' do\r
         res = @rp.store\r
         @rp.picture_id.should_not be_nil\r
       end\r
-      it '実素材idから最新画像idを取得してセットしている' do
+      it '実素材idから最新画像idを取得してセットしている' do\r
         res = @rp.store\r
         @rp.picture_id.should eq @p.id\r
       end\r
       it '自身が保存されている' do\r
-        lambda {
+        lambda {\r
           res = @rp.store\r
         }.should change ResourcePicture, :count\r
       end\r
-    end
-    #以下から例外ケース。処理先頭から失敗させていく
-    context '画像オブジェクトの取得に失敗したとき' do
-      before do
+    end\r
+    #以下から例外ケース。処理先頭から失敗させていく\r
+    context '画像オブジェクトの取得に失敗したとき' do\r
+      before do\r
         ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store\r
         res.should be_false\r
       end\r
-      it '更新されていない' do
-        @rp.store
+      it '更新されていない' do\r
+        @rp.store\r
         @rp.should be_a_new ResourcePicture\r
-      end
-    end
-    context '新規実素材の取得に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+      end\r
+    end\r
+    context '新規実素材の取得に失敗したとき' do\r
+      before do\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         Picture.any_instance.stub(:valid?).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store\r
         res.should be_false\r
       end\r
-      it '更新されていない' do
-        @rp.store
+      it '更新されていない' do\r
+        @rp.store\r
         @rp.should be_a_new ResourcePicture\r
-      end
-    end
-    context '自身の保存に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+      end\r
+    end\r
+    context '自身の保存に失敗したとき' do\r
+      before do\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store\r
         res.should be_false\r
       end\r
-      it '更新されていない' do
-        @rp.store
+      it '更新されていない' do\r
+        @rp.store\r
         @rp.should be_a_new ResourcePicture\r
-      end
-      it '処理を中断してロールバックする' do
-        lambda {
+      end\r
+      it '処理を中断してロールバックする' do\r
+        lambda {\r
           res = @rp.store\r
         }.should_not change Picture, :count\r
-      end
-    end
+      end\r
+    end\r
   end\r
-  
+  \r
   describe '画像ファイルの作成・更新に於いて' do\r
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
-      @rp = Factory.build :resource_picture, attr
-    end
-    context '事前チェック' do
-      before do
-        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。
-        #それで外部のメソッド呼び出しだけに着目してテストする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+      @rp = Factory.build :resource_picture, attr\r
+    end\r
+    context '事前チェック' do\r
+      before do\r
+        #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
+        #それで外部のメソッド呼び出しだけに着目してテストする。\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
         @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-      end
+        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
+      end\r
       it '画像ファイルの作成・更新機能で画像を保存している' do\r
-        ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)
+        ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk).exactly(1)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
-      it '自身にフォーマット変換対象かを問い合わせている' do
-        ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)
+      it '自身にフォーマット変換対象かを問い合わせている' do\r
+        ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
-      it '自身にGifフォーマット変換を依頼している' do
-        ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)
+      it '自身にGifフォーマット変換を依頼している' do\r
+        ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
       it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
-        #二回目の保存はgif変換の結果を渡す。
-        ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)
+        #二回目の保存はgif変換の結果を渡す。\r
+        ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk).exactly(1)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
         @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
-      end
-      it 'Trueを返す' do
+        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
+      end\r
+      it 'Trueを返す' do\r
         res = @rp.store_picture_with_gif @mgk\r
         res.should be_true\r
       end\r
-    end
-    context 'gif変換なしで、つつがなく終わるとき' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    context 'gif変換なしで、つつがなく終わるとき' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
-      end
-      it 'Trueを返す' do
+      end\r
+      it 'Trueを返す' do\r
         res = @rp.store_picture_with_gif @mgk\r
         res.should be_true\r
       end\r
       it 'gif保存は呼ばれていない' do\r
-        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
+        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
-    end
-    #以下から例外ケース。処理先頭から失敗させていく
-    context '画像の保存に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    #以下から例外ケース。処理先頭から失敗させていく\r
+    context '画像の保存に失敗したとき' do\r
+      before do\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
-      end
-      it 'Falseを返す' do
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store_picture_with_gif @mgk\r
         res.should be_false\r
       end\r
       it 'gif変換判定は呼ばれていない' do\r
-        ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)
+        ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
-    end
-    context 'gif変換に失敗したとき' do
-      before do
-        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。
+    end\r
+    context 'gif変換に失敗したとき' do\r
+      before do\r
+        @mgk = Mgk.new   #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
         ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)
-      end
-      it 'Falseを返す' do
+        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store_picture_with_gif @mgk\r
         res.should be_false\r
       end\r
       it 'gif画像の保存は呼ばれていない' do\r
         #本画像の保存があるので、一度は呼ばれる\r
-        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)
+        ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
         res = @rp.store_picture_with_gif @mgk\r
       end\r
-    end
-    context 'gif画像の保存に失敗したとき' do
+    end\r
+    context 'gif画像の保存に失敗したとき' do\r
       before do\r
-        @mgk = Mgk.new
+        @mgk = Mgk.new\r
         ResourcePicture.any_instance.stub(:store_picture).with(@mgk).and_return(true)\r
         ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
         class GifMgk < Mgk ; end  #store_pictureは二回呼び出される。区別をつけるために\r
         @gifmgk = GifMgk.new      #パラメータを二種類用意する。\r
-        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)
+        ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
         ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk).and_return(false)\r
-      end
-      it 'Falseを返す' do
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store_picture_with_gif @mgk\r
         res.should be_false\r
       end\r
-    end
+    end\r
   end\r
-  
+  \r
   describe '画像ファイルの作成・更新に於いて' do\r
     #PictureIo経由で画像を保存するための機能。ファイル名に自身のidを使うので事前に自身の保存が必要。\r
-    before do
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
       @rp = Factory.build :resource_picture, attr\r
-      @rp.copy_data @op
-    end
-    context '事前チェック' do
-      before do
-        #すべての処理を正常パターンで通過させ、保存機能をチェックする。
-        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
-        ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')
-      end
+      @rp.copy_data @op\r
+    end\r
+    context '事前チェック' do\r
+      before do\r
+        #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
+        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+        ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
+      end\r
       it 'サムネイル化が1回呼ばれる' do\r
-        ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)
+        ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)\r
         res = @rp.store_picture(Mgk.new)\r
       end\r
       it '画像ファイルの保存が2回呼ばれる' do\r
-        PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)
+        PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)\r
         res = @rp.store_picture(Mgk.new)\r
       end\r
       it '画像ファイルのベースへのサムネイル保存が1回呼ばれる' do\r
-        PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', @rp.filename).exactly(1)
+        PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', @rp.filename).exactly(1)\r
         res = @rp.store_picture(Mgk.new)\r
       end\r
       it '画像ファイルのfullへの保存が1回呼ばれる' do\r
-        PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'full').exactly(1)
+        PictureIO.resource_picture_io.should_receive(:put).with('data', @rp.filename, 'full').exactly(1)\r
         res = @rp.store_picture(Mgk.new)\r
       end\r
-    end
-    context 'つつがなく終わるとき' do
-      before do
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
         #すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
-        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
-      end
-      it 'Trueを返す' do
+        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+      end\r
+      it 'Trueを返す' do\r
         res = @rp.store_picture(Mgk.new)\r
         res.should be_true\r
       end\r
-    end
-    context '例外ケース' do
-      before do
-        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)
-        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)
-      end
-      it 'Falseを返す' do
+    end\r
+    context '例外ケース' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+        PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
         res = @rp.store_picture(Mgk.new)\r
         res.should be_false\r
       end\r
-    end
-    
-  end
-  
-  describe 'サムネイル変換に於いて' do
-    #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする
-    before do
-      ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)
-      @op = Factory :original_picture, :artist_id => @artist.id
-      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
+    end\r
+    \r
+  end\r
+  \r
+  describe 'サムネイル変換に於いて' do\r
+    #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする\r
+    before do\r
+      ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
       @rp = Factory.build :resource_picture, attr\r
-    end
+    end\r
     it 'サムネイルサイズに縮小した画像データを返す' do\r
-      ResourcePicture.should_receive(:resize).with(any_args).exactly(1)
+      ResourcePicture.should_receive(:resize).with(any_args).exactly(1)\r
       @rp.thumbnail(Mgk.new)\r
     end\r
     it 'データが返る' do\r
       #全体スタブより\r
       @rp.thumbnail(Mgk.new).should eq 'data'\r
     end\r
-  end
-  
-end
+  end\r
+  \r
+  describe 'クレジットデータに於いて' do\r
+    before do\r
+      @op = Factory :original_picture, :artist_id => @artist.id\r
+      @p = Factory :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{"system_picture_id": 2}', :settings => {}.to_json.to_s}\r
+      @rp = Factory.build :resource_picture, attr\r
+    end\r
+    it 'system_picture_idが入っている' do\r
+      res = @rp.credit_data\r
+      res["system_picture_id"].should eq 2\r
+    end\r
+  end\r
+  \r
+end\r
 \r
index e1feecc..41b1c3a 100644 (file)
@@ -73,9 +73,16 @@ describe StandardLicense do
     before do
       @sl = Factory.build :standard_license, :license_id => @license.id
     end
-    it 'nilを返す' do
+    it 'jsonテキストを返す' do
       r = @sl.credit 
-      r.should eq nil
+      lambda{
+        JSON.parse @sl.credit
+      }.should_not raise_error
+    end
+    it 'system_picture_idを含んでいて値はライセンスに割り当てたシステム画像になっている' do
+      r = JSON.parse @sl.credit 
+      r.has_key?('system_picture_id').should be_true
+      r['system_picture_id'].should eq @sl.license.system_picture_id
     end
   end
 end