From: yasushiito Date: Thu, 1 Nov 2012 09:59:11 +0000 (+0900) Subject: t#29983:show panel with license X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=commitdiff_plain;h=a71270cfc4ab2491edc15a281b1ea3780c96f4da t#29983:show panel with license --- diff --git a/app/assets/stylesheets/test.css b/app/assets/stylesheets/test.css index 22e9eb94..8ce454f5 100644 --- a/app/assets/stylesheets/test.css +++ b/app/assets/stylesheets/test.css @@ -15,3 +15,60 @@ div.md5 { font-size: 12px; text-align: left; } + +.pettanr-comic-wrapper { + margin: 1em auto; +} +.pettanr-comic-panel { + border-style: solid; + border-color: #111; + position: relative; + margin: 1em 0; + overflow: hidden; +} +.pettanr-comic-panel img { + position: absolute; +} +.pettanr-comic-balloon { + position: absolute; +} +.pettanr-comic-balloon img { + width: 100%; + height: 100%; } +.pettanr-comic-balloon p { + margin: 0 !important; + padding: 0 !important; display: table; + position: absolute; + top: 0; + left: 16.6%; + width: 66.6%; + height: 100%; + *height: auto; + *top: 50% !important; +} +.pettanr-comic-balloon p span, +.pettanr-comic-balloon p strong, +.pettanr-comic-balloon p em, +.pettanr-comic-balloon p i, +.pettanr-comic-balloon p samp, +.pettanr-comic-balloon p code { + vertical-align: middle; + text-align: center; + font-size: 14px; + display: table-cell; + *display: block; + zoom: 1; + *position: relative; + *top: -50%; +} +.pettanr-comic-balloon p strong { + font-weight: bold; +} +.pettanr-comic-balloon p em, +.pettanr-comic-balloon p i { + font-style: italic; +} +.pettanr-comic-balloon p samp, +.pettanr-comic-balloon p code { + font-family: monospace; +} diff --git a/app/models/panel.rb b/app/models/panel.rb index c69d8797..ce18eecf 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -199,6 +199,14 @@ class Panel < ActiveRecord::Base '[' + ary.map {|i| i.panel_elements_as_json }.join(',') + ']' end + def licensed_pictures + r = {} + ((self.panel_pictures || []) + (self.ground_pictures || [])).compact.each do |elm| + r[elm.picture_id] = elm.picture unless r[elm.picture_id] + end + r + end + def self.visible_count Panel.count end @@ -258,7 +266,7 @@ class Panel < ActiveRecord::Base res end -=begin +=begin def self.validate_id ary, pid ary.map {|v| if pid diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 013ae964..47b293ea 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -13,17 +13,26 @@ class PanelPicture < ActiveRecord::Base validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0} def flip - res = (self.height < 0 ? '' : 'v') + (self.width == 0 ? '' : 'h') + res = (self.height > 0 ? '' : 'v') + (self.width > 0 ? '' : 'h') res += '/' unless res.empty? res end def filename - flip + self.resource_picture.filename + self.flip + self.picture.filename end def url - '/pictures/' + self.picture.filename + '/pictures/' + self.filename + end + + def opt_img_tag + {:src => self.url, :vPicture => self.id, :width => self.width.abs, :height => self.height.abs, :style => "top:#{self.y}px; left:#{self.x}px; z-index:#{self.z}; "} + end + + def tmb_opt_img_tag + tw, th = PettanImager.thumbnail_size(self.width.abs, self.height.abs) + {:src => self.url, :width => tw, :height => th} end def self.default_page_size diff --git a/app/models/story.rb b/app/models/story.rb index 5bfb1958..3a7f329d 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -148,6 +148,14 @@ class Story < ActiveRecord::Base '[' + ary.map {|i| i.story_as_json(au) }.join(',') + ']' end + def self.licensed_pictures stories + r = {} + stories.each do |story| + r.merge! story.panel.licensed_pictures + end + r + end + def self.new_t comic_id r = Story.max_t(comic_id) r.blank? ? 0 : r.to_i + 1 diff --git a/app/views/layouts/test.html.erb b/app/views/layouts/test.html.erb index 39c574aa..017ef840 100644 --- a/app/views/layouts/test.html.erb +++ b/app/views/layouts/test.html.erb @@ -28,7 +28,7 @@

