From 531ec75ef74c753607bbf08d1661883b49f68617 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Sun, 5 Aug 2012 12:35:00 +0900 Subject: [PATCH] t#29174#28986:license gemnized --- Gemfile | 1 + Gemfile.lock | 3 + .../original_picture_license_groups_controller.rb | 4 +- app/controllers/standard_licenses_controller.rb | 65 ----- app/helpers/standard_licenses_helper.rb | 2 - app/models/original_picture.rb | 1 + app/models/picture.rb | 2 +- app/models/resource_picture.rb | 2 +- app/models/standard_license.rb | 17 -- app/views/layouts/system.html.erb | 18 +- app/views/layouts/test.html.erb | 34 +-- .../original_picture_license_groups/_form.html.erb | 2 +- app/views/original_pictures/show.html.erb | 2 +- app/views/resource_pictures/_form.html.erb | 8 +- app/views/resource_pictures/browse.html.erb | 8 + app/views/resource_pictures/list.html.erb | 7 +- app/views/standard_licenses/_confirm.html.erb | 5 - app/views/standard_licenses/_credit.html.erb | 7 - 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 | 12 +- ...ginal_picture_license_groups_controller_spec.rb | 8 +- .../standard_licenses_controller_spec.rb | 319 --------------------- spec/factories.rb | 5 - spec/helpers/standard_licenses_helper_spec.rb | 15 - spec/models/standard_license_spec.rb | 88 ------ 27 files changed, 62 insertions(+), 607 deletions(-) delete mode 100644 app/controllers/standard_licenses_controller.rb delete mode 100644 app/helpers/standard_licenses_helper.rb delete mode 100644 app/models/standard_license.rb delete mode 100644 app/views/standard_licenses/_confirm.html.erb delete mode 100644 app/views/standard_licenses/_credit.html.erb delete mode 100644 app/views/standard_licenses/_form.html.erb delete mode 100644 app/views/standard_licenses/new.html.erb delete mode 100644 app/views/standard_licenses/new.js.erb delete mode 100644 spec/controllers/standard_licenses_controller_spec.rb delete mode 100644 spec/helpers/standard_licenses_helper_spec.rb delete mode 100644 spec/models/standard_license_spec.rb diff --git a/Gemfile b/Gemfile index ad83b058..3709c432 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'devise', '=1.5.2' gem 'aws-s3' gem 'validates_existence' gem "validate_url" +gem "standard_licenses" # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' diff --git a/Gemfile.lock b/Gemfile.lock index 16b47808..18c0c75d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -163,6 +163,8 @@ GEM rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.6-x86-mingw32) + standard_licenses (0.0.1) + rails (~> 3.1.1) therubyracer-heroku (0.8.1.pre3) thor (0.14.6) tilt (1.3.3) @@ -208,6 +210,7 @@ DEPENDENCIES rspec-rails sass-rails (~> 3.1.4) sqlite3 + standard_licenses therubyracer-heroku uglifier (>= 1.0.3) validate_url diff --git a/app/controllers/original_picture_license_groups_controller.rb b/app/controllers/original_picture_license_groups_controller.rb index 8897d16a..05a2a248 100644 --- a/app/controllers/original_picture_license_groups_controller.rb +++ b/app/controllers/original_picture_license_groups_controller.rb @@ -45,8 +45,8 @@ class OriginalPictureLicenseGroupsController < ApplicationController respond_to do |format| if @original_picture_license_group.valid? - format.html { render :template => "#{@ctl}/new" } - format.js { render :template => "#{@ctl}/new" } + format.html { render :template => "#{@ctl}/attributes/new" } + format.js { render :template => "#{@ctl}/attributes/new" } else format.html { render action: "new" } format.js { render action: "new" } diff --git a/app/controllers/standard_licenses_controller.rb b/app/controllers/standard_licenses_controller.rb deleted file mode 100644 index 1b106b9d..00000000 --- a/app/controllers/standard_licenses_controller.rb +++ /dev/null @@ -1,65 +0,0 @@ -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 = @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" } - 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 deleted file mode 100644 index 7a49946c..00000000 --- a/app/helpers/standard_licenses_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module StandardLicensesHelper -end diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index 19c993d2..a2606bf4 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -1,5 +1,6 @@ class OriginalPicture < ActiveRecord::Base belongs_to :artist + belongs_to :original_picture_license_group has_one :resource_picture validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']} diff --git a/app/models/picture.rb b/app/models/picture.rb index 4fe43fd2..102141d4 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -110,7 +110,7 @@ class Picture < ActiveRecord::Base end def credit_template - "#{self.classname.tableize}/credit" + "#{self.classname.tableize}/attributes/credit" end def credit_data diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index 8bef0445..d558bc72 100644 --- a/app/models/resource_picture.rb +++ b/app/models/resource_picture.rb @@ -233,7 +233,7 @@ class ResourcePicture < ActiveRecord::Base end def credit_template - "#{self.classname.tableize}/credit" + "#{self.classname.tableize}/attributes/credit" end def credit_data diff --git a/app/models/standard_license.rb b/app/models/standard_license.rb deleted file mode 100644 index e359c6ce..00000000 --- a/app/models/standard_license.rb +++ /dev/null @@ -1,17 +0,0 @@ -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 - { - :system_picture_id => self.license.system_picture_id - }.to_json.to_s - end - -end diff --git a/app/views/layouts/system.html.erb b/app/views/layouts/system.html.erb index 09af0890..9cb2930e 100644 --- a/app/views/layouts/system.html.erb +++ b/app/views/layouts/system.html.erb @@ -11,18 +11,18 @@ ぺったんR
<% if user_signed_in? %> - <%= link_to "my home", :controller => '/home' %> - <%= link_to "ログアウト", destroy_user_session_path, :method => :delete %> + <%= link_to "my home", '/home' %> + <%= link_to "ログアウト", main_app.destroy_user_session_path, :method => :delete %> <% else %> - <%= link_to "ログイン", new_user_session_path %> + <%= link_to "ログイン", main_app.new_user_session_path %> <% end %>
<% if admin_signed_in? %> - <%= link_to "system", :controller => '/system' %> - <%= link_to "ログアウト", destroy_admin_session_path, :method => :delete %> + <%= link_to "system", '/system' %> + <%= link_to "ログアウト", main_app.destroy_admin_session_path, :method => :delete %> <% else %> - <%= link_to "管理者", new_admin_session_path %> + <%= link_to "管理者", main_app.new_admin_session_path %> <% end %>
@@ -30,9 +30,9 @@

