From e586fa2a510c607181a3fa9e968497bf143986bf Mon Sep 17 00:00:00 2001
From: yasushiito
+ <%= t_m 'Artist.author_id' -%>: + <% if @ar.author_id %> + <%= link_to @ar.author_id, browse_author_path(@ar.author) %> + <% end %> +
+ +<%= t_m 'Artist.created_at' -%>: <%= l @ar.created_at %>
diff --git a/app/views/artists/list.html.erb b/app/views/artists/list.html.erb index abca0851..99947d0c 100644 --- a/app/views/artists/list.html.erb +++ b/app/views/artists/list.html.erb @@ -4,14 +4,20 @@<%= notice %>
+ +<% if @failures.empty? %> +<%= t_m 'License.caption' -%> | +<%= t_m 'License.name' -%> | +
---|---|
+ <%= link_to h(artist['caption']), artist['url'] %> + | ++ <%= h(artist['name']) %> + | +
+ <%= link_to t('provider_statuses.show.artists_import'), artists_import_provider_status_path(@provider_status), :method => :post %> +
+<%= link_to t('provider_statuses.show.receive_stop'), provider_status_path(@provider_status), :method => :delete %>
<% end %> diff --git a/config/locales/pettanr.ja.yml b/config/locales/pettanr.ja.yml index 9ab78885..98283864 100644 --- a/config/locales/pettanr.ja.yml +++ b/config/locales/pettanr.ja.yml @@ -263,6 +263,9 @@ ja: created_at: ä½æ updated_at: æ´æ° provider_artist: + provider_id: 貸æ + providers_artist_id: 貸æå´çµµå¸« + demanders_artist_id: åæå´çµµå¸« created_at: ä½æ updated_at: æ´æ° provider_original_picture: @@ -635,6 +638,11 @@ ja: success: ã¤ã³ãã¼ããå®äºãã¾ãã fail: 次ã®ã©ã¤ã»ã³ã¹(%{size}件)ã§ã¨ã©ã¼ãããã¾ãããã©ã¤ã»ã³ã¹ã®ã¤ã³ã¹ãã¼ã«ç¶æ³ã確èªãã¦ãã ããã to_show: ååç¶æ³ã表示ãã + artists_import: + title: 絵師ã¤ã³ãã¼ã + success: ã¤ã³ãã¼ããå®äºãã¾ãã + fail: 次ã®çµµå¸«(%{size}件)ã§ã¨ã©ã¼ãããã¾ããã + to_show: ååç¶æ³ã表示ãã status: ç¶æ open: éã to_provider: 貸æã«åãæ¿ãã diff --git a/config/routes.rb b/config/routes.rb index f0b5e89f..d00e5231 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -299,6 +299,7 @@ Pettanr::Application.routes.draw do put :update delete :destroy post :licenses_import + post :artists_import end end resources :demanders do @@ -313,6 +314,7 @@ Pettanr::Application.routes.draw do get :browse post :req get :licenses_export + get :artists_export end member do get :edit diff --git a/db/migrate/20121216060750_create_provider_artists.rb b/db/migrate/20121216060750_create_provider_artists.rb new file mode 100644 index 00000000..0bf3525c --- /dev/null +++ b/db/migrate/20121216060750_create_provider_artists.rb @@ -0,0 +1,11 @@ +class CreateProviderArtists < ActiveRecord::Migration + def change + create_table :provider_artists do |t| + t.integer :provider_id, :null => false, :default => 0 + t.integer :providers_artist_id, :null => false, :default => 0 + t.integer :demanders_artist_id, :null => false, :default => 0 + + t.timestamps + end + end +end diff --git a/spec/controllers/demanders_controller_spec.rb b/spec/controllers/demanders_controller_spec.rb index ed7b6f01..08af954f 100644 --- a/spec/controllers/demanders_controller_spec.rb +++ b/spec/controllers/demanders_controller_spec.rb @@ -9,7 +9,7 @@ describe DemandersController do @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @user = FactoryGirl.create :user_yas - @author = @user.author #ã¦ã¼ã¶ä½ææã«é£åãã¦ä½æããã + @author = FactoryGirl.create :author, :user_id => @user.id @demand_user = FactoryGirl.create :demand_user end @@ -685,4 +685,89 @@ describe DemandersController do end end end + + describe '絵師ã¨ã¯ã¹ãã¼ãã«æ¼ãã¦' do + before do + @ds = FactoryGirl.create :demander_status + @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id, :demand_user_id => @demand_user.id + @artist = FactoryGirl.create :artist, :author_id => @author.id + sign_in @demand_user + end + context 'ã¤ã¤ããªãçµããã¨ã' do + before do + Demander.any_instance.stub(:artists_export).with(any_args).and_return([@artist, @artist, @artist]) + end + it 'ã¹ãã¼ã¿ã¹ã³ã¼ã200 OKãè¿ã' do + get :artists_export, :format => :json + response.should be_success + end + it 'æ¥ä»æååå¤æãä¾é ¼ãã¦ãã' do + DemandersController.any_instance.should_receive(:ymd_to_time).with('20111010').exactly(1) + get :artists_export, :date => '20111010', :format => :json + end + it 'åæã¢ãã«ã«çµµå¸«ã¨ã¯ã¹ãã¼ããåãåããã¦ãã' do + Demander.any_instance.should_receive(:artists_export).with(Time.parse('2011/10/10')).exactly(1) + get :artists_export, :date => '20111010', :format => :json + end + it '@artistsã«ãªã¹ããåå¾ãã¦ãã' do + get :artists_export, :format => :json + assigns(:artists).should have_at_least(3).items + end + context 'htmlå½¢å¼' do + end + context 'jsonå½¢å¼' do + it 'jsonãã¼ã¿ãè¿ã' do + get :artists_export, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'ãã¼ã¿ããªã¹ãæ§é ã«ãªã£ã¦ãã' do + get :artists_export, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'ãªã¹ãã®å é ãããã¯çµµå¸«ã£ã½ããã®ã§ãã£ã¦æ¬²ãã' do + get :artists_export, :format => :json + json = JSON.parse response.body + json.first.has_key?("name").should be_true + json.first.has_key?("author_id").should be_true + end + end + end + context 'åæ権éããªãã¨ã' do + before do + sign_out @demand_user + end + it 'ã¹ãã¼ã¿ã¹ã³ã¼ã302 Foundãè¿ã' do + get :artists_export + response.status.should eq 302 + end + context 'htmlå½¢å¼' do + it 'ãµã¤ã³ã¤ã³ãã¼ã¸ã¸é·ç§»ãã' do + get :artists_export + response.body.should redirect_to '/demand_users/sign_in' + end + end + context 'jsonå½¢å¼' do + it 'å¿çã¡ãã»ã¼ã¸ã«Unauthorizedãè¿ã' do + get :artists_export, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context 'åå権éããªãã¨ã' do + before do + Demander.any_instance.stub(:status).and_return(1) + end + context 'htmlå½¢å¼' do + end + context 'jsonå½¢å¼' do + it 'ã¹ãã¼ã¿ã¹ã³ã¼ã403 forbiddenãè¿ã' do + lambda{ + get :artists_export, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + end + end diff --git a/spec/controllers/provider_statuses_controller_spec.rb b/spec/controllers/provider_statuses_controller_spec.rb index ed08f0ef..db2c7b3e 100644 --- a/spec/controllers/provider_statuses_controller_spec.rb +++ b/spec/controllers/provider_statuses_controller_spec.rb @@ -9,7 +9,8 @@ describe ProviderStatusesController do @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @user = FactoryGirl.create :user_yas - @author = @user.author #ã¦ã¼ã¶ä½ææã«é£åãã¦ä½æããã + @author = FactoryGirl.create :author, :user_id => @user.id + @artist = FactoryGirl.create :artist, :author_id => @author.id end describe 'ä¸è¦§è¡¨ç¤ºã«æ¼ãã¦' do @@ -369,7 +370,7 @@ describe ProviderStatusesController do before do ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) ProviderStatusesController.any_instance.stub(:ymd_to_time).with(any_args).and_return(nil) - ProviderStatusesController.any_instance.stub(:export_url).with(any_args).and_return(@ps) + ProviderStatusesController.any_instance.stub(:export_url).with(any_args).and_return('http://localhost:3000/demanders/licenses_export/1.json') ProviderStatusesController.any_instance.stub(:export_from_provider).with(any_args).and_return([@license.attributes]) ProviderLicense.stub(:import).with(any_args).and_return([]) end @@ -383,7 +384,7 @@ describe ProviderStatusesController do end it 'ã¨ã¯ã¹ãã¼ãurlåå¾ãä¾é ¼ãã¦ãã' do ProviderStatusesController.any_instance.stub(:ymd_to_time).with('20111010').and_return(Time.parse('2011/10/10')) - ProviderStatusesController.any_instance.should_receive(:export_url).with(@provider.demander_url, @ps.token, Time.parse('2011/10/10')).exactly(1) + ProviderStatusesController.any_instance.should_receive(:export_url).with(@provider.demander_url, 'licenses_export', @ps.token, Time.parse('2011/10/10')).exactly(1) get :licenses_import, :id => @ps.id, :date => '20111010' end it '貸æããã®ã¨ã¯ã¹ãã¼ããä¾é ¼ãã¦ãã' do @@ -400,7 +401,7 @@ describe ProviderStatusesController do ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) ProviderStatusesController.any_instance.stub(:ymd_to_time).with('20111010').and_return(Time.parse('2011/10/10')) ProviderStatusesController.any_instance.stub(:ymd_to_time).with(any_args).and_return(nil) - ProviderStatusesController.any_instance.stub(:export_url).with(any_args).and_return(@ps) + ProviderStatusesController.any_instance.stub(:export_url).with(any_args).and_return('http://localhost:3000/demanders/licenses_export/1.json') ProviderStatusesController.any_instance.stub(:export_from_provider).with(any_args).and_return([@license.attributes]) ProviderLicense.stub(:import).with(any_args).and_return([]) end @@ -475,4 +476,121 @@ describe ProviderStatusesController do end end + describe '絵師ã¤ã³ãã¼ãã«æ¼ãã¦' do + before do + @ps = FactoryGirl.create :provider_status, :token => 'aaaaaaaaaaaaaaaaa' + @provider = FactoryGirl.create :provider, :provider_status_id => @ps.id + ProviderStatus.stub(:show).and_return(@ps) + sign_in @admin + end + context 'äºåãã§ãã¯ãã¦ãã' do + before do + ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) + ProviderStatusesController.any_instance.stub(:ymd_to_time).with(any_args).and_return(nil) + ProviderStatusesController.any_instance.stub(:export_url).with(any_args).and_return('http://localhost:3000/demanders/artists_export/1.json') + ProviderStatusesController.any_instance.stub(:export_from_provider).with(any_args).and_return([@artist.attributes]) + ProviderArtist.stub(:import).with(any_args).and_return([]) + end + it 'ååç¶æ³ã¢ãã«ã«åä½åå¾ãåãåããã¦ãã' do + ProviderStatus.should_receive(:show).exactly(1) + get :artists_import, :id => @ps.id + end + it 'æ¥ä»æååå¤æãä¾é ¼ãã¦ãã' do + ProviderStatusesController.any_instance.should_receive(:ymd_to_time).with('20111010').exactly(1) + get :licenses_import, :id => @ps.id, :date => '20111010' + end + it 'ã¨ã¯ã¹ãã¼ãurlåå¾ãä¾é ¼ãã¦ãã' do + ProviderStatusesController.any_instance.stub(:ymd_to_time).with('20111010').and_return(Time.parse('2011/10/10')) + ProviderStatusesController.any_instance.should_receive(:export_url).with(@provider.demander_url, 'artists_export', @ps.token, Time.parse('2011/10/10')).exactly(1) + get :artists_import, :id => @ps.id, :date => '20111010' + end + it '貸æããã®ã¨ã¯ã¹ãã¼ããä¾é ¼ãã¦ãã' do + ProviderStatusesController.any_instance.should_receive(:export_from_provider).exactly(1) + get :artists_import, :id => @ps.id + end + it 'çµµå¸«å¯¾ç §è¡¨ã¢ãã«ã«ã¤ã³ãã¼ããä¾é ¼ãã¦ãã' do + ProviderArtist.should_receive(:import).exactly(1) + get :artists_import, :id => @ps.id + end + end + context 'ã¤ã¤ããªãçµããã¨ã' do + before do + ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) + ProviderStatusesController.any_instance.stub(:ymd_to_time).with('20111010').and_return(Time.parse('2011/10/10')) + ProviderStatusesController.any_instance.stub(:ymd_to_time).with(any_args).and_return(nil) + ProviderStatusesController.any_instance.stub(:export_url).with(any_args).and_return('http://localhost:3000/demanders/artists_export/1.json') + ProviderStatusesController.any_instance.stub(:export_from_provider).with(any_args).and_return([@artist.attributes]) + ProviderLicense.stub(:import).with(any_args).and_return([]) + end + it 'ã¹ãã¼ã¿ã¹ã³ã¼ã200 OKãè¿ã' do + get :artists_import, :id => @ps.id + response.should be_success + end + it '@provider_statusã«ååç¶æ³ãåå¾ãã¦ãã' do + get :artists_import, :id => @ps.id + assigns(:provider_status).should eq(@ps) + end + it '@failuresã«ã¤ã³ãã¼ã失æãªã¹ããåå¾ãã¦ãã' do + get :artists_import, :id => @ps.id + assigns(:failures).should eq([]) + end + context 'htmlå½¢å¼' do + it 'artists_importãã³ãã¬ã¼ããæç»ãã' do + get :artists_import, :id => @ps.id + response.should render_template("artists_import") + end + end + context 'jsonå½¢å¼' do + it 'jsonãã¼ã¿ãè¿ã' do + get :artists_import, :id => @ps.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context '管çè 権éããªãã¨ã' do + before do + sign_out @admin + end + context 'htmlå½¢å¼' do + it 'ã¹ãã¼ã¿ã¹ã³ã¼ã302 Foundãè¿ã' do + get :artists_import, :id => @ps.id + response.status.should eq 302 + end + it 'ãµã¤ã³ã¤ã³ãã¼ã¸ã¸é·ç§»ãã' do + get :artists_import, :id => @ps.id + response.body.should redirect_to '/admins/sign_in' + end + end + context 'jsonå½¢å¼' do + it 'ã¹ãã¼ã¿ã¹ã³ã¼ã401 Unauthorizedãè¿ã' do + get :artists_import, :id => @ps.id, :format => :json + response.status.should eq 401 + end + it 'å¿çã¡ãã»ã¼ã¸ã«Unauthorizedãè¿ã' do + get :artists_import, :id => @ps.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context 'åå権éããªãã¨ã' do + before do + ProviderStatus.any_instance.stub(:status).and_return(0) + end + context 'htmlå½¢å¼' do + it 'ä¾å¤403 forbiddenãè¿ã' do + lambda{ + get :artists_import, :id => @ps.id + }.should raise_error(ActiveRecord::Forbidden) + end + end + context 'jsonå½¢å¼' do + it 'ä¾å¤403 forbiddenãè¿ã' do + lambda{ + get :artists_import, :id => @ps.id, :format => :json + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + end + end diff --git a/spec/factories.rb b/spec/factories.rb index 2fe602a5..254b3c9f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -249,4 +249,11 @@ FactoryGirl.define do provider_license.providers_license_id nil provider_license.demanders_license_id nil end + + factory :provider_artist, :class => ProviderArtist do |provider_artist| + provider_artist.provider_id nil + provider_artist.providers_artist_id nil + provider_artist.demanders_artist_id nil + end + end diff --git a/spec/models/artist_spec.rb b/spec/models/artist_spec.rb index 3ea2d45a..c5555215 100644 --- a/spec/models/artist_spec.rb +++ b/spec/models/artist_spec.rb @@ -341,5 +341,22 @@ describe Artist do r.should eq 2 end end + + describe 'ã¨ã¯ã¹ãã¼ãã«æ¼ãã¦' do + before do + @artist = FactoryGirl.create :artist, :author_id => @author.id + @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :updated_at => Time.now - 3000 + @artist3 = FactoryGirl.create :artist, :author_id => nil + end + it 'éå§æ¥æãçç¥ãããå ´åã¯ãã¹ã¦ã®å 絵師ãè¿ã' do + r = Artist.export + r.should eq [@artist, @artist2] + end + it 'éå§æ¥æ以éã«æ´æ°ãããå 絵師ãè¿ã' do + r = Artist.export @artist.updated_at - 100 + r.should eq [@artist] + end + end + end diff --git a/spec/models/demander_spec.rb b/spec/models/demander_spec.rb index 525e7175..638a40a5 100644 --- a/spec/models/demander_spec.rb +++ b/spec/models/demander_spec.rb @@ -9,7 +9,7 @@ describe Demander do @lg = FactoryGirl.create :license_group @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id @user = FactoryGirl.create :user_yas - @author = @user.author #ã¦ã¼ã¶ä½ææã«é£åãã¦ä½æããã + @author = FactoryGirl.create :author, :user_id => @user.id @demand_user = FactoryGirl.create :demand_user end describe 'æ¤è¨¼ã«æ¼ãã¦' do @@ -544,4 +544,51 @@ describe Demander do end end + describe '絵師ã¨ã¯ã¹ãã¼ãã«æ¼ãã¦' do + before do + @ds = FactoryGirl.create :demander_status, :requested_at => Time.now, :approved_at => Time.now, :rejected_at => Time.now, :receive_hour1 => 0, :receive_hour2 => 0 + @demander = FactoryGirl.create :demander, :demander_status_id => @ds.id + @artist = FactoryGirl.create :artist, :author_id => @author.id + end + context 'äºåãã§ãã¯ãã' do + before do + Demander.any_instance.stub(:status).and_return(3) + end + it '絵師ã¢ãã«ã«ã¨ã¯ã¹ãã¼ããä¾é ¼ãã¦ãã' do + Artist.stub(:export).with(nil).and_return([@artist]) + Artist.should_receive(:export).with(nil).exactly(1) + r = @demander.artists_export + end + end + context 'ã¤ã¤ããªãçµããã¨ã' do + before do + Demander.any_instance.stub(:status).and_return(3) + end + it '絵師ãªã¹ããè¿ã' do + Artist.stub(:export).with(Time.parse('2011/10/10')).and_return([@artist]) + r = @demander.artists_export Time.parse('2011/10/10') + r.should eq [@artist] + end + end + context 'æ¥ææå®ããªãã¨ã' do + before do + Demander.any_instance.stub(:status).and_return(3) + end + it 'ãã©ã¡ã¼ã¿ãªãã§ãªã¹ããåå¾ãã' do + Artist.stub(:export).with(nil).and_return([@artist]) + Artist.should_receive(:export).with(nil).exactly(1) + r = @demander.artists_export nil + end + end + #ä¾å¤ã±ã¼ã¹ + context 'ç¶æ ã貸ä¸ä¸ã§ãªãã¨ã' do + it 'ä¾å¤403 ActiveRecord::Forbiddenãçºçããã' do + Demander.any_instance.stub(:status).and_return(2) + lambda{ + r = @demander.artists_export + }.should raise_error(ActiveRecord::Forbidden) + end + end + end + end diff --git a/spec/models/provider_artist_spec.rb b/spec/models/provider_artist_spec.rb new file mode 100644 index 00000000..1f4e2752 --- /dev/null +++ b/spec/models/provider_artist_spec.rb @@ -0,0 +1,187 @@ +# -*- encoding: utf-8 -*- +#çµµå¸«å¯¾ç §è¡¨ +require 'spec_helper' + +describe ProviderArtist do + before do + @admin = FactoryGirl.create :admin + @sp = FactoryGirl.create :system_picture + @lg = FactoryGirl.create :license_group + @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id + @user = FactoryGirl.create :user_yas + @author = FactoryGirl.create :author, :user_id => @user.id + @artist = FactoryGirl.create :artist, :author_id => @author.id + @other_user = FactoryGirl.create :user_yas + @other_author = FactoryGirl.create :author, :user_id => @other_user.id + @provider_status = FactoryGirl.create :provider_status + @provider = FactoryGirl.create :provider, :provider_status_id => @provider_status.id + end + describe 'æ¤è¨¼ã«æ¼ãã¦' do + before do + @pa = FactoryGirl.build :provider_artist, :provider_id => @provider.id, :providers_artist_id => 2, :demanders_artist_id => @artist.id + end + + context 'ãªã¼ã½ããã¯ã¹ãªãã¼ã¿ã®ã¨ã' do + it 'ä¸éãã¼ã¿ãéã' do + @pa.should be_valid + end + it 'ä¸éãã¼ã¿ãéã' do + @pa.should be_valid + end + end + + context 'provider_idãæ¤è¨¼ããã¨ã' do + it 'nullãªã失æãã' do + @pa.provider_id = nil + @pa.should_not be_valid + end + it 'æ°å¤ã§ãªããã°å¤±æãã' do + @pa.provider_id = 'a' + @pa.should_not be_valid + end + it 'åå¨ãã貸æã§ãªããã°å¤±æãã' do + @pa.provider_id = 0 + @pa.should_not be_valid + end + end + context 'providers_artist_idãæ¤è¨¼ããã¨ã' do + it 'nullãªã失æãã' do + @pa.providers_artist_id = nil + @pa.should_not be_valid + end + it 'æ°å¤ã§ãªããã°å¤±æãã' do + @pa.providers_artist_id = 'a' + @pa.should_not be_valid + end + end + context 'demanders_artist_idãæ¤è¨¼ããã¨ã' do + it 'nullãªã失æãã' do + @pa.demanders_artist_id = nil + @pa.should_not be_valid + end + it 'æ°å¤ã§ãªããã°å¤±æãã' do + @pa.demanders_artist_id = 'a' + @pa.should_not be_valid + end + end + end + + describe 'å¯¾ç §è¡¨åå¾ã«æ¼ãã¦' do + before do + @pa = FactoryGirl.create :provider_artist, :provider_id => @provider.id, :providers_artist_id => 2, :demanders_artist_id => @artist.id + end + it 'åå¾ããå¯¾ç §è¡¨ãè¿ã' do + r = ProviderArtist.get_one @provider.id, 2 + r.should be_true + end + it '該å½ããå¯¾ç §è¡¨ãåå¨ããªãã£ãããæ°è¦ã«èããå¯¾ç §è¡¨ãªãã¸ã§ã¯ããè¿ã' do + r = ProviderArtist.get_one @provider.id, 1 + r.should be_a_new ProviderArtist + r = ProviderArtist.get_one 0, 2 + r.should be_a_new ProviderArtist + end + end + + describe '貸æå´çµµå¸«åæã«æ¼ãã¦' do + before do + @pa = FactoryGirl.create :provider_artist, :provider_id => @provider.id, :providers_artist_id => 2, :demanders_artist_id => @artist.id + @newpa = ProviderArtist.new + end + context 'èªèº«ã«çµµå¸«ããªã³ã¯ãã¦ãªãã¨ã' do + before do + end + it '絵師ãªãã¸ã§ã¯ããæ°è¦ã«èã' do + lambda { + r = @newpa.modify_artist @artist.attributes + }.should change Artist, :count + end + end + context 'èªèº«ã«çµµå¸«ããªã³ã¯ãã¦ããã¨ã' do + it 'èªèº«ãã絵師ãåå¾ãã' do + lambda { + r = @pa.modify_artist @artist.attributes + }.should_not change Artist, :count + end + end + it '貸æå´çµµå¸«ã«ã©ã å¤ãã絵師åãã»ãããã 絵師ãªãã¸ã§ã¯ããä¿åãã' do + r = @pa.modify_artist :name => 'artist2' + @artist.reload + @artist.name.should eq 'artist2' + end + it 'ä½å®¶idãã¯ãªã¢ããã(å¤çµµå¸«ã®è¨¼æ)' do + r = @pa.modify_artist :name => 'artist2' + @artist.reload + @artist.author_id.should be_blank + end + it '絵師ãªãã¸ã§ã¯ããè¿ã' do + r = @pa.modify_artist @artist.attributes + r.should eq @artist + end + end + + describe 'ã¤ã³ãã¼ãã«æ¼ãã¦' do + before do + @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :name => 'artist2' + end + context 'äºåãã§ãã¯ãã' do + before do + ProviderArtist.stub(:get_one).with(any_args).and_return(ProviderArtist.new) + ProviderArtist.any_instance.stub(:modify_artist).with(any_args).and_return(@artist) + ProviderArtist.any_instance.stub(:save).with(any_args).and_return(true) + end + it 'å¯¾ç §è¡¨åå¾ãåãåããã¦ãã' do + ProviderArtist.should_receive(:get_one).with(any_args).exactly(1) + r = ProviderArtist.import @provider.id, [@artist.attributes] + end + it 'å¯¾ç §è¡¨ã«çµµå¸«åæãä¾é ¼ãã¦ãã¦ãã' do + ProviderArtist.any_instance.should_receive(:modify_artist).with(any_args).exactly(1) + r = ProviderArtist.import @provider.id, [@artist.attributes] + end + it 'å¯¾ç §è¡¨ãªãã¸ã§ã¯ããä¿åãã¦ãã' do + ProviderArtist.any_instance.should_receive(:save).with(any_args).exactly(1) + r = ProviderArtist.import @provider.id, [@artist.attributes] + end + end + context 'ã¤ã¤ããªãçµããã¨ã' do + it '空ã£ã½ã®é åãè¿ã' do + r = ProviderArtist.import @provider.id, [@artist.attributes] + r.should be_empty + end + it 'å¯¾ç §è¡¨ã追å ããã' do + lambda { + r = ProviderArtist.import @provider.id, [@artist.attributes] + }.should change ProviderArtist, :count + end + end + context 'è¤æ°ã¤ã³ãã¼ãã®ã¨ã' do + it '空ã£ã½ã®é åãè¿ã' do + r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes] + r.should be_empty + end + it 'å¯¾ç §è¡¨ã追å ããã' do + lambda { + r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes] + }.should change(ProviderArtist, :count).by(2) + end + end + #è¦åã±ã¼ã¹ + context 'å¯¾ç §è¡¨ãªãã¸ã§ã¯ãã®ä¿åã«å¤±æããã¨ã' do + before do + ProviderArtist.any_instance.stub(:save).with(any_args).and_return(false) + end + it 'çµæã«è²¸æå´çµµå¸«ã®ã«ã©ã å¤ã追å ãã¦ãã' do + r = ProviderArtist.import @provider.id, [@artist.attributes] + r.should_not be_empty + end + end + context '絵師ãªãã¸ã§ã¯ãã®ä¿åã«å¤±æããã¨ã' do + before do + Artist.any_instance.stub(:save).with(any_args).and_return(false) + end + it 'çµæã«è²¸æå´çµµå¸«ã®ã«ã©ã å¤ã追å ãã¦ãã' do + r = ProviderArtist.import @provider.id, [@artist.attributes] + r.should_not be_empty + end + end + end +end diff --git a/spec/models/provider_license_spec.rb b/spec/models/provider_license_spec.rb index 50501fcf..3983a3f9 100644 --- a/spec/models/provider_license_spec.rb +++ b/spec/models/provider_license_spec.rb @@ -36,7 +36,7 @@ describe ProviderLicense do @pl.provider_id = 'a' @pl.should_not be_valid end - it 'åå¨ãã貸æã¦ã¼ã¶ã§ãªããã°å¤±æãã' do + it 'åå¨ãã貸æã§ãªããã°å¤±æãã' do @pl.provider_id = 0 @pl.should_not be_valid end -- 2.11.0