From c952cb16dc5e99208d9b520fa95076092af5edde Mon Sep 17 00:00:00 2001 From: yasushiito Date: Tue, 3 Jul 2012 18:54:36 +0900 Subject: [PATCH] add Picture --- .../original_picture_license_groups.js.coffee | 3 - app/assets/stylesheets/standard_licenses.css.scss | 3 + app/controllers/resource_pictures_controller.rb | 30 +- app/controllers/standard_licenses_controller.rb | 63 ++++ app/helpers/standard_licenses_helper.rb | 2 + app/models/picture.rb | 2 + app/models/standard_license.rb | 15 + app/views/resource_pictures/_form.html.erb | 17 ++ app/views/resource_pictures/new.html.erb | 1 + app/views/resource_pictures/new.js.erb | 1 + app/views/standard_licenses/_form.html.erb | 32 +++ app/views/standard_licenses/new.html.erb | 1 + app/views/standard_licenses/new.js.erb | 1 + config/routes.rb | 10 +- .../20120701101503_create_standard_licenses.rb | 10 + db/migrate/20120703091854_rp_join_rp_license.rb | 13 + db/migrate/20120703094658_create_pictures.rb | 19 ++ db/standard_license.json | 19 ++ ...ginal_picture_license_groups_controller_spec.rb | 4 + .../standard_licenses_controller_spec.rb | 319 +++++++++++++++++++++ spec/factories.rb | 5 + spec/helpers/standard_licenses_helper_spec.rb | 15 + spec/models/picture_spec.rb | 5 + spec/models/resource_picture_spec.rb | 24 +- spec/models/standard_license_spec.rb | 81 ++++++ 25 files changed, 677 insertions(+), 18 deletions(-) delete mode 100644 app/assets/javascripts/original_picture_license_groups.js.coffee create mode 100644 app/assets/stylesheets/standard_licenses.css.scss create mode 100644 app/controllers/standard_licenses_controller.rb create mode 100644 app/helpers/standard_licenses_helper.rb create mode 100644 app/models/picture.rb create mode 100644 app/models/standard_license.rb create mode 100644 app/views/resource_pictures/_form.html.erb create mode 100644 app/views/resource_pictures/new.html.erb create mode 100644 app/views/resource_pictures/new.js.erb create mode 100644 app/views/standard_licenses/_form.html.erb create mode 100644 app/views/standard_licenses/new.html.erb create mode 100644 app/views/standard_licenses/new.js.erb create mode 100644 db/migrate/20120701101503_create_standard_licenses.rb create mode 100644 db/migrate/20120703091854_rp_join_rp_license.rb create mode 100644 db/migrate/20120703094658_create_pictures.rb create mode 100644 db/standard_license.json create mode 100644 spec/controllers/standard_licenses_controller_spec.rb create mode 100644 spec/helpers/standard_licenses_helper_spec.rb create mode 100644 spec/models/picture_spec.rb create mode 100644 spec/models/standard_license_spec.rb diff --git a/app/assets/javascripts/original_picture_license_groups.js.coffee b/app/assets/javascripts/original_picture_license_groups.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/original_picture_license_groups.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# 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/ diff --git a/app/assets/stylesheets/standard_licenses.css.scss b/app/assets/stylesheets/standard_licenses.css.scss new file mode 100644 index 00000000..5d737dfe --- /dev/null +++ b/app/assets/stylesheets/standard_licenses.css.scss @@ -0,0 +1,3 @@ +// 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/ diff --git a/app/controllers/resource_pictures_controller.rb b/app/controllers/resource_pictures_controller.rb index a68cd7c8..ce413b23 100644 --- a/app/controllers/resource_pictures_controller.rb +++ b/app/controllers/resource_pictures_controller.rb @@ -1,5 +1,5 @@ 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 @@ -29,7 +29,35 @@ class ResourcePicturesController < ApplicationController 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| diff --git a/app/controllers/standard_licenses_controller.rb b/app/controllers/standard_licenses_controller.rb new file mode 100644 index 00000000..993e2100 --- /dev/null +++ b/app/controllers/standard_licenses_controller.rb @@ -0,0 +1,63 @@ +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 diff --git a/app/helpers/standard_licenses_helper.rb b/app/helpers/standard_licenses_helper.rb new file mode 100644 index 00000000..7a49946c --- /dev/null +++ b/app/helpers/standard_licenses_helper.rb @@ -0,0 +1,2 @@ +module StandardLicensesHelper +end diff --git a/app/models/picture.rb b/app/models/picture.rb new file mode 100644 index 00000000..f62ecbe4 --- /dev/null +++ b/app/models/picture.rb @@ -0,0 +1,2 @@ +class Picture < ActiveRecord::Base +end diff --git a/app/models/standard_license.rb b/app/models/standard_license.rb new file mode 100644 index 00000000..4c50d049 --- /dev/null +++ b/app/models/standard_license.rb @@ -0,0 +1,15 @@ +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 diff --git a/app/views/resource_pictures/_form.html.erb b/app/views/resource_pictures/_form.html.erb new file mode 100644 index 00000000..d3ca608e --- /dev/null +++ b/app/views/resource_pictures/_form.html.erb @@ -0,0 +1,17 @@ +<%= 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 %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/resource_pictures/new.html.erb b/app/views/resource_pictures/new.html.erb new file mode 100644 index 00000000..ffacbb2d --- /dev/null +++ b/app/views/resource_pictures/new.html.erb @@ -0,0 +1 @@ +<%= render 'resource_pictures/form' %> diff --git a/app/views/resource_pictures/new.js.erb b/app/views/resource_pictures/new.js.erb new file mode 100644 index 00000000..ed93c2b1 --- /dev/null +++ b/app/views/resource_pictures/new.js.erb @@ -0,0 +1 @@ +$("#oplg").html("<%= escape_javascript(render('form')) -%>"); diff --git a/app/views/standard_licenses/_form.html.erb b/app/views/standard_licenses/_form.html.erb new file mode 100644 index 00000000..44e3daa2 --- /dev/null +++ b/app/views/standard_licenses/_form.html.erb @@ -0,0 +1,32 @@ +<% + unless @standard_license + @standard_license = StandardLicense.new + @standard_license.supply_default @artist + end + %> +<%= form_for(@standard_license) do |f| %> + <% if @standard_license.errors.any? %> +
+