<%= alert %>

- <%= link_to "browse", :controller => '/system', :action => :browse%> - <%= link_to "approve", :controller => '/system', :action => :waiting_list%> - <%= link_to "token", :controller => '/system', :action => :auth_token%> + <%= link_to "browse", '/system/browse' %> + <%= link_to "approve", '/system/waiting_list' %> + <%= link_to "token", '/system/auth_token' %>
<%= yield %> diff --git a/app/views/layouts/test.html.erb b/app/views/layouts/test.html.erb index 9bb1395e..773cbb1d 100644 --- a/app/views/layouts/test.html.erb +++ b/app/views/layouts/test.html.erb @@ -10,36 +10,36 @@
<% if user_signed_in? %> - <%= link_to "my home", :controller => '/home' %> - <%= link_to "sign out", destroy_user_session_path, :method => :delete %> + <%= link_to "my home", '/home' %> + <%= link_to "sign out", main_app.destroy_user_session_path, :method => :delete %> <% else %> - <%= link_to "sign in", new_user_session_path %> + <%= link_to "sign in", main_app.new_user_session_path %> <% end %>
<% if admin_signed_in? %> - <%= link_to "system", :controller => '/system' %> - <%= link_to "sign out", destroy_admin_session_path, :method => :delete %> + <%= link_to "system", '/system' %> + <%= link_to "sign out", main_app.destroy_admin_session_path, :method => :delete %> <% else %> - <%= link_to "sign in", new_admin_session_path %> + <%= link_to "sign in", main_app.new_admin_session_path %> <% end %>