<%= notice %>

<%= alert %>

<%= link_to 'comics', main_app.comics_path %> -<%= link_to 'stories', main_app.stories_path %> +<%= link_to 'stories', main_app.new_story_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 %> diff --git a/app/views/panel_pictures/index.html.erb b/app/views/panel_pictures/index.html.erb index b83fa8b8..d0ba00b4 100644 --- a/app/views/panel_pictures/index.html.erb +++ b/app/views/panel_pictures/index.html.erb @@ -6,12 +6,10 @@ panel picture link - Width - Height - x - y - z + x, y, z t + WidthxHeight + vh updated_at @@ -19,14 +17,12 @@ <%= panel_picture.id %> <%= panel_picture.panel_id %> - <%= panel_picture.picture_id %> + <%= link_to(tag(:img, panel_picture.tmb_opt_img_tag), panel_picture.picture) %> <%= h panel_picture.link %> - <%= panel_picture.x %> - <%= panel_picture.y %> - <%= panel_picture.z %> + <%= panel_picture.x %>, <%= panel_picture.y %>, <%= panel_picture.z %> <%= panel_picture.t %> - <%= panel_picture.width %> - <%= panel_picture.height %> + <%= panel_picture.width %>x<%= panel_picture.height %> + <%= panel_picture.flip %> <%= panel_picture.updated_at %> <% end %> diff --git a/app/views/panel_pictures/list.html.erb b/app/views/panel_pictures/list.html.erb index f87feff7..640c79b6 100644 --- a/app/views/panel_pictures/list.html.erb +++ b/app/views/panel_pictures/list.html.erb @@ -4,7 +4,7 @@ id panel - resource_picture + picture link x y @@ -20,7 +20,7 @@ <%= panel_picture.id %> <%= link_to panel_picture.panel_id, :controller => 'panels', :action => :browse, :id => panel_picture.panel_id%> - <%= link_to panel_picture.resource_picture_id, :controller => 'resource_pictures', :action => :browse, :id => panel_picture.resource_picture_id %> + <%= link_to panel_picture.picture_id, panel_picture.picture %> <%= h panel_picture.link %> <%= panel_picture.x %> <%= panel_picture.y %> diff --git a/app/views/panels/_body.html.erb b/app/views/panels/_body.html.erb new file mode 100644 index 00000000..0b622fa1 --- /dev/null +++ b/app/views/panels/_body.html.erb @@ -0,0 +1,17 @@ +
+ <% panel.panel_elements.each do |elm| %> + <% case elm.class.to_s %> + <% when 'PanelPicture' %> + <%= tag(:img, elm.opt_img_tag) %> + <% when Balloon %> +
+ + <% elm.speeches.each do |speech| %> +

+ <%= h speech.content -%> +

+ <% end %> +
+ <% end ; p elm.class %> + <% end %> +
diff --git a/app/views/panels/_footer.html.erb b/app/views/panels/_footer.html.erb new file mode 100644 index 00000000..b1c8efc6 --- /dev/null +++ b/app/views/panels/_footer.html.erb @@ -0,0 +1,10 @@ + + + + + +
+ <%= panel.width %>x<%= panel.height %> + + <%= panel.updated_at %> +
diff --git a/app/views/panels/_header.html.erb b/app/views/panels/_header.html.erb new file mode 100644 index 00000000..3aed425b --- /dev/null +++ b/app/views/panels/_header.html.erb @@ -0,0 +1,10 @@ + + + + + +
+ ID:<%= link_to panel.id, panel_path(panel) %> + + <%= link_to h(panel.author.name), author_path(panel.author) %> +
diff --git a/app/views/panels/_licensed_pictures.html.erb b/app/views/panels/_licensed_pictures.html.erb new file mode 100644 index 00000000..b00d63b1 --- /dev/null +++ b/app/views/panels/_licensed_pictures.html.erb @@ -0,0 +1,14 @@ +
+ <% licensed_pictures.each do |pid, picture| %> + + + + + +
+ <%= link_to(tag(:img, picture.opt_img_tag), picture_path(picture.id)) -%> + + <%= render picture.credit_template, :picture => picture %> +
+ <% end %> +
diff --git a/app/views/panels/_standard.html.erb b/app/views/panels/_standard.html.erb index 3b4c7dc7..778ac0f3 100644 --- a/app/views/panels/_standard.html.erb +++ b/app/views/panels/_standard.html.erb @@ -1,23 +1,5 @@ -
- <% @panel.panel_elements.each do |elm| %> - <% if elm.kind_of?(PanelPicture) %> - - <% end %> - <% if elm.kind_of?(Balloon) %> -
- - <% elm.speeches.each do |speech| %> -

