+++ /dev/null
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
--- /dev/null
+// Place all the styles related to the StandardLicenses controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
class ResourcePicturesController < ApplicationController
- before_filter :authenticate_user!, :only => [:index, :show]
+ before_filter :authenticate_user!, :only => [:index, :show, :new, :create]
before_filter :authenticate_admin!, :only => [:list, :browse]
# GET /resource_pictures
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]
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ end
+ end
+
+ def create
+ @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]
+ respond_to do |format|
+ if @resource_picture.store
+ format.html { render :template => "resource_pictures/new" }
+ format.js { render :template => "resource_pictures/new" }
+ 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|
--- /dev/null
+class StandardLicensesController < ApplicationController
+ layout 'test' if Pettanr::TestLayout
+ before_filter :authenticate_user!, :only => [:new, :create]
+ before_filter :authenticate_artist, :only => [:new, :create]
+
+ private
+
+ def authenticate_artist
+ if @author.artist?
+ true
+ else
+ respond_to do |format|
+ format.html { redirect_to new_artist_path, :status => :found }
+ format.js { render "artists/new" }
+ format.json {
+ raise ActiveRecord::Forbidden
+ }
+ end
+ false
+ end
+ end
+
+ public
+
+ # GET /standard_licenses/new
+ # GET /standard_licenses/new.js
+ 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
+ @standard_license = StandardLicense.new
+ @standard_license.supply_default @artist
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.js
+ end
+ end
+
+ # POST /standard_licenses
+ # POST /standard_licenses.js
+ def create
+ @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
+ @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,
+ :credit => @standard_license.credit, :settings => @license.settings
+
+ respond_to do |format|
+ if @standard_license.valid?
+ format.html { render :template => "resource_pictures/new" }
+ format.js { render :template => "resource_pictures/new" }
+ else
+ format.html { render action: "new" }
+ format.js { render action: "new" }
+ end
+ end
+ end
+
+end
--- /dev/null
+module StandardLicensesHelper
+end
--- /dev/null
+class Picture < ActiveRecord::Base
+end
--- /dev/null
+class StandardLicense < ActiveRecord::Base
+ belongs_to :license
+
+ validates :license_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_name, :presence => true
+
+ def supply_default ar
+ self.artist_name = ar.name
+ end
+
+ def credit
+ nil
+ end
+
+end
--- /dev/null
+<%= form_for(@resource_picture) do |f| %>
+
+ <%= hidden_field_tag :original_picture_id, @original_picture.id %>
+
+ <%= hidden_field_tag 'original_picture_license_group[original_picture_id]', @original_picture_license_group.original_picture_id %>
+ <%= hidden_field_tag 'original_picture_license_group[license_group_id]', @original_picture_license_group.license_group_id %>
+
+ <%= f.hidden_field :original_picture_id %>
+ <%= f.hidden_field :license_id %>
+ <%= f.hidden_field :artist_name %>
+ <%= f.hidden_field :credit %>
+ <%= f.hidden_field :settings %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
--- /dev/null
+<%= render 'resource_pictures/form' %>
--- /dev/null
+$("#oplg").html("<%= escape_javascript(render('form')) -%>");
--- /dev/null
+<%
+ unless @standard_license
+ @standard_license = StandardLicense.new
+ @standard_license.supply_default @artist
+ end
+ %>
+<%= form_for(@standard_license) do |f| %>
+ <% if @standard_license.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@standard_license.errors.count, "error") %> prohibited this comic from being saved:</h2>
+
+ <ul>
+ <% @standard_license.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :license_id %><br />
+ <%= f.collection_select :license_id, @license_group.licenses.map {|l| [l.name, l.id] }, :last, :first %>
+ <%= f.text_field :artist_name %>
+ </div>
+ <%= hidden_field_tag :original_picture_id, @original_picture.id %>
+ <%= hidden_field_tag 'original_picture_license_group[original_picture_id]', @original_picture_license_group.original_picture_id %>
+ <%= hidden_field_tag 'original_picture_license_group[license_group_id]', @original_picture_license_group.license_group_id %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
--- /dev/null
+<%= render 'standard_licenses/form' %>
--- /dev/null
+$("#oplg").html("<%= escape_javascript(render('form')) -%>");
collection do
get :index
get :show
+ get :new
+ post :create
get :count
get :list
get :browse
end
- member do
- end
end
resources :original_pictures do
collection do
post :create
end
end
+ resources :standard_licenses do
+ collection do
+ get :new
+ post :create
+ end
+ end
resources :panels do
collection do
get :index
--- /dev/null
+class CreateStandardLicenses < ActiveRecord::Migration
+ def change
+ create_table :standard_licenses do |t|
+ t.column :license_id, :integer, :null => false, :default => 0
+ t.column :artist_name, :string, :null => false, :default => 'unknown'
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+class RpJoinRpLicense < ActiveRecord::Migration
+ def up
+ add_column :resource_pictures, :artist_name, :string, :null => false, :default => 'unknown'
+ add_column :resource_pictures, :credit, :string
+ add_column :resource_pictures, :settings, :string
+ end
+
+ def down
+ remove_column :resource_pictures, :artist_name, :string, :null => false, :default => 'unknown'
+ remove_column :resource_pictures, :credit, :string
+ remove_column :resource_pictures, :settings, :string
+ end
+end
--- /dev/null
+class CreatePictures < ActiveRecord::Migration
+ def change
+ create_table :pictures do |t|
+ t.integer :original_picture_id, :null => false, :default => 0
+ t.integer :revision, :null => false, :default => 1
+ t.string :ext, :null => false
+ t.integer :width, :null => false
+ t.integer :height, :null => false
+ t.integer :filesize, :null => false
+ t.integer :artist_id, :null => false, :default => 0
+ t.integer :license_id, :null => false, :default => 0
+ t.string :artist_name, :null => false, :default => 'unknown'
+ t.string :credit
+ t.string :settings
+
+ t.timestamps
+ end
+ end
+end
--- /dev/null
+{\r
+ "StandardLicense": {\r
+ "classname": "StandardLicense", \r
+ "caption": "Standard License", \r
+ "url": "http://test.com/standard_license",\r
+ "licenses_attributes": {\r
+ "StandardLicenseA": {\r
+ "caption": "Flag A", \r
+ "url": "http://test.com/standard_license/a",\r
+ "system_picture": "Data"\r
+ },\r
+ "StandardLicenseB": {\r
+ "caption": "Flag B", \r
+ "url": "http://test.com/standard_license/b",\r
+ "system_picture": "Data"\r
+ }\r
+ }\r
+ }\r
+}\r
post :create, @attr
assigns(:ctl).should eq 'original_pictures'
end
+ it '@original_picture_license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
+ end
it 'モデルに検証依頼する' do
OriginalPictureLicenseGroup.any_instance.stub(:valid?).with(any_args()).and_return(true)
OriginalPictureLicenseGroup.any_instance.should_receive(:valid?).exactly(1)
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンス選択
+require 'spec_helper'
+
+describe StandardLicensesController do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @sp = Factory :system_picture
+ @lg = Factory :license_group, :classname => 'OriginalPicture'
+ @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '新規作成フォーム表示に於いて' do
+ before do
+ sign_in @user
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ it 'ステータスコード200 OKを返す' do
+ get :new, @attr
+ response.should be_success
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.stub(:show).with(any_args()).and_return(@op)
+ OriginalPicture.should_receive(:show).with(any_args()).exactly(1)\r
+ get :new, @attr
+ end
+ it '@original_pictureにデータを用意している' do
+ get :new, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '@original_picture_license_groupに新規データを用意している' do
+ get :new, @attr
+ assigns(:original_picture_license_group).should be_a_new(OriginalPictureLicenseGroup)
+ end
+ it 'ライセンスグループモデルに単体取得を問い合わせている' do
+ LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
+ LicenseGroup.should_receive(:show).with(any_args()).exactly(1)\r
+ get :new, @attr
+ end
+ it '@license_groupにデータを用意している' do
+ get :new, @attr
+ assigns(:license_group).should eq @lg
+ end
+ it '@standard_licenseにライセンス選択新規データを用意している' do
+ get :new, @attr
+ assigns(:standard_license).should be_a_new(StandardLicense)
+ end
+ it 'ライセンス選択にデフォルト値補充を依頼している' do
+ StandardLicense.any_instance.should_receive(:supply_default).exactly(1)\r
+ get :new, @attr
+ end
+ context 'html形式' do
+ it 'ページテンプレートnewを描画する' do
+ get :new, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it '部分テンプレートnew.jsを描画する' do
+ get :new, @attrj
+ response.should render_template("new")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
+ @attrj = @attr.merge({:format => :js})
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ get :new, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ get :new, @attrj
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ get :new, @attrj
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id}}
+ @attrj = @attr.merge({:format => :js})
+ Author.any_instance.stub(:artist?).and_return(false)
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ get :new, @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ get :new, @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 Okを返す' do
+ get :new, @attrj
+ response.status.should eq 200
+ end
+ it '絵師登録部分テンプレートartists/new.jsを描画する' do
+ get :new, @attrj
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ end
+
+ describe '新規作成に於いて' do
+ before do
+ sign_in @user
+ end
+ context '事前チェックしておく' do
+ before do
+ StandardLicense.any_instance.stub(:valid?).with(any_args()).and_return(true)
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ it '原画モデルに単体取得を問い合わせている' do
+ OriginalPicture.stub(:show).with(any_args()).and_return(@op)
+ OriginalPicture.should_receive(:show).exactly(1)\r
+ post :create, @attr
+ end
+ it '@original_pictureにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture).should eq @op
+ end
+ it '@original_picture_license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:original_picture_license_group).should be_a_new OriginalPictureLicenseGroup
+ end
+ it 'ライセンスグループモデルに単体取得を問い合わせている' do
+ LicenseGroup.stub(:show).with(any_args()).and_return(@lg)
+ LicenseGroup.should_receive(:show).exactly(1)\r
+ post :create, @attr
+ end
+ it '@license_groupにデータを用意している' do
+ post :create, @attr
+ assigns(:license_group).should eq @lg
+ end
+ it '@standard_licenseにデータを用意している' do
+ post :create, @attr
+ assigns(:standard_license).should be_a_new StandardLicense
+ end
+ it '@licenseにデータを用意している' do
+ post :create, @attr
+ assigns(:license).should eq @license
+ end
+ it '@creditにデータを用意している' do
+ post :create, @attr
+ assigns(:credit).should eq nil
+ end
+ it 'モデルに検証依頼する' do
+ StandardLicense.any_instance.stub(:valid?).with(any_args()).and_return(true)
+ StandardLicense.any_instance.should_receive(:valid?).exactly(1)
+ post :create, @attr
+ end
+ end
+ context 'つつがなく終わるとき' do
+ before do
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ it "検証が通る" do
+ post :create, @attr
+ assigns(:standard_license).valid?.should eq true
+ end
+ it "DBに変化がない" do
+ lambda {
+ post :create, @attr
+ }.should_not change StandardLicense, :count
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.should be_success
+ end
+ it 'ライセンスクラスの新規作成テンプレートnewを描画する' do
+ post :create, @attr
+ response.should render_template("resource_pictures/new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.should be_success
+ end
+ it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do
+ post :create, @attrj
+ response.should render_template("resource_pictures/new")
+ end
+ end
+ end
+ context '作家権限がないとき' do
+ before do
+ sign_out @user
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it 'サインインページへ遷移する' do
+ post :create, @attr
+ response.body.should redirect_to '/users/sign_in'
+ end
+ end
+ context 'json形式' do
+ it 'ステータスコード401 Unauthorizedを返す' do
+ post :create, @attrj
+ response.status.should eq 401
+ end
+ it '応答メッセージにUnauthorizedを返す' do
+ post :create, @attrj
+ response.message.should match(/Unauthorized/)
+ end
+ end
+ end
+ context '作家が絵師でないとき' do
+ before do
+ Author.any_instance.stub(:artist?).and_return(false)
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ context 'html形式' do
+ it 'ステータスコード302 Foundを返す' do
+ post :create, @attr
+ response.status.should eq 302
+ end
+ it '絵師登録ページへ遷移する' do
+ post :create, @attr
+ response.should redirect_to new_artist_path
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.status.should eq 200
+ end
+ it '絵師登録ページへ遷移する' do
+ post :create, @attrj
+ response.should render_template("artists/new")
+ end
+ end
+ end
+ context '検証、保存に失敗した' do
+ before do
+ StandardLicense.any_instance.stub(:valid?).and_return(false)
+ @oplg = Factory.build :oplg, :original_picture_id => @op.id, :license_group_id => @lg.id
+ @attr = {:original_picture_id => @op.id, :original_picture_license_group => {:original_picture_id => @oplg.original_picture_id, :license_group_id => @oplg.license_group_id},
+ :standard_license => {:license_id => @license.id, :artist_name => @artist.name}
+ }
+ @attrj = @attr.merge({:format => :js})
+ end
+ it "未保存の原画ライセンスグループを保持している" do
+ post :create, @attr
+ assigns(:standard_license).should be_a_new(StandardLicense)
+ end
+ context 'html形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attr
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @attr
+ response.should render_template("new")
+ end
+ end
+ context 'js形式' do
+ it 'ステータスコード200 OKを返す' do
+ post :create, @attrj
+ response.status.should eq 200
+ end
+ it '新規ページを描画する' do
+ post :create, @attrj
+ response.should render_template("new")
+ end
+ end
+ end
+ end
+
+end
oplg.license_group_id 1
end
+Factory.define :standard_license, :class => StandardLicense do |sl|
+ sl.license_id 1
+ sl.artist_name 'no name'
+end
+
Factory.define :resource_picture, :class => ResourcePicture do |rp|
rp.ext 'png'
rp.width 222
--- /dev/null
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the StandardLicensesHelper. For example:
+#
+# describe StandardLicensesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe StandardLicensesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
--- /dev/null
+require 'spec_helper'
+
+describe Picture do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
@sp = Factory :system_picture
@lg = Factory :license_group
@license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
- @original_picture = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.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])
\r
describe '単体取得に於いて' do
before do
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory :original_picture, :artist_id => @artist.id
@rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
end
it '指定の素材を返す' do
end
describe '一覧取得に於いて' do
before do
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory :original_picture, :artist_id => @artist.id
@rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
end
context 'page補正について' do
pic.should eq [@rp]
end
it '時系列で並んでいる' do
- nop = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ 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, :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, :license_id => @license.id
+ 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, :updated_at => Time.now + 100
- nop3 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ 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, :updated_at => Time.now + 200
- nop4 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ 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, :updated_at => Time.now + 300
- nop5 = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ 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, :updated_at => Time.now + 400
ResourcePicture.stub(:default_page_size).and_return(2)
end
describe '対象素材の取得に於いて' do
before do\r
@op = Factory.build :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
- :artist_id => @artist.id, :license_id => @license.id
+ :artist_id => @artist.id
@rp = Factory.build :resource_picture, \r
- :artist_id => @artist.id, :license_id => @license.id
+ :artist_id => @artist.id
end
context '原画オブジェクトが素材を持っている(更新ケース)' do
before do\r
describe '作成・更新に於いて' do
before do
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory :original_picture, :artist_id => @artist.id
@rp = Factory.build :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
end
context '事前チェック' do
ResourcePicture.any_instance.stub(:v).with(any_args).and_return('data')
ResourcePicture.any_instance.stub(:vh).with(any_args).and_return('data')
ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('data')
- @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id
+ @op = Factory :original_picture, :artist_id => @artist.id
@rp = Factory :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id
end
context '事前チェック' do
--- /dev/null
+# -*- encoding: utf-8 -*-
+#ライセンス選択
+require 'spec_helper'
+
+describe StandardLicense do
+ before do
+ Factory :admin
+ @user = Factory( :user_yas)
+ @author = @user.author
+ @artist = Factory :artist_yas, :author_id => @author.id
+ @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
+ @op = Factory :original_picture, :artist_id => @artist.id
+ end
+
+ describe '検証に於いて' do
+ before do
+ end
+
+ it 'オーソドックスなデータなら通る' do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ @sl.should be_valid
+ end
+
+ context 'license_idを検証するとき' do
+ before do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @sl.license_id = @license.id
+ @sl.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @sl.license_id = nil
+ @sl.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @sl.license_id = 'a'
+ @sl.should_not be_valid
+ end
+ it '存在するライセンスグループでなければ失敗する' do
+ @sl.license_id = 0
+ @sl.should_not be_valid
+ end
+ end
+ context 'artist_nameを検証するとき' do
+ before do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ end
+ it 'テストデータの確認' do
+ @sl.artist_name = 'a'
+ @sl.should be_valid
+ end
+ it 'nullなら失敗する' do
+ @sl.artist_name = nil
+ @sl.should_not be_valid
+ end
+ end
+ end
+ describe '補充に於いて' do
+ it '原画idを補充している' do
+ @sl = StandardLicense.new
+ @sl.artist_name = nil
+ @sl.supply_default @artist
+ @sl.artist_name.should eq @artist.name
+ end
+ end
+ describe 'クレジットデータに於いて' do
+ before do
+ @sl = Factory.build :standard_license, :license_id => @license.id
+ end
+ it 'nilを返す' do
+ r = @sl.credit
+ r.should eq nil
+ end
+ end
+end