<%= notice %>

<%= alert %>

-<%= link_to 'comics', comics_path %> -<%= link_to 'panels', panels_path %> -<%= link_to 'original_pictures', original_pictures_path %> -<%= link_to 'resource_pictures', resource_pictures_path %> -<%= link_to 'panel_pictures', panel_pictures_path %> -<%= link_to 'speech_balloons', speech_balloons_path %> -<%= link_to 'balloons', balloons_path %> -<%= link_to 'speeches', speeches_path %> +<%= link_to 'comics', main_app.comics_path %> +<%= link_to 'panels', main_app.panels_path %> +<%= link_to 'original_pictures', main_app.original_pictures_path %> +<%= link_to 'resource_pictures', main_app.resource_pictures_path %> +<%= link_to 'panel_pictures', main_app.panel_pictures_path %> +<%= link_to 'speech_balloons', main_app.speech_balloons_path %> +<%= link_to 'balloons', main_app.balloons_path %> +<%= link_to 'speeches', main_app.speeches_path %> : -<%= link_to 'speech_balloon_templates', speech_balloon_templates_path %> +<%= link_to 'speech_balloon_templates', main_app.speech_balloon_templates_path %> : -<%= link_to 'artists', artists_path %> -<%= link_to 'system_pictures', system_pictures_path %> +<%= link_to 'artists', main_app.artists_path %> +<%= link_to 'system_pictures', main_app.system_pictures_path %>
<%= yield %> diff --git a/app/views/original_picture_license_groups/_form.html.erb b/app/views/original_picture_license_groups/_form.html.erb index 51b3736c..0b8e7b95 100644 --- a/app/views/original_picture_license_groups/_form.html.erb +++ b/app/views/original_picture_license_groups/_form.html.erb @@ -13,7 +13,7 @@
<%= f.label :license_group_id %>
- <%= f.collection_select :license_group_id, LicenseGroup.list.map {|l| [l.name, l.id] }, :last, :first %> + <%= f.collection_select :license_group_id, LicenseGroup.list.map {|l| [l.caption, l.id] }, :last, :first %> <%= f.hidden_field :original_picture_id %>
<%= hidden_field_tag :original_picture_id, @original_picture.id %> diff --git a/app/views/original_pictures/show.html.erb b/app/views/original_pictures/show.html.erb index bb1f979d..5d32979c 100644 --- a/app/views/original_pictures/show.html.erb +++ b/app/views/original_pictures/show.html.erb @@ -31,7 +31,7 @@ browse picture

-Select License +<%= link_to 'Select License', :controller => 'original_picture_license_groups', :action => :new, :original_picture_id => @original_picture.id %>

<%= render 'original_picture_license_groups/form' %> diff --git a/app/views/resource_pictures/_form.html.erb b/app/views/resource_pictures/_form.html.erb index 809410cf..b8ef2701 100644 --- a/app/views/resource_pictures/_form.html.erb +++ b/app/views/resource_pictures/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for(@resource_picture) do |f| %> +<%= form_for(@resource_picture, :url => '/resource_pictures', :method => :post) do |f| %> <%= hidden_field_tag :original_picture_id, @original_picture.id %> @@ -13,14 +13,14 @@ <%= f.hidden_field :settings %>
- <%= link_to h(@license_group.caption), license_group_path(@license_group) %> - <%= link_to h(@license.caption), license_path(@license) %> + <%= link_to h(@license_group.caption), main_app.license_group_path(@license_group) %> + <%= link_to h(@license.caption), main_app.license_path(@license) %>
artist name:<%= @resource_picture.artist_name %>
- <%= render @resource_picture.classname.tableize + '/confirm' %> + <%= render :partial => @resource_picture.classname.tableize + '/attributes/confirm' %>
<%= f.submit %> diff --git a/app/views/resource_pictures/browse.html.erb b/app/views/resource_pictures/browse.html.erb index 76b40949..f43b1718 100644 --- a/app/views/resource_pictures/browse.html.erb +++ b/app/views/resource_pictures/browse.html.erb @@ -1,4 +1,12 @@