<%= pluralize(@standard_license.errors.count, "error") %> prohibited this comic from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :license_id %>
+ <%= f.collection_select :license_id, @license_group.licenses.map {|l| [l.name, l.id] }, :last, :first %> + <%= f.text_field :artist_name %> +
+ <%= 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.submit %> +
+<% end %> diff --git a/app/views/standard_licenses/new.html.erb b/app/views/standard_licenses/new.html.erb new file mode 100644 index 00000000..d1e2498a --- /dev/null +++ b/app/views/standard_licenses/new.html.erb @@ -0,0 +1 @@ +<%= render 'standard_licenses/form' %> diff --git a/app/views/standard_licenses/new.js.erb b/app/views/standard_licenses/new.js.erb new file mode 100644 index 00000000..ed93c2b1 --- /dev/null +++ b/app/views/standard_licenses/new.js.erb @@ -0,0 +1 @@ +$("#oplg").html("<%= escape_javascript(render('form')) -%>"); diff --git a/config/routes.rb b/config/routes.rb index 2ba69998..79088cb5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -82,12 +82,12 @@ Pettanr::Application.routes.draw do 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 @@ -110,6 +110,12 @@ Pettanr::Application.routes.draw do post :create end end + resources :standard_licenses do + collection do + get :new + post :create + end + end resources :panels do collection do get :index diff --git a/db/migrate/20120701101503_create_standard_licenses.rb b/db/migrate/20120701101503_create_standard_licenses.rb new file mode 100644 index 00000000..618bf458 --- /dev/null +++ b/db/migrate/20120701101503_create_standard_licenses.rb @@ -0,0 +1,10 @@ +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 diff --git a/db/migrate/20120703091854_rp_join_rp_license.rb b/db/migrate/20120703091854_rp_join_rp_license.rb new file mode 100644 index 00000000..488eff45 --- /dev/null +++ b/db/migrate/20120703091854_rp_join_rp_license.rb @@ -0,0 +1,13 @@ +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 diff --git a/db/migrate/20120703094658_create_pictures.rb b/db/migrate/20120703094658_create_pictures.rb new file mode 100644 index 00000000..154f481e --- /dev/null +++ b/db/migrate/20120703094658_create_pictures.rb @@ -0,0 +1,19 @@ +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 diff --git a/db/standard_license.json b/db/standard_license.json new file mode 100644 index 00000000..e8b8ae47 --- /dev/null +++ b/db/standard_license.json @@ -0,0 +1,19 @@ +{ + "StandardLicense": { + "classname": "StandardLicense", + "caption": "Standard License", + "url": "http://test.com/standard_license", + "licenses_attributes": { + "StandardLicenseA": { + "caption": "Flag A", + "url": "http://test.com/standard_license/a", + "system_picture": "Data" + }, + "StandardLicenseB": { + "caption": "Flag B", + "url": "http://test.com/standard_license/b", + "system_picture": "Data" + } + } + } +} diff --git a/spec/controllers/original_picture_license_groups_controller_spec.rb b/spec/controllers/original_picture_license_groups_controller_spec.rb index eb55c720..aa2553c2 100644 --- a/spec/controllers/original_picture_license_groups_controller_spec.rb +++ b/spec/controllers/original_picture_license_groups_controller_spec.rb @@ -145,6 +145,10 @@ describe OriginalPictureLicenseGroupsController do 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) diff --git a/spec/controllers/standard_licenses_controller_spec.rb b/spec/controllers/standard_licenses_controller_spec.rb new file mode 100644 index 00000000..e7d9c780 --- /dev/null +++ b/spec/controllers/standard_licenses_controller_spec.rb @@ -0,0 +1,319 @@ +# -*- 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) + 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) + 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) + 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) + 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) + 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 diff --git a/spec/factories.rb b/spec/factories.rb index 09f4cf24..89213cdb 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -132,6 +132,11 @@ Factory.define :oplg, :class => OriginalPictureLicenseGroup do |oplg| 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 diff --git a/spec/helpers/standard_licenses_helper_spec.rb b/spec/helpers/standard_licenses_helper_spec.rb new file mode 100644 index 00000000..7caad3a3 --- /dev/null +++ b/spec/helpers/standard_licenses_helper_spec.rb @@ -0,0 +1,15 @@ +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 diff --git a/spec/models/picture_spec.rb b/spec/models/picture_spec.rb new file mode 100644 index 00000000..5ef8eeae --- /dev/null +++ b/spec/models/picture_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Picture do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/resource_picture_spec.rb b/spec/models/resource_picture_spec.rb index 28a3430c..d1278a21 100644 --- a/spec/models/resource_picture_spec.rb +++ b/spec/models/resource_picture_spec.rb @@ -13,7 +13,7 @@ describe ResourcePicture do @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 + @original_picture = Factory :original_picture, :artist_id => @artist.id class Mgk ; class Image ; end ; end Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new]) @@ -212,7 +212,7 @@ describe ResourcePicture do 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 @@ -247,7 +247,7 @@ describe ResourcePicture 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 @@ -280,20 +280,20 @@ describe ResourcePicture 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 @@ -396,9 +396,9 @@ describe ResourcePicture do describe '対象素材の取得に於いて' do before do @op = Factory.build :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, - :artist_id => @artist.id, :license_id => @license.id + :artist_id => @artist.id @rp = Factory.build :resource_picture, - :artist_id => @artist.id, :license_id => @license.id + :artist_id => @artist.id end context '原画オブジェクトが素材を持っている(更新ケース)' do before do @@ -432,7 +432,7 @@ describe ResourcePicture do 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 @@ -576,7 +576,7 @@ describe ResourcePicture 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 diff --git a/spec/models/standard_license_spec.rb b/spec/models/standard_license_spec.rb new file mode 100644 index 00000000..e1feecc8 --- /dev/null +++ b/spec/models/standard_license_spec.rb @@ -0,0 +1,81 @@ +# -*- 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 -- 2.11.0