- <%= h speech.content -%> -

- <% end %> -
- <% end %> - <% end %> -
- -
-
Width:
<%= @panel.width %>
-
Height:
<%= @panel.height %>
-
+<%= render 'panels/header', :panel => panel %> +<%= render 'panels/body', :panel => panel %> +<%= render 'panels/footer', :panel => panel %> +<%= render 'panels/licensed_pictures', :licensed_pictures => panel.licensed_pictures %> diff --git a/app/views/panels/index.html.erb b/app/views/panels/index.html.erb index f209acad..8fd31278 100644 --- a/app/views/panels/index.html.erb +++ b/app/views/panels/index.html.erb @@ -1,21 +1,6 @@

Listing panels 最近の投稿

<% @panels.each do |panel| %> -
-
- <% panel.panel_pictures.each do |panel_picture| %> -
- -
- <% end %> - <% (panel.speech_balloons || []).each do |sb| %> - <% (sb.balloons || []).each do |balloon| %> - <% end %> - <% (sb.speeches || []).each do |speech| %> - <% end %> - <% end %> -
- <%= h panel.author.name %> <%= panel.updated_at %> -
+ <%= render 'standard', :panel => panel %> <% end %> <%= link_to 'open form', new_panel_path, :remote => true %>
diff --git a/app/views/panels/show.html.erb b/app/views/panels/show.html.erb index df3247a1..02df25fc 100644 --- a/app/views/panels/show.html.erb +++ b/app/views/panels/show.html.erb @@ -10,6 +10,6 @@
<% end %>

<%= notice %>

-<%= render 'standard' %> +<%= render 'standard', :panel => @panel %> <%= link_to 'Back', panels_path %> diff --git a/app/views/stories/_footer.html.erb b/app/views/stories/_footer.html.erb new file mode 100644 index 00000000..d850cd89 --- /dev/null +++ b/app/views/stories/_footer.html.erb @@ -0,0 +1,10 @@ + + + + + +
+ <%= story.panel.width %>x<%= story.panel.height %> + + <%= story.panel.updated_at %> +
diff --git a/app/views/stories/_header.html.erb b/app/views/stories/_header.html.erb new file mode 100644 index 00000000..103f9608 --- /dev/null +++ b/app/views/stories/_header.html.erb @@ -0,0 +1,13 @@ + + + + + + +
+ No.<%= link_to story.t, story_path(story) %> + + <%= link_to h(story.panel.author.name), author_path(story.panel.author) %> + + ID:<%= link_to story.panel.id, panel_path(story.panel) %> +
diff --git a/app/views/stories/_licensed_pictures.html.erb b/app/views/stories/_licensed_pictures.html.erb new file mode 100644 index 00000000..b00d63b1 --- /dev/null +++ b/app/views/stories/_licensed_pictures.html.erb @@ -0,0 +1,14 @@ +
+ <% licensed_pictures.each do |pid, picture| %> + + + + + +
+ <%= link_to(tag(:img, picture.opt_img_tag), picture_path(picture.id)) -%> + + <%= render picture.credit_template, :picture => picture %> +
+ <% end %> +
diff --git a/app/views/stories/_order.html.erb b/app/views/stories/_order.html.erb new file mode 100644 index 00000000..9cc6dd41 --- /dev/null +++ b/app/views/stories/_order.html.erb @@ -0,0 +1,28 @@ +<%= form_for(@story) do |f| %> + <% if @story.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.hidden_field :comic_id %> +
+
+ <%= f.number_field :t %> +
+
+ <%= f.hidden_field :panel_id %> +
+ +
+ <%= f.submit %> +
+<% end %> +<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %> diff --git a/app/views/stories/comic.html.erb b/app/views/stories/comic.html.erb index dfa9effb..2801f31f 100644 --- a/app/views/stories/comic.html.erb +++ b/app/views/stories/comic.html.erb @@ -2,21 +2,19 @@ <% @stories.each do |story| %> <% @story = story %> - <% @panel = story.panel %> - <%= render 'panels/standard' %> - <% if story.author.id == @author.id -%> - - t:<%= story.t %> - -<%= button_to 'Destroy', @story, confirm: 'Are you sure?', method: :delete %> - <%= render 'editform' %> - <%= link_to 'open js', edit_story_path(story), :remote => true %> -
+ <%= render 'header', :story => story %> + <%= render 'panels/body', :panel => story.panel %> + <%= render 'footer', :story => story %> + <% if story.own? @author -%> + <%= link_to 'move', edit_story_path(story), :remote => true %> + t -
+ <% end -%> <% end %> -<% if @comic.author.id == @author.id -%> +<%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %> +