<%= notice %>

+credit +

+ <%= @resource_picture.credit %> +

+settings +

+ <%= @resource_picture.settings %> +

ノーマル diff --git a/app/views/resource_pictures/list.html.erb b/app/views/resource_pictures/list.html.erb index 6e9fd441..2141011a 100644 --- a/app/views/resource_pictures/list.html.erb +++ b/app/views/resource_pictures/list.html.erb @@ -10,10 +10,12 @@ artist license_id original_picture_id + artist_name + classname + picture created_at updated_at - <% @resource_pictures.each do |resource_picture| %> <%= link_to resource_picture.id, :action => :browse, :id => resource_picture.id%> @@ -24,6 +26,9 @@ <%= link_to resource_picture.artist_id, :controller => 'artists', :action => :browse, :id => resource_picture.artist_id %> <%= link_to resource_picture.license_id, :controller => 'licenses', :action => :browse, :id => resource_picture.license_id %> <%= link_to resource_picture.original_picture_id, :controller => 'original_pictures', :action => :browse, :id => resource_picture.original_picture_id%> + <%= resource_picture.artist_name %> + <%= resource_picture.classname %> + <%= link_to resource_picture.picture_id, main_app.picture_path(resource_picture.picture_id) %> <%= resource_picture.created_at %> <%= resource_picture.updated_at %> diff --git a/app/views/standard_licenses/_confirm.html.erb b/app/views/standard_licenses/_confirm.html.erb deleted file mode 100644 index 9d0eb302..00000000 --- a/app/views/standard_licenses/_confirm.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% @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 ) -%> diff --git a/app/views/standard_licenses/_credit.html.erb b/app/views/standard_licenses/_credit.html.erb deleted file mode 100644 index cfa175fd..00000000 --- a/app/views/standard_licenses/_credit.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -

-<%= content_tag(:a, - tag(:img, :src => picture.license.system_picture.url, :alt => h(picture.license.license_group.caption.to_s + '[' + picture.license.caption.to_s + ']')), - :href => picture.license.url ) -%> -
-著作者:<%= link_to h(picture.artist_name), :controller => 'artists', :action => :show, :id => picture.artist.id %> diff --git a/app/views/standard_licenses/_form.html.erb b/app/views/standard_licenses/_form.html.erb deleted file mode 100644 index 44e3daa2..00000000 --- a/app/views/standard_licenses/_form.html.erb +++ /dev/null @@ -1,32 +0,0 @@ -<% - 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:

- -
    - <% @standard_license.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% 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 deleted file mode 100644 index d1e2498a..00000000 --- a/app/views/standard_licenses/new.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render 'standard_licenses/form' %> diff --git a/app/views/standard_licenses/new.js.erb b/app/views/standard_licenses/new.js.erb deleted file mode 100644 index ed93c2b1..00000000 --- a/app/views/standard_licenses/new.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#oplg").html("<%= escape_javascript(render('form')) -%>"); diff --git a/config/routes.rb b/config/routes.rb index e2e60d66..02264de4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,9 @@ Pettanr::Application.routes.draw do devise_for :users , :controllers => { :registrations => "user_registrations" } devise_for :admins - + + mount StandardLicenses::Engine => "/standard_licenses" + resources :authors do collection do get :index @@ -123,14 +125,6 @@ Pettanr::Application.routes.draw do post :create end end - resources :standard_licenses do - new do - get :new - end - collection do - post :create - end - end resources :panels do new do get :new diff --git a/spec/controllers/original_picture_license_groups_controller_spec.rb b/spec/controllers/original_picture_license_groups_controller_spec.rb index 9791a6c0..598fa8a8 100644 --- a/spec/controllers/original_picture_license_groups_controller_spec.rb +++ b/spec/controllers/original_picture_license_groups_controller_spec.rb @@ -9,7 +9,7 @@ describe OriginalPictureLicenseGroupsController do @author = @user.author @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @sp = FactoryGirl.create :system_picture - @lg = FactoryGirl.create :license_group, :classname => 'OriginalPicture' + @lg = FactoryGirl.create :license_group, :classname => 'StandardLicense' @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @op = FactoryGirl.create :original_picture, :artist_id => @artist.id end @@ -143,7 +143,7 @@ describe OriginalPictureLicenseGroupsController do end it '@ctlにコントローラを用意している' do post :create, @attr - assigns(:ctl).should eq 'original_pictures' + assigns(:ctl).should eq 'standard_licenses' end it '@original_picture_license_groupにデータを用意している' do post :create, @attr @@ -176,7 +176,7 @@ describe OriginalPictureLicenseGroupsController do end it 'ライセンスクラスの新規作成テンプレートnewを描画する' do post :create, @attr - response.should render_template("original_pictures/new") + response.should render_template("standard_licenses/attributes/new") end end context 'js形式' do @@ -186,7 +186,7 @@ describe OriginalPictureLicenseGroupsController do end it 'ライセンスクラスの新規作成部分テンプレートnew.jsを描画する' do post :create, @attrj - response.should render_template("original_pictures/new") + response.should render_template("standard_licenses/attributes/new") end end end diff --git a/spec/controllers/standard_licenses_controller_spec.rb b/spec/controllers/standard_licenses_controller_spec.rb deleted file mode 100644 index d802b8ac..00000000 --- a/spec/controllers/standard_licenses_controller_spec.rb +++ /dev/null @@ -1,319 +0,0 @@ -# -*- encoding: utf-8 -*- -#ライセンス選択 -require 'spec_helper' - -describe StandardLicensesController do - before do - FactoryGirl.create :admin - @user = FactoryGirl.create( :user_yas) - @author = @user.author - @artist = FactoryGirl.create :artist_yas, :author_id => @author.id - @sp = FactoryGirl.create :system_picture - @lg = FactoryGirl.create :license_group, :classname => 'OriginalPicture' - @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id - @op = FactoryGirl.create :original_picture, :artist_id => @artist.id - end - - describe '新規作成フォーム表示に於いて' do - before do - sign_in @user - end - context 'つつがなく終わるとき' do - before do - @oplg = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 c84bf258..18cb73bd 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -100,11 +100,6 @@ FactoryGirl.define do oplg.license_group_id 1 end - factory :standard_license, :class => StandardLicense do |sl| - sl.license_id 1 - sl.artist_name 'no name' - end - factory :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 deleted file mode 100644 index 7caad3a3..00000000 --- a/spec/helpers/standard_licenses_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -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/standard_license_spec.rb b/spec/models/standard_license_spec.rb deleted file mode 100644 index bfcbc304..00000000 --- a/spec/models/standard_license_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# -*- encoding: utf-8 -*- -#ライセンス選択 -require 'spec_helper' - -describe StandardLicense do - before do - FactoryGirl.create :admin - @user = FactoryGirl.create( :user_yas) - @author = @user.author - @artist = FactoryGirl.create :artist_yas, :author_id => @author.id - @other_user = FactoryGirl.create( :user_yas) - @other_author = @other_user.author - @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id - @sp = FactoryGirl.create :system_picture - @lg = FactoryGirl.create :license_group - @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id - @op = FactoryGirl.create :original_picture, :artist_id => @artist.id - end - - describe '検証に於いて' do - before do - end - - it 'オーソドックスなデータなら通る' do - @sl = FactoryGirl.build :standard_license, :license_id => @license.id - @sl.should be_valid - end - - context 'license_idを検証するとき' do - before do - @sl = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.build :standard_license, :license_id => @license.id - end - it 'jsonテキストを返す' do - r = @sl.credit - 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 -- 2.11.0