<%= h @comic.title %>

+<% if @comic.own? @author -%> <%= link_to 'add panel', new_story_path, :remote => true %>
t diff --git a/app/views/stories/edit.js.erb b/app/views/stories/edit.js.erb new file mode 100644 index 00000000..29c687f7 --- /dev/null +++ b/app/views/stories/edit.js.erb @@ -0,0 +1 @@ +$("#story-update-<%= @story.id -%>").html("<%= escape_javascript(render('editform')) -%>"); diff --git a/app/views/stories/show.html.erb b/app/views/stories/show.html.erb index 9fe43d21..0122e4a9 100644 --- a/app/views/stories/show.html.erb +++ b/app/views/stories/show.html.erb @@ -1,5 +1,4 @@ - <% @panel = @story.panel %> - <%= render 'panels/standard' %> + <%= render 'panels/standard', :panel => @story.panel %> <% if @story.author.id == @author.id -%> t:<%= @story.t %> diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index 15224c77..03ac3d1a 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' #コマ describe Panel do before do - @admin = FactoryGirl.create :admin + @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 - @color = FactoryGirl.create :color + @color = FactoryGirl.create :color @user = FactoryGirl.create( :user_yas) @author = @user.author @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @@ -25,29 +25,29 @@ describe Panel do @panel = FactoryGirl.build :panel, :author_id => @author.id end - context 'オーソドックスなデータのとき' do - it '下限データが通る' do - @panel.width = 1 - @panel.height = 1 - @panel.border = 0 - @panel.x = -99999 - @panel.y = -99999 - @panel.z = 1 - @panel.publish = 0 - @panel.should be_valid - end - it '上限データが通る' do - @panel.width = 99999 - @panel.height = 99999 - @panel.border = 99999 - @panel.x = 99999 - @panel.y = 99999 - @panel.z = 99999 - @panel.publish = 99999 - @panel.should be_valid - end - end - + context 'オーソドックスなデータのとき' do + it '下限データが通る' do + @panel.width = 1 + @panel.height = 1 + @panel.border = 0 + @panel.x = -99999 + @panel.y = -99999 + @panel.z = 1 + @panel.publish = 0 + @panel.should be_valid + end + it '上限データが通る' do + @panel.width = 99999 + @panel.height = 99999 + @panel.border = 99999 + @panel.x = 99999 + @panel.y = 99999 + @panel.z = 99999 + @panel.publish = 99999 + @panel.should be_valid + end + end + context 'widthを検証するとき' do it 'nullなら失敗する' do @panel.width = nil @@ -220,56 +220,56 @@ describe Panel do before do @panel = FactoryGirl.create :panel, :author_id => @author.id end - context '検査対象がnil(ゲスト)のとき' do - context 'クローズドモードのとき' do - before do - MagicNumber['run_mode'] = 1 - end + context '検査対象がnil(ゲスト)のとき' do + context 'クローズドモードのとき' do + before do + MagicNumber['run_mode'] = 1 + end it '不許可を返す。' do - r = @panel.visible?(nil) - r.should be_false + r = @panel.visible?(nil) + r.should be_false end end - context 'オープンモードのとき' do - before do - MagicNumber['run_mode'] = 0 - end + context 'オープンモードのとき' do + before do + MagicNumber['run_mode'] = 0 + end it '公開コマなら許可する' do Panel.any_instance.stub(:publish?).and_return(true) - r = @panel.visible?(nil) - r.should be_true + r = @panel.visible?(nil) + r.should be_true end it '非公開コマなら許可しない' do Panel.any_instance.stub(:publish?).and_return(false) - r = @panel.visible?(nil) - r.should be_false + r = @panel.visible?(nil) + r.should be_false end end end - context '検査対象が作家のとき' do + context '検査対象が作家のとき' do it '自分のコマなら許可する' do Panel.any_instance.stub(:own?).and_return(true) Panel.any_instance.stub(:publish?).and_return(true) - r = @panel.visible?(@author) - r.should == true + r = @panel.visible?(@author) + r.should == true end it '他人の非公開コマなら許可しない' do Panel.any_instance.stub(:own?).and_return(false) Panel.any_instance.stub(:publish?).and_return(false) - r = @panel.visible?(@author) - r.should == false + r = @panel.visible?(@author) + r.should == false end it '他人のコマでも公開なら許可する' do Panel.any_instance.stub(:own?).and_return(false) Panel.any_instance.stub(:publish?).and_return(true) - r = @panel.visible?(@author) - r.should == true + r = @panel.visible?(@author) + r.should == true end end - context '検査対象がそれ以外のとき' do + context '検査対象がそれ以外のとき' do it '不許可を返す。' do - r = @panel.visible?(@admin) - r.should be_false + r = @panel.visible?(@admin) + r.should be_false end end end @@ -308,7 +308,7 @@ describe Panel do r.should eq [@panel] end it '時系列で並んでいる' do - #公開コミックは(他人のコミックであっても)含んでいる + #公開コミックは(他人のコミックであっても)含んでいる npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 r = Panel.list r.should eq [npl, @panel] @@ -344,19 +344,19 @@ describe Panel do pl.should eq [@panel] end end - context 'DBに5件あって1ページの件数を2件に変えたとして' do - before do + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 Panel.stub(:default_page_size).and_return(2) - end - it '件数0は全件(5件)を返す' do - r = Panel.list 5, 0 - r.should have(5).items - end - end + end + it '件数0は全件(5件)を返す' do + r = Panel.list 5, 0 + r.should have(5).items + end + end end describe '一覧取得オプションに於いて' do it 'includeキーを含んでいる' do @@ -454,13 +454,13 @@ describe Panel do pl = Panel.mylist @author pl.should eq [npl, @panel] end - context 'DBに5件あって1ページの件数を2件に変えたとして' do - before do + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 - end + end it '通常は2件を返す' do pl = Panel.list 1, 2 pl.should have(2).items @@ -478,20 +478,20 @@ describe Panel do pl = Panel.mylist @author, 3, 2 pl.should eq [@panel] end - end - context 'DBに5件あって1ページの件数を0件に変えたとして' do - before do + end + context 'DBに5件あって1ページの件数を0件に変えたとして' do + before do @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200 @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300 @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400 Author.stub(:default_panel_page_size).and_return(2) - end - it '通常は全件(5件)を返す' do - r = Panel.mylist @author, 5, 0 - r.should have(5).items - end - end + end + it '通常は全件(5件)を返す' do + r = Panel.mylist @author, 5, 0 + r.should have(5).items + end + end end describe '単体取得に於いて' do @@ -502,12 +502,12 @@ describe Panel do it '単体取得オプションを利用している' do Panel.stub(:show_opt).with(any_args).and_return({}) Panel.should_receive(:show_opt).with(any_args).exactly(1) - r = Panel.show @panel.id, @author + r = Panel.show @panel.id, @author end it '閲覧許可を問い合わせている' do Panel.any_instance.stub(:visible?).with(any_args).and_return(true) Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1) - r = Panel.show @panel.id, @author + r = Panel.show @panel.id, @author end end it '指定のコマを返す' do @@ -539,12 +539,12 @@ describe Panel do it '単体取得オプションを利用している' do Panel.stub(:show_opt).with(any_args).and_return({}) Panel.should_receive(:show_opt).with(any_args).exactly(1) - r = Panel.edit @panel.id, @author + r = Panel.edit @panel.id, @author end it '所持判定を問い合わせている' do Panel.any_instance.stub(:own?).with(any_args).and_return(true) Panel.any_instance.should_receive(:own?).with(any_args).exactly(1) - r = Panel.edit @panel.id, @author + r = Panel.edit @panel.id, @author end end it '指定のコマを返す' do @@ -932,6 +932,42 @@ describe Panel do j.first.has_key?('p').should be_true end end + + describe 'ライセンス素材に於いて' do + before do + #コマを作成しておく。 + @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id + @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id + @sb = @panel.speech_balloons.create( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id) + ) + @pc = @panel.panel_colors.create( + FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + ) + @panel.reload + end + context '事前チェック' do + end + context 'つつがなく終わるとき' do + end + it '連想配列(値は実素材、キーは実素材id)を返している' do + r = @panel.licensed_pictures + r.is_a?(Hash).should be_true + r.should have(2).items + r[@pp.picture_id].should eq @p + r[@gp.picture_id].should eq @p2 + end + end + describe '検証値収集に於いて' do context 'つつがなく終わるとき' do it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do @@ -1063,8 +1099,8 @@ describe Panel do describe '保存に於いて' do before do @attr = FactoryGirl.attributes_for :panel - @panel = Panel.new - @panel.supply_default + @panel = Panel.new + @panel.supply_default end context 'つつがなく終わるとき' do before do diff --git a/spec/models/story_spec.rb b/spec/models/story_spec.rb index 5983b871..0974b9ea 100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@ -13,10 +13,10 @@ describe Story do @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @other_user = FactoryGirl.create( :user_yas) @other_author = @other_user.author - @op = FactoryGirl.create :original_picture, :artist_id => @artist.id - @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id - @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id - @sbt = FactoryGirl.create :speech_balloon_template + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + @sbt = FactoryGirl.create :speech_balloon_template end describe '検証に於いて' do @@ -152,66 +152,66 @@ describe Story do end end - describe '閲覧許可に於いて' do - before do + describe '閲覧許可に於いて' do + before do @comic = FactoryGirl.create :comic, :author_id => @author.id @panel = FactoryGirl.create :panel, :author_id => @author.id @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id - end + end context '検査対象がnil(ゲスト)のとき' do context 'クローズドモードのとき' do before do MagicNumber['run_mode'] = 1 end - it '不許可を返す。' do + it '不許可を返す。' do r = @story.visible?(nil) r.should be_false - end - end + end + end context 'オープンモードのとき' do before do MagicNumber['run_mode'] = 0 end - it '公開コミックのストーリーなら許可する' do - Comic.any_instance.stub(:visible?).with(nil).and_return(true) + it '公開コミックのストーリーなら許可する' do + Comic.any_instance.stub(:visible?).with(nil).and_return(true) r = @story.visible?(nil) r.should be_true - end - it '非公開コミックのストーリーなら許可しない' do - Comic.any_instance.stub(:visible?).with(nil).and_return(false) + end + it '非公開コミックのストーリーなら許可しない' do + Comic.any_instance.stub(:visible?).with(nil).and_return(false) r = @story.visible?(nil) r.should be_false - end - end - end + end + end + end context '検査対象が作家のとき' do - it '自分のコミックのストーリーなら許可する' do - Comic.any_instance.stub(:own?).with(@author).and_return(true) - Comic.any_instance.stub(:visible?).with(@author).and_return(true) + it '自分のコミックのストーリーなら許可する' do + Comic.any_instance.stub(:own?).with(@author).and_return(true) + Comic.any_instance.stub(:visible?).with(@author).and_return(true) r = @story.visible?(@author) r.should == true - end - it '他人の非公開コミックのストーリーなら許可しない' do - Comic.any_instance.stub(:own?).with(@other_author).and_return(false) - Comic.any_instance.stub(:visible?).with(@other_author).and_return(false) + end + it '他人の非公開コミックのストーリーなら許可しない' do + Comic.any_instance.stub(:own?).with(@other_author).and_return(false) + Comic.any_instance.stub(:visible?).with(@other_author).and_return(false) r = @story.visible?(@other_author) r.should == false - end - it '他人のコミックのストーリーでも公開なら許可する' do - Comic.any_instance.stub(:own?).with(@other_author).and_return(false) - Comic.any_instance.stub(:visible?).with(@other_author).and_return(true) + end + it '他人のコミックのストーリーでも公開なら許可する' do + Comic.any_instance.stub(:own?).with(@other_author).and_return(false) + Comic.any_instance.stub(:visible?).with(@other_author).and_return(true) r = @story.visible?(@other_author) r.should == true - end - end + end + end context '検査対象がそれ以外のとき' do - it '不許可を返す。' do + it '不許可を返す。' do r = @story.visible?(@admin) r.should be_false - end - end - end - + end + end + end + describe '一覧取得に於いて' do before do @comic = FactoryGirl.create :comic, :author_id => @author.id @@ -371,13 +371,13 @@ describe Story do @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 end - context 'つつがなく終わるとき' do - it '一覧取得オプションを利用している' do - Story.stub(:list_opt).with(any_args).and_return({}) - Story.should_receive(:list_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + Story.stub(:list_opt).with(any_args).and_return({}) + Story.should_receive(:list_opt).with(any_args).exactly(1) r = Story.mylist @author - end - end + end + end it 'リストを返す' do s = Story.mylist @author s.should eq [@story] @@ -428,7 +428,7 @@ describe Story do @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400 - Author.stub(:default_story_size).and_return(2) + Author.stub(:default_story_size).and_return(2) end it '通常は全件(5件)を返す' do r = Story.mylist @author, 5, 0 @@ -443,18 +443,18 @@ describe Story do @panel = FactoryGirl.create :panel, :author_id => @author.id @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id end - context 'つつがなく終わるとき' do - it '単体取得オプションを利用している' do - Story.stub(:show_opt).with(any_args).and_return({}) - Story.should_receive(:show_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Story.stub(:show_opt).with(any_args).and_return({}) + Story.should_receive(:show_opt).with(any_args).exactly(1) r = Story.show @story.id, @author - end - it '閲覧許可を問い合わせている' do - Story.any_instance.stub(:visible?).with(@author).and_return(true) - Story.any_instance.should_receive(:visible?).with(@author).exactly(1) + end + it '閲覧許可を問い合わせている' do + Story.any_instance.stub(:visible?).with(@author).and_return(true) + Story.any_instance.should_receive(:visible?).with(@author).exactly(1) r = Story.show @story.id, @author - end - end + end + end it '指定のストーリーを返す' do l = Story.show @story.id, @author l.should eq @story @@ -482,18 +482,18 @@ describe Story do @panel = FactoryGirl.create :panel, :author_id => @author.id @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id end - context 'つつがなく終わるとき' do - it '単体取得オプションを利用している' do - Story.stub(:show_opt).with(any_args).and_return({}) - Story.should_receive(:show_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + Story.stub(:show_opt).with(any_args).and_return({}) + Story.should_receive(:show_opt).with(any_args).exactly(1) r = Story.edit @story.id, @author - end - it '所持判定を問い合わせている' do - Story.any_instance.stub(:own?).with(any_args).and_return(true) - Story.any_instance.should_receive(:own?).with(any_args).exactly(1) + end + it '所持判定を問い合わせている' do + Story.any_instance.stub(:own?).with(any_args).and_return(true) + Story.any_instance.should_receive(:own?).with(any_args).exactly(1) r = Story.edit @story.id, @author - end - end + end + end it '指定のストーリーを返す' do l = Story.edit @story.id, @author l.should eq @story @@ -577,94 +577,124 @@ describe Story do end describe 'ストーリーのjson出力に於いて' do - before do - #コマを作成しておく。 - @panel = FactoryGirl.create :panel, :author_id => @author.id - @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height - @sb = @panel.speech_balloons.create( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) - ) - @gc = @panel.ground_colors.create( - FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id) - ) - @gp = @panel.ground_pictures.create( - FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id) - ) - @pc = @panel.panel_colors.create( - FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) - ) - @panel.reload + before do + #コマを作成しておく。 + @panel = FactoryGirl.create :panel, :author_id => @author.id + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height + @sb = @panel.speech_balloons.create( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) + ) + @gc = @panel.ground_colors.create( + FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id) + ) + @gp = @panel.ground_pictures.create( + FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id) + ) + @pc = @panel.panel_colors.create( + FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000) + ) + @panel.reload @comic = FactoryGirl.create :comic, :author_id => @author.id @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id - end + end context '事前チェックする' do - before do + before do Panel.any_instance.stub(:elements).and_return('{}') - end - it 'コマ要素のjson出力を依頼している' do + end + it 'コマ要素のjson出力を依頼している' do Panel.any_instance.stub(:visible?).with(any_args).and_return(true) - Panel.any_instance.should_receive(:elements).with(any_args).exactly(1) + Panel.any_instance.should_receive(:elements).with(any_args).exactly(1) r = @story.story_as_json @author - end - end - it 'json textを返している' do - r = JSON.parse @story.story_as_json(@author) - r.is_a?(Hash).should be_true - end - it 'comic,author,panel,コマ要素を含んでいる' do - r = JSON.parse @story.story_as_json(@author) - r.has_key?('comic').should be_true - r['comic'].has_key?('author').should be_true - r.has_key?('author').should be_true - r.has_key?('panel').should be_true - r['panel'].has_key?('author').should be_true - end + end + end + it 'json textを返している' do + r = JSON.parse @story.story_as_json(@author) + r.is_a?(Hash).should be_true + end + it 'comic,author,panel,コマ要素を含んでいる' do + r = JSON.parse @story.story_as_json(@author) + r.has_key?('comic').should be_true + r['comic'].has_key?('author').should be_true + r.has_key?('author').should be_true + r.has_key?('panel').should be_true + r['panel'].has_key?('author').should be_true + end context 'コマ閲覧許可のとき' do - before do + before do Panel.any_instance.stub(:visible?).with(any_args).and_return(true) - end - it 'コマ要素にコマ要素を追加している' do - r = JSON.parse @story.story_as_json(@author) - r['panel'].has_key?('elements').should be_true - r['panel']['elements'].should_not be_empty - end - end + end + it 'コマ要素にコマ要素を追加している' do + r = JSON.parse @story.story_as_json(@author) + r['panel'].has_key?('elements').should be_true + r['panel']['elements'].should_not be_empty + end + end context 'コマ閲覧不許可のとき' do - before do + before do Panel.any_instance.stub(:visible?).with(any_args).and_return(false) - end - it 'コマ要素にデータを含ませない' do - r = JSON.parse @story.story_as_json(@author) - r['panel'].has_key?('elements').should be_false - end - end + end + it 'コマ要素にデータを含ませない' do + r = JSON.parse @story.story_as_json(@author) + r['panel'].has_key?('elements').should be_false + end + end end - describe 'ストーリーリストのjson出力に於いて' do - before do - @panel = FactoryGirl.create :panel, :author_id => @author.id + describe 'ストーリーリストのjson出力に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id @comic = FactoryGirl.create :comic, :author_id => @author.id @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id - Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}') - end - context 'つつがなく終わるとき' do - it 'ストーリーのjson出力を依頼している' do - Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1) - r = Story.list_as_json_text [@story], @author - end - end - it 'json textを返している' do - r = Story.list_as_json_text [@story], @author - j = JSON.parse r - j.is_a?(Array).should be_true - end - it 'ストーリーを含んでいる' do - r = Story.list_as_json_text [@story], @author + Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}') + end + context 'つつがなく終わるとき' do + it 'ストーリーのjson出力を依頼している' do + Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1) + r = Story.list_as_json_text [@story], @author + end + end + it 'json textを返している' do + r = Story.list_as_json_text [@story], @author + j = JSON.parse r + j.is_a?(Array).should be_true + end + it 'ストーリーを含んでいる' do + r = Story.list_as_json_text [@story], @author j = JSON.parse r - j.first.has_key?('s').should be_true - end + j.first.has_key?('s').should be_true + end + end + + describe 'ライセンス素材に於いて' do + before do + #コマを作成しておく。 + @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id + @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id + @panel = FactoryGirl.create :panel, :author_id => @author.id + @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id + @panel.reload + @panel2 = FactoryGirl.create :panel, :author_id => @author.id + @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id + @panel2.reload + + @comic = FactoryGirl.create :comic, :author_id => @author.id + @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id + @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id + end + context '事前チェック' do + end + context 'つつがなく終わるとき' do + end + it '連想配列(値は実素材、キーは実素材id)を返している' do + r = Story.licensed_pictures [@story, @story2] + r.is_a?(Hash).should be_true + r.should have(2).items + r[@pp.picture_id].should eq @p + r[@pp2.picture_id].should eq @p2 + end end - + describe 't補充値に於いて' do before do @comic = FactoryGirl.create :comic, :author_id => @author.id