From 9f6a95c6c89ca7d7671fa019f122e31215aa1bcd Mon Sep 17 00:00:00 2001 From: yasushiito Date: Wed, 26 Sep 2012 08:34:13 +0900 Subject: [PATCH] t#29400 --- app/controllers/ground_pictures_controller.rb | 2 +- app/controllers/home_controller.rb | 2 +- app/controllers/original_pictures_controller.rb | 5 +- app/controllers/panels_controller.rb | 24 +- .../speech_balloon_templates_controller.rb | 1 + app/controllers/stories_controller.rb | 25 +- app/models/original_picture.rb | 2 +- app/models/panel.rb | 324 +++-- app/models/resource_picture.rb | 2 +- app/models/story.rb | 45 +- app/views/comics/_form.html.erb | 2 +- app/views/comics/index.html.erb | 2 +- app/views/layouts/test.html.erb | 4 +- app/views/speech_balloon_templates/index.html.erb | 20 +- app/views/stories/comic.html.erb | 25 + app/views/stories/show.html.erb | 12 +- config/routes.rb | 1 + spec/cli/u/comics/create.json | 2 +- spec/cli/u/original_pictures/create.json | 2 +- spec/cli/u/panels/create.json | 2 +- spec/cli/u/stories/create.json | 2 +- spec/controllers/home_controller_spec.rb | 4 - spec/controllers/panels_controller_spec.rb | 88 +- spec/controllers/stories_controller_spec.rb | 254 +++- spec/models/comic_spec.rb | 2 +- spec/models/panel_picture_spec.rb | 2 +- spec/models/panel_spec.rb | 1285 +++++++++++--------- spec/models/story_spec.rb | 211 ++-- 28 files changed, 1362 insertions(+), 990 deletions(-) create mode 100644 app/views/stories/comic.html.erb diff --git a/app/controllers/ground_pictures_controller.rb b/app/controllers/ground_pictures_controller.rb index 28de1711..aa23e7f0 100644 --- a/app/controllers/ground_pictures_controller.rb +++ b/app/controllers/ground_pictures_controller.rb @@ -7,7 +7,7 @@ class GroundPicturesController < ApplicationController def index @page = GroundPicture.page params[:page] @page_size = GroundPicture.page_size params[:page_size] - @ground_pictures = GroundPicture.list({}, @page, @page_size) + @ground_pictures = GroundPicture.list(@page, @page_size) respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index baf93000..9d296c1f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -86,7 +86,7 @@ class HomeController < ApplicationController respond_to do |format| format.html # index.html.erb - format.json { render json: @panels.to_json(Panel.list_json_opt) } + format.json { render json: @panels.to_json() } end end diff --git a/app/controllers/original_pictures_controller.rb b/app/controllers/original_pictures_controller.rb index 1896730c..6cd34004 100644 --- a/app/controllers/original_pictures_controller.rb +++ b/app/controllers/original_pictures_controller.rb @@ -109,11 +109,12 @@ class OriginalPicturesController < ApplicationController # PUT /original_pictures/1 # PUT /original_pictures/1.json def update - @picture_data = set_image params[:original_picture][:file] + @imager = PettanImager.load set_image params[:original_picture][:file] @original_picture = OriginalPicture.edit(params[:id], @author) + @original_picture.overwrite @artist respond_to do |format| - if @original_picture.store(@picture_data, @artist) + if @original_picture.store(@imager) format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' } format.json { render json: @original_picture.to_json(OriginalPicture.show_json_opt), status: :created, location: @original_picture } else diff --git a/app/controllers/panels_controller.rb b/app/controllers/panels_controller.rb index 29390ce4..a138cbaf 100644 --- a/app/controllers/panels_controller.rb +++ b/app/controllers/panels_controller.rb @@ -10,11 +10,11 @@ class PanelsController < ApplicationController def index @page = Panel.page params[:page] @page_size = Panel.page_size params[:page_size] - @panels = Panel.list({}, @page, @page_size) + @panels = Panel.list(@page, @page_size) respond_to do |format| format.html # index.html.erb - format.json { render json: @panels.to_json(Panel.list_json_opt) } + format.json { render text: '[' + @panels.map {|i| i.panel_elements_as_json }.join(',') + ']' } end end @@ -25,9 +25,9 @@ class PanelsController < ApplicationController respond_to do |format| format.html # show.html.erb - format.json { render json: @panel.to_json(Panel.show_json_include_opt) } + format.json { render json: @panel.panel_elements_as_json } format.jsonp { - render :json => "callback(" + @panel.to_json(Panel.show_json_include_opt) + ");" + render :json => "callback(" + @panel.panel_elements_as_json + ");" } end end @@ -63,7 +63,7 @@ class PanelsController < ApplicationController respond_to do |format| format.html # new.html.erb format.js - format.json { render json: @panel } + format.json { render json: @panel.panel_elements_as_json } end end @@ -80,16 +80,15 @@ class PanelsController < ApplicationController def create @panel = Panel.new @panel.supply_default + jsn = nil if params[:json] - jsn = JSON.parse(params[:json]) + jsn = JSON.parse_no_except(params[:json]) end @prm = params[:panel] || jsn - @panel.attributes = @prm - @panel.overwrite @author respond_to do |format| - if @panel.store + if @panel.store @prm, @author format.html { redirect_to @panel, notice: 'Panel was successfully created.' } - format.json { render json: @panel, status: :created, location: @panel } + format.json { render json: @panel.panel_elements_as_json, status: :created, location: @panel } else format.html { render action: "new" } format.json { render json: @panel.errors, status: :unprocessable_entity } @@ -101,14 +100,13 @@ class PanelsController < ApplicationController # PUT /panels/1.json def update @panel = Panel.edit(params[:id], @author) + jsn = nil if params[:json] jsn = JSON.parse(params[:json]) end @prm = params[:panel] || jsn - @panel.attributes = @prm - @panel.overwrite @author respond_to do |format| - if @panel.store + if @panel.store @prm, @author format.html { redirect_to @panel, notice: 'Panel was successfully updated.' } format.json { head :ok } else diff --git a/app/controllers/speech_balloon_templates_controller.rb b/app/controllers/speech_balloon_templates_controller.rb index 1cbe2b8f..b84c68af 100644 --- a/app/controllers/speech_balloon_templates_controller.rb +++ b/app/controllers/speech_balloon_templates_controller.rb @@ -1,4 +1,5 @@ class SpeechBalloonTemplatesController < ApplicationController + layout 'test' if Pettanr::TestLayout before_filter :authenticate_user!, :only => [:index, :show] before_filter :authenticate_admin!, :only => [:list, :browse, :destroy] diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 4f41dc16..adbbc203 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -3,20 +3,29 @@ class StoriesController < ApplicationController if Const.run_mode == 0 before_filter :authenticate_user!, :only => [:new, :create, :edit, :update, :destroy] else - before_filter :authenticate_user!, :only => [:index, :show, :new, :create, :edit, :update, :destroy] + before_filter :authenticate_user!, :only => [:index, :show, :comic, :new, :create, :edit, :update, :destroy] end before_filter :authenticate_admin!, :only => [:list, :browse] def show + @story = Story.show(params[:id], @author) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @story.story_as_json(@author) } + end + end + + def comic @comic = Comic.show(params[:id], @author) cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i @offset = Story.offset cnt, params[:offset] @panel_count = Story.panel_count cnt, params[:count] - @stories = Story.list(@comic, @author, @offset, @panel_count) + @stories = Story.play_list(@comic, @author, @offset, @panel_count) respond_to do |format| format.html # index.html.erb format.json { - render :json => @stories.to_json_list + render :json => '[' + @stories.map {|i| i.story_as_json(@author)}.join(',') + ']' } format.jsonp { render :json => "callback(" + @stories.to_json_list + ");" @@ -51,7 +60,7 @@ class StoriesController < ApplicationController respond_to do |format| format.html # new.html.erb format.js - format.json { render json: @story } + format.json { render json: @story.story_as_json(@author) } end end @@ -72,11 +81,13 @@ class StoriesController < ApplicationController @story.supply_default @story.attributes = params[:story] @story.overwrite @author + @comic = Comic.edit(@story.comic_id, @author) + @panel = Panel.show(@story.panel_id, @author) respond_to do |format| if @story.store - format.html { redirect_to action: :show, id: @story.comic_id } - format.json { render json: @story.to_json() } + format.html { redirect_to action: :comic, id: @story.comic_id } + format.json { render json: @story.story_as_json(@author) } else format.html { render action: "new" } format.json { render json: @story.errors, status: :unprocessable_entity } @@ -93,7 +104,7 @@ class StoriesController < ApplicationController @story.overwrite @author respond_to do |format| if @story.store ot - format.html { redirect_to action: :show, id: @story.comic_id } + format.html { redirect_to action: :comic, id: @story.comic_id } format.json { head :ok } else format.html { render action: "edit" } diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index bd776a68..534e337a 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -41,7 +41,7 @@ class OriginalPicture < ActiveRecord::Base end def opt_img_tag - tw, th = ResourcePicture.fix_size_both(MagicNumber['thumbnail_width'], MagicNumber['thumbnail_height'], self.width, self.height) + tw, th = PettanImager.thumbnail_size(self.width, self.height) {:src => self.url, :width => tw, :height => th} end diff --git a/app/models/panel.rb b/app/models/panel.rb index db740ffa..e9424b1f 100644 --- a/app/models/panel.rb +++ b/app/models/panel.rb @@ -21,91 +21,33 @@ class Panel < ActiveRecord::Base validates :y, :numericality => {:allow_blank => true} validates :z, :numericality => {:allow_blank => true, :greater_than => 0} validates :author_id, :presence => true, :numericality => true, :existence => true + validates :publish, :presence => true, :numericality => true def supply_default self.border = 2 + self.publish = 0 end def overwrite au - return false unless au self.author_id = au.id end - def self.collect_element_value elements, name, ex_nil = false - e = elements.map {|e| - e.map {|o| - o[name] - } - }.flatten - e = e.compact if ex_nil - e - end - - def self.validate_id ary, pid - ary.map {|v| - if pid - (v == pid or v == nil) ? nil : false - else - v ? false : nil - end - }.compact.empty? - end - - def self.validate_element_id elements, name, pid - Panel.validate_id(Panel.collect_element_value(elements, name), pid) - end - - def self.validate_elements_id c - c.map {|conf| - Panel.validate_element_id(conf[:elements], conf[:name], conf[:parent_id]) ? nil : false - }.compact.empty? - end - - def self.validate_t ary - i = 0 - ary.compact.sort.each do |t| - break false unless t == i - i += 1 - end - ary.compact.size == i - end - - def self.validate_element_t elements, name - Panel.validate_t(Panel.collect_element_value(elements, name, true)) - end - - def self.validate_elements_t c - c.map {|conf| - Panel.validate_element_t(conf[:elements], conf[:name]) ? nil : false - }.compact.empty? + def visible? au + return false unless au + self.own?(au) or self.publish? end - def validate_id_list - r = self.speech_balloons.map {|sb| - {:elements => [sb.speeches, sb.balloons], :name => :speech_balloon_id, :parent_id => sb.id} - } - r.unshift({:elements => [self.panel_pictures, self.speech_balloons], :name => :panel_id, :parent_id => self.id}) - r + def own? au + return false unless au + self.author_id == au.id end - def validate_child - r1 = Panel.validate_elements_id validate_id_list - r2 = Panel.validate_elements_t [ - {:elements => [self.panel_pictures, self.speech_balloons], :name => :t} - ] - r1 and r2 + def usable? au + visible? au end - def store - res = false - Panel.transaction do - unless validate_child - self.errors.add :base , 'invalid time' - raise ActiveRecord::Rollback - end - res = self.save - end - res + def publish? + self.publish > 0 end def self.default_page_size @@ -129,17 +71,11 @@ class Panel < ActiveRecord::Base page_size end - def self.offset cnt, prm = nil - offset = prm.to_i - offset = cnt - 1 if offset >= cnt - offset = cnt - offset.abs if offset < 0 - offset = 0 if offset < 0 - offset - end - - def self.list opt = {}, page = 1, page_size = self.default_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => 'panels.publish > 0', :order => 'panels.updated_at desc', :limit => page_size, :offset => (page -1) * page_size}) + def self.list page = 1, page_size = self.default_page_size + opt = {} + opt.merge!(self.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => 'panels.publish > 0', :order => 'panels.updated_at desc'}) Panel.find(:all, opt) end @@ -161,7 +97,31 @@ class Panel < ActiveRecord::Base }} end - def self.list_json_opt + def self.mylist au, page = 1, page_size = Author.default_panel_page_size + opt = {} + opt.merge!(self.list_opt) + opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0 + opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panels.updated_at desc'}) + Panel.find(:all, opt) + end + + def self.show rid, au + opt = {} + opt.merge!(Panel.show_opt) + res = Panel.find(rid, opt) + raise ActiveRecord::Forbidden unless res.visible?(au) + res + end + + def self.edit rid, au + opt = {} + opt.merge!(Panel.show_opt) + res = Panel.find(rid, opt) + raise ActiveRecord::Forbidden unless res.own?(au) + res + end + + def self.show_opt {:include => { :panel_pictures => { :picture => {:artist => {}, :license => {}} @@ -179,133 +139,143 @@ class Panel < ActiveRecord::Base }} end - def self.mylist au, opt = {}, page = 1, panel_page_size = Author.default_panel_page_size - opt.merge!(self.list_opt) unless opt[:include] - opt.merge!({:conditions => ['panels.author_id = ?', au.id], :order => 'panels.updated_at desc', :limit => panel_page_size, :offset => (page -1) * page_size}) - Panel.find(:all, opt) + def parts_element + ((self.panel_pictures || []) + (self.speech_balloons || [])).compact end - def self.show rid, au, opt = {} - r = Panel.find(rid, :include => self.show_include_opt(opt)) - raise ActiveRecord::Forbidden unless r.visible?(au) - r + def parts + res = [] + self.parts_element.each do |e| + res[e.t] = e + end + res end - def self.edit rid, au, opt = {} - r = Panel.find(rid, :include => self.show_include_opt(opt)) - raise ActiveRecord::Forbidden unless r.own?(au) - r + def grounds + ((self.ground_colors || []) + (self.ground_pictures || []) + (self.panel_colors || [])).compact end - def self.show_include_opt opt = {} - res = { - :panel_pictures => { - :picture => {:artist => {}, :license => {}} - }, - :speech_balloons => {:balloons => {}, :speeches => {}}, - :ground_pictures => { - :picture => {:artist => {}, :license => {}} - }, - :ground_colors => { - :color => {} - }, - :panel_colors => { - }, - :author => {} + def panel_elements + parts + grounds + end + + @@elm_json_opt = { + 'PanelPicture' => { + :picture => {:artist => {}, :license => {}} + }, + 'SpeechBalloon' => {:balloons => {}, :speeches => {}}, + 'GroundPicture' => { + :picture => {:artist => {}, :license => {}} + }, + 'GroundColor' => { + :color => {} + }, + 'PanelColor' => { + } + } + + def self.elm_json_opt e + @@elm_json_opt[e.class.to_s] + end + + def elements + self.panel_elements.map {|e| + #(-_-;)<... kore wa hidoi + JSON.parse e.to_json({:include => Panel.elm_json_opt(e)}) } - res.merge!(opt[:include]) if opt[:include] - res end - def self.show_json_include_opt - {:include => { - :panel_pictures => { - :picture => {:artist => {}, :license => {}} - }, - :speech_balloons => {:balloons => {}, :speeches => {}}, - :ground_pictures => { - :picture => {:artist => {}, :license => {}} - }, - :ground_colors => { - :color => {} - }, - :panel_colors => { - }, - :author => {} - }} + def panel_elements_as_json + self.to_json({:include => {:author => {}}, :methods => :elements}) end - def visible? au - return false unless au - self.own?(au) or self.publish? + def self.visible_count + Panel.count end - def own? author - return false unless author - self.author_id == author.id + def self.collect_element_value elements, name + elements.map {|e| + e.map {|o| + o[name] + } + }.flatten end - def usable? au - visible? au + def self.validate_t ary + i = 0 + ary.compact.sort.each do |t| + break false unless t == i + i += 1 + end + ary.compact.size == i end - def publish? - self.publish > 0 + def self.validate_element_t elements, name + Panel.validate_t(Panel.collect_element_value(elements, name)) end - def sort_by_time - pe = [] - self.panel_pictures.each do |picture| - pe[picture.t] = picture - end - self.speech_balloons.each do |sb| - pe[sb.t] = sb - end - pe + def self.validate_elements_t c + c.map {|conf| + Panel.validate_element_t(conf[:elements], conf[:name]) ? nil : false + }.compact.empty? end - def each_ground - (self.ground_colors || []) + (self.ground_pictures || []) + (self.panel_colors || []).each do |e| - yield e - end + def validate_t_list + [ + {:elements => [self.panel_pictures, self.speech_balloons], :name => :t} + ] end - - def each_element - self.sort_by_time.each do |e| - yield e - end + def validate_child +# r1 = Panel.validate_elements_id validate_id_list + Panel.validate_elements_t validate_t_list end - def panel_elements - res = [] - self.each_element do |elm| - if elm.kind_of?(PanelPicture) - res[elm.t] = elm.to_json({:include => {:picture => {:artist => {}, :license => {}}}}) - end - if elm.kind_of?(SpeechBalloon) - res[elm.t] = elm.to_json({:include => {:balloons => {}, :speeches => {}}}) - end + def store attr, au + if attr == false + self.errors.add :base, 'invalid json' + return false end - self.each_ground do |elm| - if elm.kind_of?(GroundColor) - res << elm.to_json({:include => :color}) - end - if elm.kind_of?(GroundPicture) - res << elm.to_json({:include => {:picture => {:artist => {}, :license => {}}}}) - end - if elm.kind_of?(PanelColor) - res << elm.to_json({:include => {}}) + self.attributes = attr + self.overwrite au + res = false + Panel.transaction do + unless validate_child + self.errors.add :base , 'invalid time' + raise ActiveRecord::Rollback end + res = self.save end res end - def to_json_play - self.to_json :methods => :panel_elements +=begin + def self.validate_id ary, pid + ary.map {|v| + if pid + (v == pid or v == nil) ? nil : false + else + v ? false : nil + end + }.compact.empty? + end + + def self.validate_element_id elements, name, pid + Panel.validate_id(Panel.collect_element_value(elements, name), pid) end - def self.visible_count - Panel.count + def self.validate_elements_id c + c.map {|conf| + Panel.validate_element_id(conf[:elements], conf[:name], conf[:parent_id]) ? nil : false + }.compact.empty? + end + + def validate_id_list + r = self.speech_balloons.map {|sb| + {:elements => [sb.speeches, sb.balloons], :name => :speech_balloon_id, :parent_id => sb.id} + } + r.unshift({:elements => [self.panel_pictures, self.speech_balloons], :name => :panel_id, :parent_id => self.id}) + r end +=end end diff --git a/app/models/resource_picture.rb b/app/models/resource_picture.rb index 94c43c18..7bd555cc 100644 --- a/app/models/resource_picture.rb +++ b/app/models/resource_picture.rb @@ -72,7 +72,7 @@ class ResourcePicture < ActiveRecord::Base end def opt_img_tag - tw, th = ResourcePicture.fix_size_both(MagicNumber['thumbnail_width'], MagicNumber['thumbnail_height'], self.width, self.height) + tw, th = PettanImager.thumbnail_size(self.width, self.height) {:src => self.url, :width => tw, :height => th} end diff --git a/app/models/story.rb b/app/models/story.rb index df03c85f..46ce75e6 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -22,12 +22,6 @@ class Story < ActiveRecord::Base self.author_id == author.id end - def self.edit sid, au - res = Story.find sid - raise ActiveRecord::Forbidden unless res.own?(au) - res - end - def self.default_panel_size 30 end @@ -51,11 +45,11 @@ class Story < ActiveRecord::Base count end - def self.list comic, author, offset = 0, limit = Story.default_panel_size + def self.play_list comic, author, offset = 0, limit = Story.default_panel_size opt = {} opt.merge!(Story.list_opt) opt.merge!({:offset => offset, :limit => limit}) if limit > 0 - opt.merge!({:conditions => ['stories.comic_id = ? and comics.visible > 0 and panels.publish > 0', comic.id], :order => 'stories.t'}) + opt.merge!({:conditions => ['stories.comic_id = ?', comic.id], :order => 'stories.t'}) Story.find(:all, opt) end @@ -95,8 +89,39 @@ class Story < ActiveRecord::Base Story.find(:all, opt) end - def to_json_list - self.to_json( :include => {:author => {}, :panels => {:methods => :panel_element}}) + def self.edit sid, au + opt = {} + opt.merge!(Story.show_opt) + res = Story.find sid, opt + raise ActiveRecord::Forbidden unless res.own?(au) + res + end + + def self.show_opt + {:include => { + :author => {}, + :comic => { + :author => {} + }, + :panel => { + :author => {}, + :panel_pictures => {:picture => {:artist => {}, :license => {}}}, + :speech_balloons =>{:balloons => {}, :speeches => {}} + } + }} + end + + def elements + self.panel.elements + end + + def story_as_json au + panel_include = if self.panel and self.panel.visible?(au) + {:include => {:author => {}}, :methods => :elements} + else + {:include => {:author => {}}} + end + self.to_json({:include => {:comic => {:include => {:author => {}}}, :author => {}, :panel => panel_include}}) end def self.new_t comic_id diff --git a/app/views/comics/_form.html.erb b/app/views/comics/_form.html.erb index 21a7d4f9..636f7fdb 100644 --- a/app/views/comics/_form.html.erb +++ b/app/views/comics/_form.html.erb @@ -17,7 +17,7 @@
<%= f.label :visible %>
- <%= f.collection_select :visible, [['only me', 0], ['everyone', 3]], :last, :first, :html => {:selected => @comic.visible} %> + <%= f.collection_select :visible, [['only me', 0], ['everyone', 1]], :last, :first, :html => {:selected => @comic.visible} %>
diff --git a/app/views/comics/index.html.erb b/app/views/comics/index.html.erb index 5ea6d810..246b92e2 100644 --- a/app/views/comics/index.html.erb +++ b/app/views/comics/index.html.erb @@ -3,7 +3,7 @@ <% @comics.each do |comic| %>
- <%= link_to h(comic.title), :controller => 'stories', :action => :show, :id => comic.id %> + <%= link_to h(comic.title), :controller => 'stories', :action => :comic, :id => comic.id %>
作家:<%= h comic.author.name %> diff --git a/app/views/layouts/test.html.erb b/app/views/layouts/test.html.erb index ff14561c..45a8b706 100644 --- a/app/views/layouts/test.html.erb +++ b/app/views/layouts/test.html.erb @@ -28,13 +28,11 @@

<%= notice %>

<%= alert %>

<%= link_to 'comics', main_app.comics_path %> +<%= link_to 'stories', main_app.stories_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', main_app.speech_balloon_templates_path %> <%= link_to 'colors', main_app.colors_path %> diff --git a/app/views/speech_balloon_templates/index.html.erb b/app/views/speech_balloon_templates/index.html.erb index 3ea04e5c..148dee06 100644 --- a/app/views/speech_balloon_templates/index.html.erb +++ b/app/views/speech_balloon_templates/index.html.erb @@ -1,26 +1,12 @@ -

Listing speech_balloons

+

Listing speach balloon template

- - - - - -<% @speech_balloons.each do |speech_balloon| %> +<% @speech_balloon_templates.each do |st| %> - - - - - - + <% end %>
NameTail countsize countt
<%= h speech_balloon.name %><%= speech_balloon.tail_count %><%= speech_balloon.size_count %><%= speech_balloon.t %><%= link_to 'show', speech_balloon %> - <% if admin_signed_in? -%> - <%= link_to 'Destroy', speech_balloon, confirm: 'Are you sure?', method: :delete %> - <% end -%> - <%= h st.caption %>
diff --git a/app/views/stories/comic.html.erb b/app/views/stories/comic.html.erb new file mode 100644 index 00000000..dfa9effb --- /dev/null +++ b/app/views/stories/comic.html.erb @@ -0,0 +1,25 @@ +

<%= h @comic.title %>

+ +<% @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 %> +
+ t +
+ <% end -%> +<% end %> +<% if @comic.author.id == @author.id -%> + <%= link_to 'add panel', new_story_path, :remote => true %> +
+ t +
+<% end %> +<%= link_to 'Back', comics_path %> diff --git a/app/views/stories/show.html.erb b/app/views/stories/show.html.erb index dfa9effb..c8b19a8a 100644 --- a/app/views/stories/show.html.erb +++ b/app/views/stories/show.html.erb @@ -1,16 +1,12 @@ -

<%= h @comic.title %>

- -<% @stories.each do |story| %> - <% @story = story %> <% @panel = story.panel %> <%= render 'panels/standard' %> - <% if story.author.id == @author.id -%> + <% if @story.author.id == @author.id -%> - t:<%= story.t %> + 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 %> + <%= link_to 'open js', edit_story_path(@story), :remote => true %>
t
@@ -21,5 +17,3 @@
t
-<% end %> -<%= link_to 'Back', comics_path %> diff --git a/config/routes.rb b/config/routes.rb index 6a1e38c7..f984d8ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -243,6 +243,7 @@ Pettanr::Application.routes.draw do # Keep in mind you can assign values other than :controller and :action match 'resource_pictures/:subdir/:id(.:format)/' => 'resource_pictures#show' match 'pictures/:subdir/:id(.:format)/' => 'pictures#show' + match 'stories/comic/:id(.:format)' => 'stories#comic' match 'home/(:action)', :controller => 'home' match 'system/(:action)', :controller => 'system' match 'authors/(:action(/:id))', :controller => 'authors' diff --git a/spec/cli/u/comics/create.json b/spec/cli/u/comics/create.json index c780055a..4f67cbdc 100644 --- a/spec/cli/u/comics/create.json +++ b/spec/cli/u/comics/create.json @@ -5,5 +5,5 @@ "height": 200, "visible": 3 }, - "auth_token": "vX7rc33zxVJSQPKjp2vc" + "auth_token": "3fhobSVvDxjUSUPSKy5y" } \ No newline at end of file diff --git a/spec/cli/u/original_pictures/create.json b/spec/cli/u/original_pictures/create.json index 6020ade1..5b494359 100644 --- a/spec/cli/u/original_pictures/create.json +++ b/spec/cli/u/original_pictures/create.json @@ -2,5 +2,5 @@ "original_picture": { "file": "iVBORw0KGgoAAAANSUhEUgAAAWIAAAF7CAYAAADohYEpAAAcW0lEQVR4nO3dTW4cx7KG4ewLz0gYGgmCVsGleBEeHJ+zAQ489IArEDS4i7hL4SoIgSPBIMd9BzolF4tVWfkTmRGR+T4AAdkkm93183V0VGbW5Xq9BgCAnv/RfgIAMDuCGACUEcQAoIwgBgBlBDEAKCOI0d3lcrnydfwVQgj/+eMPhjNN5MLwNbSyhAr6ul6vF+3ngDwEMUQRvrYQyj4QxKhC8PpAINtGECMZoTsGQtkeghiHCN7xEco2EMT4qXfw3t/f9/xzbjw8PHT/mwSyLoJ4Uj1Cl6Dt5+/v30MIIXz5+rX4MQhjPQTxJKh2x7eEcQgh/PrhQ3FlTSD3RxAPSKO3S/DaQSD7QxAPgGoXW+sw3sppXxDGfRDEDhG8SHUUyISxLQSxcbQZIGUbyoSxHQSxMVS7a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B3EIdSfBjIFsMYRD6BvEOaFTsy2sLHY/upFDOASjrYmtnFbF1kwfC0cb5F6q5xvR+nEIZVmjH6drLoJ4URrIvfvIvfWq/jzQ/DRQUzDgrdGP0y0XrYkjs/ePvc00aj1ywlJLhjDOo31sanMdxIvZAtnrTKOz/VSzPyyF8NrsgWzhuPNgiCBeyz3wPYVx6VVvSydDizC2GsI5egS29W0wM1c94hS5fTov/WNvbYgeRgjghZfniTaGq4i3SioNjVCWHONp/aSWqIpHCmFg+CAOYY4+nbfQKV3ciSF6GNEUQbwYMZA9B06r/eF5m2BO5u/QIWm0E9T762nx/L1vE8xpqop4zXN1PFrYSO2L0bYL5jFtEC88BfLIQVOzH0beLpjD9EG8RyucZw+Uku0++zbDGAhimJITxoQwRjHchA74RrhiRlONmgAAiwhiAFBGEAOAMoIYAJQRxACgjCAGAGUEMQAoI4gBQBlBDADKCGIAUEYQA4AyghgAlBHEAKCMIAYAZQQxACgjiAFAGUEMAMoIYgBQRhADgDKCGACUEcQAoIwgBgBlBDEAKCOIAUAZQQwAyghiAFBGEAOAMoIYAJQRxACgjCAGAGUEMQAoI4gBQBlBDADKCGIAUEYQA4AyghgAlP0/Bxl7hN5Zu0EAAAAASUVORK5CYII=" }, - "auth_token": "vX7rc33zxVJSQPKjp2vc" + "auth_token": "3fhobSVvDxjUSUPSKy5y" } \ No newline at end of file diff --git a/spec/cli/u/panels/create.json b/spec/cli/u/panels/create.json index 53014549..a9d642cd 100644 --- a/spec/cli/u/panels/create.json +++ b/spec/cli/u/panels/create.json @@ -37,5 +37,5 @@ } } }, - "auth_token": "3d3Fvz9RafTPcpzLrYSW" + "auth_token": "3fhobSVvDxjUSUPSKy5y" } \ No newline at end of file diff --git a/spec/cli/u/stories/create.json b/spec/cli/u/stories/create.json index 75d07d2d..6ccc5f2e 100644 --- a/spec/cli/u/stories/create.json +++ b/spec/cli/u/stories/create.json @@ -3,5 +3,5 @@ "comic_id": 1, "panel_id": 1 }, - "auth_token": "vX7rc33zxVJSQPKjp2vc" + "auth_token": "3fhobSVvDxjUSUPSKy5y" } \ No newline at end of file diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 2809d269..f42e53f5 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -174,10 +174,6 @@ describe HomeController do get :panel, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end - it 'コマモデルにjson一覧出力オプションを問い合わせている' do - Panel.should_receive(:list_json_opt).exactly(1) - get :panel, :format => :json - end it 'データがリスト構造になっている' do get :panel, :format => :json json = JSON.parse response.body diff --git a/spec/controllers/panels_controller_spec.rb b/spec/controllers/panels_controller_spec.rb index db00bf23..31e8bfca 100644 --- a/spec/controllers/panels_controller_spec.rb +++ b/spec/controllers/panels_controller_spec.rb @@ -44,10 +44,6 @@ describe PanelsController do end end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :index - response.should be_success - end it 'コマモデルに一覧を問い合わせている' do Panel.should_receive(:list).exactly(1) get :index @@ -57,18 +53,26 @@ describe PanelsController do assigns(:panels).should have_at_least(3).items end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :index + response.should be_success + end it 'indexテンプレートを描画する' do get :index response.should render_template("index") end end context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :index, :format => :json + response.should be_success + end it 'jsonデータを返す' do get :index, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end - it 'コマモデルにjson一覧出力オプションを問い合わせている' do - Panel.should_receive(:list_json_opt).exactly(1) + it 'コマモデルにコマのjson出力を問い合わせている' do + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(3) get :index, :format => :json end it 'データがリスト構造になっている' do @@ -113,14 +117,10 @@ describe PanelsController do describe '単体表示に於いて' do before do @panel = FactoryGirl.create :panel, :author_id => @user.author.id - Panel.stub(:show).and_return(@panel) + Panel.stub(:show).with(@panel.id.to_s, @author).and_return(@panel) sign_in @user end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :show, :id => @panel.id - response.should be_success - end it 'コマモデルに単体取得を問い合わせている' do Panel.should_receive(:show).exactly(1) get :show @@ -130,16 +130,28 @@ describe PanelsController do assigns(:panel).id.should eq(@panel.id) end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id + response.should be_success + end it 'showテンプレートを描画する' do get :show, :id => @panel.id response.should render_template("show") end end context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @panel.id, :format => :json + response.should be_success + end it 'jsonデータを返す' do get :show, :id => @panel.id, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'コマモデルにコマのjson出力を問い合わせている' do + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1) + get :show, :id => @panel.id, :format => :json + end it 'データがアレになっている' do get :show, :id => @panel.id, :format => :json json = JSON.parse response.body @@ -241,10 +253,6 @@ describe PanelsController do sign_in @user end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :new - response.should be_success - end it '@panelに新規データを用意している' do get :new assigns(:panel).should be_a_new(Panel) @@ -254,6 +262,10 @@ describe PanelsController do get :new end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :new + response.should be_success + end it 'newテンプレートを描画する' do get :new response.should render_template("new") @@ -265,6 +277,16 @@ describe PanelsController do response.should render_template("new") end end + context 'json形式' do + it 'jsonデータを返す' do + get :new, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'コマモデルにコマのjson出力を問い合わせている' do + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1) + get :new, :format => :json + end + end end context '作家権限がないとき' do before do @@ -295,13 +317,12 @@ describe PanelsController do describe '新規作成に於いて' do before do - @panel = FactoryGirl.create :panel, :author_id => @user.author.id + @panel = FactoryGirl.build :panel, :author_id => @author.id @attr = FactoryGirl.attributes_for(:panel, :author_id => @author.id) sign_in @user end context '事前チェックする' do before do - controller Panel.stub(:count).and_return(10) end it 'panelがパラメータにあれば、展開する' do @@ -319,20 +340,16 @@ describe PanelsController do } assigns(:prm)['border'].to_i.should eq @panel.border end - end - context 'つつがなく終わるとき' do it 'コマモデルにデフォルト値補充を依頼している' do Panel.any_instance.should_receive(:supply_default).exactly(1) post :create, :panel => @attr end - it 'コマモデルに上書き補充を依頼している' do - Panel.any_instance.should_receive(:overwrite).exactly(1) - post :create, :panel => @attr - end it 'モデルに保存依頼する' do Panel.any_instance.should_receive(:store).exactly(1) post :create, :panel => @attr end + end + context 'つつがなく終わるとき' do it "@panelに作成されたコマを保持していて、それがDBにある" do post :create, :panel => @attr assigns(:panel).should be_a(Panel) @@ -360,6 +377,10 @@ describe PanelsController do post :create, :panel => @attr, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'コマモデルにコマのjson出力を問い合わせている' do + Panel.any_instance.should_receive(:panel_elements_as_json).exactly(1) + post :create, :panel => @attr, :format => :json + end it 'データがアレになっている' do post :create, :panel => @attr, :format => :json json = JSON.parse response.body @@ -430,10 +451,6 @@ describe PanelsController do Panel.stub(:show).and_return(@panel) end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :edit, :id => @panel.id - response.should be_success - end it 'コマモデルに編集取得を問い合わせている' do Panel.should_receive(:edit).exactly(1) get :edit, :id => @panel.id @@ -443,12 +460,20 @@ describe PanelsController do assigns(:panel).should eq @panel end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @panel.id + response.should be_success + end it 'editテンプレートを描画する' do get :edit, :id => @panel.id response.should render_template("edit") end end context 'js形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @panel.id, :format => :js + response.should be_success + end it 'edit.jsテンプレートを描画する' do get :edit, :id => @panel.id, :format => :js response.should render_template("edit") @@ -516,10 +541,6 @@ describe PanelsController do Panel.should_receive(:edit).exactly(1) put :update, :id => @panel.id, :panel => @attr end - it 'コマモデルに上書き補充を依頼している' do - Panel.any_instance.should_receive(:overwrite).exactly(1) - put :update, :id => @panel.id, :panel => @attr - end it 'モデルに保存依頼する' do Panel.any_instance.should_receive(:store).exactly(1) put :update, :id => @panel.id, :panel => @attr @@ -547,6 +568,11 @@ describe PanelsController do put :update, :id => @panel.id, :panel => @attr, :format => :json response.should be_success end + it 'ページ本体は特に返さない' do + Panel.any_instance.stub(:save).with(any_args()).and_return(true) + put :update, :id => @panel.id, :panel => @attr, :format => :json + response.body.should match /./ + end end end context '作家権限がないとき' do diff --git a/spec/controllers/stories_controller_spec.rb b/spec/controllers/stories_controller_spec.rb index 0ac61e4b..ec5310dc 100644 --- a/spec/controllers/stories_controller_spec.rb +++ b/spec/controllers/stories_controller_spec.rb @@ -13,18 +13,194 @@ describe StoriesController do @panel = FactoryGirl.create :panel, :author_id => @author.id end - + describe '一覧表示に於いて' do + end + + describe '単体表示に於いて' do + before do + sign_in @user + @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id + Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic) + Story.stub(:show).with(@story.id.to_s, @author).and_return(@story) + end + context 'つつがなく終わるとき' do + it 'ストーリーモデルに単体取得を問い合わせている' do + Story.should_receive(:show).with(@story.id.to_s, @author).exactly(1) + get :show, :id => @story.id + end + it '@storyにアレを取得している' do + get :show, :id => @story.id + assigns(:story).should eq @story + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @story.id + response.should be_success + end + it 'showテンプレートを描画する' do + get :show, :id => @story.id + response.should render_template("show") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :show, :id => @story.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :show, :id => @story.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'ストーリーモデルにストーリーjson出力を問い合わせている' do + Story.any_instance.should_receive(:story_as_json).exactly(1) + get :show, :id => @story.id, :format => :json + end + it 'データがアレになっている' do + get :show, :id => @story.id, :format => :json + json = JSON.parse response.body + json.has_key?("panel_id").should be_true + json.has_key?("comic_id").should be_true + json.has_key?("author_id").should be_true + end + end + end + context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :show, :id => @story.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :show, :id => @story.id + response.body.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :show, :id => @story.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :show, :id => @story.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + end + describe '閲覧に於いて' do before do @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id - Comic.stub(:show).and_return(@comic) + Comic.stub(:show).with(@comic.id.to_s, @author).and_return(@comic) + Story.stub(:count).and_return(10) + Story.stub(:play_list).with(any_args).and_return([@story, @story, @story]) sign_in @user end + context 'パラメータチェックする' do + it '与えられたoffsetがセットされている' do + get :comic, :id => @comic.id, :offset => 5 + assigns(:offset).should eq 5 + end + it '省略されると@offsetに0値が入る' do + get :comic, :id => @comic.id + assigns(:offset).should eq 0 + end + it '与えられたcountがセットされている' do + get :comic, :id => @comic.id, :count => 4 + assigns(:panel_count).should eq 4 + end + it '省略されると@panel_countにデフォルト値が入る' do + get :comic, :id => @comic.id + assigns(:panel_count).should eq Story.default_panel_size + end + it '最大を超えると@panel_countにデフォルト最大値が入る' do + get :comic, :id => @comic.id, :count => 1500 + assigns(:panel_count).should eq Story.max_panel_size + end + it '不正な値が入ると@panel_countにデフォルト最大値が入る' do + get :comic, :id => @comic.id, :count => -1 + assigns(:panel_count).should eq Story.default_panel_size + end + end context '事前チェックする' do + it 'コミックモデルに単体取得を問い合わせている' do + Comic.should_receive(:show).with(@comic.id.to_s, @author).exactly(1) + get :comic, :id => @comic.id + end + it 'ストーリーモデルにプレイリスト取得を問い合わせている' do + Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1) + get :comic, :id => @comic.id + end end context 'つつがなく終わるとき' do + it '@storiesにリストを取得している' do + get :comic, :id => @comic.id + assigns(:stories).should have_at_least(3).items + end + context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :comic, :id => @comic.id + response.should be_success + end + it 'comicテンプレートを描画する' do + get :comic, :id => @comic.id + response.should render_template("comic") + end + end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :comic, :id => @comic.id, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :comic, :id => @comic.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do + Story.any_instance.should_receive(:story_as_json).exactly(3) + get :comic, :id => @comic.id, :format => :json + end + it 'データがリスト構造になっている' do + get :comic, :id => @comic.id, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do + get :comic, :id => @comic.id, :format => :json + json = JSON.parse response.body + json.first.has_key?("panel_id").should be_true + json.first.has_key?("comic_id").should be_true + json.first.has_key?("author_id").should be_true + end + end end context '作家権限がないとき' do + before do + sign_out @user + end + context 'html形式' do + it 'ステータスコード302 Foundを返す' do + get :comic, :id => @comic.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :comic, :id => @comic.id + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :comic, :id => @comic.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :comic, :id => @comic.id, :format => :json + response.message.should match(/Unauthorized/) + end + end end end @@ -33,10 +209,6 @@ describe StoriesController do sign_in @user end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :new - response.should be_success - end it '@storyに新規データを用意している' do get :new assigns(:story).should be_a_new(Story) @@ -46,17 +218,46 @@ describe StoriesController do get :new end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :new + response.should be_success + end it 'newテンプレートを描画する' do get :new response.should render_template("new") end end context 'js形式' do + it 'ステータスコード200 OKを返す' do + get :new, :format => :js + response.should be_success + end it 'new.jsテンプレートを描画する' do get :new, :format => :js response.should render_template("new") end end + context 'json形式' do + it 'ステータスコード200 OKを返す' do + get :new, :format => :json + response.should be_success + end + it 'jsonデータを返す' do + get :new, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do + Story.any_instance.should_receive(:story_as_json).exactly(1) + get :new, :format => :json + end + it 'データがアレになっている' do + get :new, :format => :json + json = JSON.parse response.body + json.has_key?("panel_id").should be_true + json.has_key?("comic_id").should be_true + json.has_key?("author_id").should be_true + end + end end context '作家権限がないとき' do before do @@ -72,13 +273,13 @@ describe StoriesController do response.body.should redirect_to '/users/sign_in' end end - context 'js形式' do + context 'json形式' do it 'ステータスコード401 Unauthorizedを返す' do - get :new, :format => :js + get :new, :format => :json response.status.should eq 401 end it '応答メッセージにUnauthorizedを返す' do - get :new, :format => :js + get :new, :format => :json response.message.should match(/Unauthorized/) end end @@ -97,13 +298,22 @@ describe StoriesController do end it 'POSTデータから、カラム値を復元している' do Story.any_instance.stub(:store).and_return(true) - Story.any_instance.should_receive(:attributes=).exactly(1) post :create, :story => @attr + assigns(:story).comic_id.should eq @comic.id + assigns(:story).panel_id.should eq @panel.id end it '上書き補充を依頼する' do Story.any_instance.should_receive(:overwrite).exactly(1) post :create, :story => @attr end + it 'コミックモデルに編集取得を依頼している' do + Comic.should_receive(:edit).with(@comic.id, @author).exactly(1) + post :create, :story => @attr + end + it 'コマモデルに単体取得を依頼している' do + Panel.should_receive(:show).with(@panel.id, @author).exactly(1) + post :create, :story => @attr + end it 'モデルに保存依頼する' do Story.any_instance.should_receive(:store).exactly(1) post :create, :story => @attr @@ -122,7 +332,7 @@ describe StoriesController do it 'コミックのストーリー表示へ遷移する' do # Story.any_instance.stub(:store).and_return(true) post :create, :story => @attr - response.should redirect_to(:action => :show, :id => @attr[:comic_id]) + response.should redirect_to(:action => :comic, :id => @attr[:comic_id]) end end context 'json形式' do @@ -135,6 +345,10 @@ describe StoriesController do post :create, :story => @attr, :format => :json lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) end + it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do + Story.any_instance.should_receive(:story_as_json).exactly(1) + post :create, :story => @attr, :format => :json + end it 'データがアレになっている' do post :create, :story => @attr, :format => :json json = JSON.parse response.body @@ -205,11 +419,7 @@ describe StoriesController do Story.stub(:show).and_return(@story) end context 'つつがなく終わるとき' do - it 'ステータスコード200 OKを返す' do - get :edit, :id => @story.id - response.should be_success - end - it 'コマモデルに編集取得を問い合わせている' do + it 'ストーリーモデルに編集取得を問い合わせている' do Story.should_receive(:edit).exactly(1) get :edit, :id => @story.id end @@ -218,12 +428,20 @@ describe StoriesController do assigns(:story).should eq @story end context 'html形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @story.id + response.should be_success + end it 'editテンプレートを描画する' do get :edit, :id => @story.id response.should render_template("edit") end end context 'js形式' do + it 'ステータスコード200 OKを返す' do + get :edit, :id => @story.id, :format => :js + response.should be_success + end it 'edit.jsテンプレートを描画する' do get :edit, :id => @story.id, :format => :js response.should render_template("edit") @@ -293,10 +511,10 @@ describe StoriesController do put :update, :id => @story.id, :story => @attr response.status.should eq 302 end - it 'コミックのストーリー表示へ遷移する' do + it 'ストーリー表示へ遷移する' do # Story.any_instance.stub(:store).and_return(true) put :update, :id => @story.id, :story => @attr - response.should redirect_to(:action => :show, :id => @attr[:comic_id]) + response.should redirect_to(:action => :comic, :id => @attr[:comic_id]) end end context 'json形式' do diff --git a/spec/models/comic_spec.rb b/spec/models/comic_spec.rb index 8887e3e0..f83e83fc 100644 --- a/spec/models/comic_spec.rb +++ b/spec/models/comic_spec.rb @@ -318,7 +318,7 @@ describe Comic do @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400 - Color.stub(:default_page_size).and_return(0) + Comic.stub(:default_page_size).and_return(2) end it '通常は全件(5件)を返す' do r = Comic.mylist @author, 5, 0 diff --git a/spec/models/panel_picture_spec.rb b/spec/models/panel_picture_spec.rb index a85ed4b9..bed7168d 100644 --- a/spec/models/panel_picture_spec.rb +++ b/spec/models/panel_picture_spec.rb @@ -485,7 +485,7 @@ describe PanelPicture do it '自分のコマのコマ絵は非公開コマでも含んでいる' do pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 ni = FactoryGirl.create :panel_picture, :panel_id => pl.id, :picture_id => @p.id, - :width => @p.width, :height => @p.height + :width => @p.width, :height => @p.height, :updated_at => Time.now + 100 r = PanelPicture.mylist @author r.should eq [ni, @pp] end diff --git a/spec/models/panel_spec.rb b/spec/models/panel_spec.rb index ecf150a4..002f9dd1 100644 --- a/spec/models/panel_spec.rb +++ b/spec/models/panel_spec.rb @@ -7,6 +7,7 @@ describe Panel do @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 @user = FactoryGirl.create( :user_yas) @author = @user.author @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @@ -21,21 +22,33 @@ describe Panel do describe '検証に於いて' do before do - end - - it 'オーソドックスなデータなら通る' do @panel = FactoryGirl.build :panel, :author_id => @author.id - @panel.should be_valid 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 - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.width = 1 - @panel.should be_valid - end it 'nullなら失敗する' do @panel.width = nil @panel.should_not be_valid @@ -54,13 +67,6 @@ describe Panel do end end context 'heightを検証するとき' do - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.height = '1' - @panel.should be_valid - end it 'nullなら失敗する' do @panel.height = nil @panel.should_not be_valid @@ -79,13 +85,6 @@ describe Panel do end end context 'borderを検証するとき' do - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.border = '1' - @panel.should be_valid - end it 'nullなら失敗する' do @panel.border = nil @panel.should_not be_valid @@ -104,13 +103,6 @@ describe Panel do end end context 'xを検証するとき' do - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.x = '1' - @panel.should be_valid - end it '数値でなければ失敗する' do @panel.x = 'a' @panel.should_not be_valid @@ -125,13 +117,6 @@ describe Panel do end end context 'yを検証するとき' do - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.y = '1' - @panel.should be_valid - end it '数値でなければ失敗する' do @panel.y = 'a' @panel.should_not be_valid @@ -146,13 +131,6 @@ describe Panel do end end context 'zを検証するとき' do - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.z = '1' - @panel.should be_valid - end it '数値でなければ失敗する' do @panel.z = 'a' @panel.should_not be_valid @@ -167,13 +145,6 @@ describe Panel do end end context 'author_idを検証するとき' do - before do - @panel = FactoryGirl.build :panel, :author_id => @author.id - end - it 'テストデータの確認' do - @panel.author_id = @author.id - @panel.should be_valid - end it 'nullなら失敗する' do @panel.author_id = nil @panel.should_not be_valid @@ -182,11 +153,17 @@ describe Panel do @panel.author_id = 'a' @panel.should_not be_valid end - it '存在する絵師でなければ失敗する' do + it '存在する作家でなければ失敗する' do @panel.author_id = 0 @panel.should_not be_valid end end + context '公開フラグを検証するとき' do + it '数値でなければ失敗する' do + @panel.publish = 'a' + @panel.should_not be_valid + end + end context '全体を検証するとき' do before do @panel = FactoryGirl.create :panel, :author_id => @author.id @@ -203,6 +180,11 @@ describe Panel do @panel.supply_default @panel.border.should eq 2 end + it 'publishは0を補充する' do + @panel.publish = nil + @panel.supply_default + @panel.publish.should eq 0 + end end describe '上書き補充に於いて' do @@ -235,6 +217,7 @@ describe Panel do panel.own?(nil).should == false end end + describe '閲覧許可に於いて' do before do end @@ -263,192 +246,7 @@ describe Panel do panel.visible?(@author).should == false end end - describe '単体取得に於いて' do - before do - @panel = FactoryGirl.create :panel, :author_id => @author.id - end - it '指定のコマを返す' do - Panel.any_instance.stub(:visible?).and_return(true) - pl = Panel.show @panel.id, @author - pl.should eq @panel - end - context '他人の非公開コミックのコマを開こうとしたとき' do - it '403Forbidden例外を返す' do - Panel.any_instance.stub(:visible?).and_return(false) - lambda{ - Panel.show @panel.id, @author - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しないコマを開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Panel.show 110, @author - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - describe '編集取得に於いて' do - before do - @panel = FactoryGirl.create :panel, :author_id => @author.id - end - it '指定のコマを返す' do - Panel.any_instance.stub(:own?).and_return(true) - pl = Panel.edit @panel.id, @author - pl.should eq @panel - end - context '他人のコマを開こうとしたとき' do - it '403Forbidden例外を返す' do - Panel.any_instance.stub(:own?).and_return(false) - lambda{ - Panel.edit @panel.id, @author - }.should raise_error(ActiveRecord::Forbidden) - end - end - context '存在しないコマを開こうとしたとき' do - it '404RecordNotFound例外を返す' do - lambda{ - Panel.edit 110, @author - }.should raise_error(ActiveRecord::RecordNotFound) - end - end - end - describe '関連テーブルプションに於いて' do - it '6つの項目を含んでいる' do - r = Panel.show_include_opt - r.should have(6).items - end - it 'コマ絵を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:panel_pictures).should be_true - end - it 'コマ絵は実素材を含んでいる' do - r = Panel.show_include_opt - r[:panel_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.show_include_opt - r[:panel_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Panel.show_include_opt - r[:panel_pictures][:picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.show_include_opt - r.has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_include_opt - r[:speech_balloons].has_key?(:speeches).should be_true - end - it '景色画像を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:ground_pictures).should be_true - end - it '景色画像は実素材を含んでいる' do - r = Panel.show_include_opt - r[:ground_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.show_include_opt - r[:ground_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Panel.show_include_opt - r[:ground_pictures][:picture].has_key?(:license).should be_true - end - it '間接色を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:ground_colors).should be_true - end - it '間接色は色を含んでいる' do - r = Panel.show_include_opt - r[:ground_colors].has_key?(:color).should be_true - end - it '景色を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:panel_colors).should be_true - end - it '作家を含んでいる' do - r = Panel.show_include_opt - r.has_key?(:author).should be_true - end - end - describe 'json単体出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.show_json_include_opt - r.has_key?(:include).should be_true - end - it '6つの項目を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.should have(6).items - end - it 'コマ絵を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:panel_pictures).should be_true - end - it 'コマ絵は実素材を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:panel_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:panel_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:panel_pictures][:picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:speech_balloons].has_key?(:speeches).should be_true - end - it '景色画像を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:ground_pictures).should be_true - end - it '景色画像は実素材を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:ground_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:ground_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:ground_pictures][:picture].has_key?(:license).should be_true - end - it '間接色を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:ground_colors).should be_true - end - it '間接色は色を含んでいる' do - r = Panel.show_json_include_opt[:include] - r[:ground_colors].has_key?(:color).should be_true - end - it '景色を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:panel_colors).should be_true - end - it '作家を含んでいる' do - r = Panel.show_json_include_opt[:include] - r.has_key?(:author).should be_true - end - end + describe '一覧取得に於いて' do before do @panel = FactoryGirl.create :panel, :author_id => @author.id @@ -479,18 +277,19 @@ describe Panel do end end it 'リストを返す' do - pl = Panel.list - pl.should eq [@panel] + r = Panel.list + r.should eq [@panel] end it '時系列で並んでいる' do - npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 - pl = Panel.list - pl.should eq [npl, @panel] + #公開コミックは(他人のコミックであっても)含んでいる + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + r = Panel.list + r.should eq [npl, @panel] end - it '非公開のコマは含まない' do + it '非公開のコマ(自分のコマであっても)は含まない' do npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 - pl = Panel.list - pl.should eq [@panel] + r = Panel.list + r.should eq [@panel] end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do @@ -506,18 +305,31 @@ describe Panel do end it 'page=1なら末尾2件を返す' do #時系列で並んでいる - pl = Panel.list( {}, 1) + pl = Panel.list 1 pl.should eq [@npl5, @npl4] end it 'page=2なら中間2件を返す' do - pl = Panel.list({}, 2) + pl = Panel.list 2 pl.should eq [@npl3, @npl2] end it 'page=3なら先頭1件を返す' do - pl = Panel.list({}, 3) + pl = Panel.list 3 pl.should eq [@panel] end end + 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 describe 'list関連テーブルプションに於いて' do it 'includeキーを含んでいる' do @@ -590,120 +402,702 @@ describe Panel do end end describe 'json一覧出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = Panel.list_json_opt - r.has_key?(:include).should be_true + end + + describe '自分のコマ一覧取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id end - it '6つの項目を含んでいる' do - r = Panel.list_json_opt[:include] - r.should have(6).items + it 'リストを返す' do + pl = Panel.mylist @author + pl.should eq [@panel] end - it 'コマ絵を含んでいる' do - r = Panel.list_json_opt[:include] - r.has_key?(:panel_pictures).should be_true + it '時系列で並んでいる' do + npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 + pl = Panel.mylist @author + pl.should eq [npl, @panel] end - it 'コマ絵は実素材を含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Panel.list_json_opt[:include] - r[:panel_pictures][:picture].has_key?(:license).should be_true - end - it 'フキダシを含んでいる' do - r = Panel.list_json_opt[:include] - r.has_key?(:speech_balloons).should be_true + it '他人のコマは公開でも含まない' do + npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + pl = Panel.mylist @author + pl.should eq [@panel] end - it 'フキダシはフキダシ枠を含んでいる' do - r = Panel.list_json_opt[:include] - r[:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - r = Panel.list_json_opt[:include] - r[:speech_balloons].has_key?(:speeches).should be_true - end - it '景色画像を含んでいる' do - r = Panel.list_json_opt[:include] - r.has_key?(:ground_pictures).should be_true + it '自分のコマは非公開でも含んでいる' do + npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100 + pl = Panel.mylist @author + pl.should eq [npl, @panel] end - it '景色画像は実素材を含んでいる' do - r = Panel.list_json_opt[:include] - r[:ground_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Panel.list_json_opt[:include] - r[:ground_pictures][:picture].has_key?(:artist).should be_true + 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 + it '通常は2件を返す' do + pl = Panel.list 1, 2 + pl.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = Panel.mylist @author, 1, 2 + pl.should eq [@npl5, @npl4] + end + it 'page=2なら中間2件を返す' do + pl = Panel.mylist @author, 2, 2 + pl.should eq [@npl3, @npl2] + end + it 'page=3なら先頭1件を返す' do + pl = Panel.mylist @author, 3, 2 + pl.should eq [@panel] + end + 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 + Panel.stub(:default_page_size).and_return(2) + end + it '通常は全件(5件)を返す' do + r = Panel.mylist @author, 5, 0 + r.should have(5).items + end + end + end + + describe '単体取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + context 'つつがなく終わるとき' 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 + 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 + end + end + it '指定のコマを返す' do + Panel.any_instance.stub(:visible?).and_return(true) + pl = Panel.show @panel.id, @author + pl.should eq @panel + end + context '閲覧許可が出なかったとき' do + it '403Forbidden例外を返す' do + Panel.any_instance.stub(:visible?).and_return(false) + lambda{ + Panel.show @panel.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しないコマを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Panel.show 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '編集取得に於いて' do + before do + @panel = FactoryGirl.create :panel, :author_id => @author.id + end + context 'つつがなく終わるとき' 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 + 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 + end + end + it '指定のコマを返す' do + Panel.any_instance.stub(:own?).and_return(true) + pl = Panel.edit @panel.id, @author + pl.should eq @panel + end + context '他人のコマを開こうとしたとき' do + it '403Forbidden例外を返す' do + Panel.any_instance.stub(:own?).and_return(false) + lambda{ + Panel.edit @panel.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end + end + context '存在しないコマを開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + Panel.edit 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) + end + end + end + describe '関連テーブルプションに於いて' do + it 'includeキーを含んでいる' do + r = Panel.show_opt + r.has_key?(:include).should be_true + end + it '6つの項目を含んでいる' do + r = Panel.show_opt[:include] + r.should have(6).items + end + it 'コマ絵を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:panel_pictures).should be_true + end + it 'コマ絵は実素材を含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.show_opt[:include] + r[:panel_pictures][:picture].has_key?(:artist).should be_true end it '実素材はライセンスを含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_opt[:include] + r[:panel_pictures][:picture].has_key?(:license).should be_true + end + it 'フキダシを含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:speech_balloons).should be_true + end + it 'フキダシはフキダシ枠を含んでいる' do + r = Panel.show_opt[:include] + r[:speech_balloons].has_key?(:balloons).should be_true + end + it 'フキダシはセリフを含んでいる' do + r = Panel.show_opt[:include] + r[:speech_balloons].has_key?(:speeches).should be_true + end + it '景色画像を含んでいる' do + r = Panel.show_opt[:include] + r.has_key?(:ground_pictures).should be_true + end + it '景色画像は実素材を含んでいる' do + r = Panel.show_opt[:include] + r[:ground_pictures].has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = Panel.show_opt[:include] + r[:ground_pictures][:picture].has_key?(:artist).should be_true + end + it '実素材はライセンスを含んでいる' do + r = Panel.show_opt[:include] r[:ground_pictures][:picture].has_key?(:license).should be_true end it '間接色を含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_opt[:include] r.has_key?(:ground_colors).should be_true end it '間接色は色を含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_opt[:include] r[:ground_colors].has_key?(:color).should be_true end it '景色を含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_opt[:include] r.has_key?(:panel_colors).should be_true end it '作家を含んでいる' do - r = Panel.list_json_opt[:include] + r = Panel.show_opt[:include] r.has_key?(:author).should be_true end end - - describe '自分のコマ一覧取得に於いて' do + describe 'json単体出力オプションに於いて' do + end + describe 'コマ部品集合に於いて' 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 + end + it 'リストを返している' do + r = @panel.parts_element + r.is_a?(Array).should be_true + end + it 'コマ絵とフキダシを合わせている' do + r = @panel.parts_element + r.include?(@pp).should be_true + r.include?(@sb).should be_true + end + it '景色素材と景色カラーと景色カラーコードを含んでいない' do + r = @panel.parts_element + r.include?(@gc).should_not be_true + r.include?(@gp).should_not be_true + r.include?(@pc).should_not be_true end - it 'リストを返す' do - pl = Panel.mylist @author - pl.should eq [@panel] + end + describe 'コマ部品に於いて' 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 end - it '時系列で並んでいる' do - npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100 - pl = Panel.mylist @author - pl.should eq [npl, @panel] + context 'つつがなく終わるとき' do + it 'コマ部品集合を利用している' do + Panel.any_instance.stub(:parts_element).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1) + r = @panel.parts + end end - it '他人のコマは公開でも含まない' do - npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 - pl = Panel.mylist @author - pl.should eq [@panel] + it 'リストを返している' do + r = @panel.parts + r.is_a?(Array).should be_true + r.size.should eq 2 end - it '自分のコマは非公開でも含んでいる' do - npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100 - pl = Panel.mylist @author - pl.should eq [npl, @panel] + it 'tでソートしている' do + r = @panel.parts + r[0].should eq @sb + r[1].should eq @pp + end + context 'さらに末尾にフキダシを追加したとき' do + before do + @sb2 = @panel.speech_balloons.create( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + ) + @panel.reload + end + it 'tでソートしている' do + r = @panel.parts + r[0].should eq @sb + r[1].should eq @pp + r[2].should eq @sb2 + end end end - - #異常データ検出 - #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった - #コマ絵とフキダシの整合チェックをする - describe 'id収集に於いて' do + describe 'コマ地に於いて' 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 + end + it 'リストを返している' do + r = @panel.grounds + r.is_a?(Array).should be_true + end + it '景色素材と景色カラーと景色カラーコードを合わせている' do + r = @panel.grounds + r.include?(@gc).should be_true + r.include?(@gp).should be_true + r.include?(@pc).should be_true + end + it 'コマ絵とフキダシを含んでいない' do + r = @panel.grounds + r.include?(@pp).should_not be_true + r.include?(@sb).should_not be_true + end + end + describe 'コマ要素に於いて' 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 + end + context 'つつがなく終わるとき' do + it 'コマ部品を利用している' do + Panel.any_instance.stub(:parts).with(any_args).and_return([]) + Panel.any_instance.should_receive(:parts).with(any_args).exactly(1) + r = @panel.panel_elements + end + it 'コマ地を利用している' do + Panel.any_instance.stub(:grounds).with(any_args).and_return([]) + Panel.any_instance.should_receive(:grounds).with(any_args).exactly(1) + r = @panel.panel_elements + end + end + it 'リストを返している' do + r = @panel.panel_elements + r.is_a?(Array).should be_true + end + it 'コマ絵とフキダシを合わせている' do + r = @panel.panel_elements + r.include?(@pp).should be_true + r.include?(@sb).should be_true + end + it '景色素材と景色カラーと景色カラーコードを合わせている' do + r = @panel.panel_elements + r.include?(@gc).should be_true + r.include?(@gp).should be_true + r.include?(@pc).should be_true + end + it 'tでソートしている[t順にソートできる部品の方が優先順位は高い。]' do + r = @panel.panel_elements + r[0].should eq @sb + r[1].should eq @pp + end + 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 + end + context 'つつがなく終わるとき' do + before do + Panel.stub(:elm_json_opt).with(@pp).and_return({}) + Panel.stub(:elm_json_opt).with(@sb).and_return({}) + Panel.stub(:elm_json_opt).with(@gp).and_return({}) + Panel.stub(:elm_json_opt).with(@gc).and_return({}) + Panel.stub(:elm_json_opt).with(@pc).and_return({}) + end + it 'コマ要素のjson出力オプションにコマ絵json出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@pp).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションにフキダシjson出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@sb).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションに景色素材json出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@gp).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションに景色カラーjson出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@gc).exactly(1) + r = @panel.elements + end + it 'コマ要素のjson出力オプションに景色カラーコードjson出力オプションを依頼している' do + Panel.should_receive(:elm_json_opt).with(@pc).exactly(1) + r = @panel.elements + end + end + it 'リストを返している' do + r = @panel.elements + r.is_a?(Array).should be_true + end + 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 + end + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:elements).with(any_args).and_return({}) + end + it 'コマ要素のjson出力を依頼している' do + Panel.any_instance.should_receive(:elements).with(any_args).exactly(1) + r = @panel.panel_elements_as_json + end + end + it 'json textを返している' do + r = JSON.parse @panel.panel_elements_as_json + r.is_a?(Hash).should be_true + end + it 'author,コマ要素を含んでいる' do + r = JSON.parse @panel.panel_elements_as_json + r.has_key?('author').should be_true + r.has_key?('elements').should be_true + #t:0 + sb = r['elements'].first + sb.has_key?('classname').should be_true + sb.has_key?('balloons').should be_true + sb.has_key?('speeches').should be_true + #t:1 + end + end + describe '検証値収集に於いて' do context 'つつがなく終わるとき' do - it '第一パラメータで指定された配列中から第二引数のidを収集している' do - a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], + it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do + elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]] - r = Panel.collect_element_value a, :panel_id + r = Panel.collect_element_value elements, :panel_id r.should eq [1, 2, 3, 4] end + it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do + elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}], + [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]] + r = Panel.collect_element_value elements, :t + r.should eq [1, 2, 3, 0] + end end - context 'Nil除外指示があるとき' do - it '収集したpanel_idのうちnilは除外している' do - a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}], - [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]] - r = Panel.collect_element_value a, :panel_id, true - r.should eq [1, 2, 3, 4] + end + describe 'シリアライズチェックに於いて' do + context 'つつがなく終わるとき' do + it '0からシリアライズされているならTrueを返す' do + r = Panel.validate_t [0, 1, 2] + r.should be_true + end + it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do + r = Panel.validate_t [0, 2, 1] + r.should be_true + end + it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do + r = Panel.validate_t [ 2, 1, 4, 3, 0] + r.should be_true + end + end + context '異常なとき' do + it '0から始まらないならFalseを返す' do + r = Panel.validate_t [1, 2, 3] + r.should be_false + end + it '連続していないならFalseを返す' do + r = Panel.validate_t [0, 1, 2, 4] + r.should be_false + end + it '連続していないならFalseを返す' do + r = Panel.validate_t [0, 1, 2, 4, 5] + r.should be_false + end + end + end + describe 'tチェック単体に於いて' do + before do + end + context 'つつがなく終わるとき' do + it '検証値収集を依頼している' do + Panel.should_receive(:collect_element_value).with(any_args).exactly(1) + Panel.stub(:collect_element_value).with(any_args).and_return([]) + Panel.stub(:validate_t).with(any_args).and_return(true) + r = Panel.validate_element_t [], :t + end + it 'シリアライズチェック依頼している' do + Panel.stub(:collect_element_value).with(any_args).and_return([]) + Panel.should_receive(:validate_t).with(any_args).exactly(1) + Panel.stub(:validate_t).with(any_args).and_return(true) + r = Panel.validate_element_t [], :t + end + end + end + describe '従属データの検証に於いて' do + context 'つつがなく終わるとき' do + it 'trueを返している' do + @panel = FactoryGirl.build :panel, :author_id => @author.id + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + ) + sb1.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + ) + sb1.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) + ) + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3) + ) + sb2.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + ) + sb2.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) + ) + r = @panel.validate_child + r.should be_true + end + end + context 'シリアライズされていないとき' do + it 'falseを返している' do + @panel = FactoryGirl.build :panel, :author_id => @author.id + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0) + ) + @panel.panel_pictures.build( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1) + ) + sb1 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) + ) + sb1.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) + ) + sb1.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) + ) + sb2 = @panel.speech_balloons.build( + FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4) + ) + sb2.balloons.build( + FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) + ) + sb2.speeches.build( + FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) + ) + r = @panel.validate_child + r.should be_false + end + end + end + describe '保存に於いて' do + before do + @attr = FactoryGirl.attributes_for :panel + @panel = Panel.new + @panel.supply_default + end + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) + Panel.any_instance.stub(:save).with(any_args).and_return(true) + end + it 'コマモデルに上書き補充を依頼している' do + Panel.any_instance.should_receive(:overwrite).exactly(1) + r = @panel.store @attr, @author + end + it '従属データの検証を依頼している' do + Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1) + r = @panel.store @attr, @author + end + it '保存を依頼している' do + Panel.any_instance.should_receive(:save).with(any_args).exactly(1) + @panel = FactoryGirl.build :panel, :author_id => @author.id + r = @panel.store @attr, @author + end + end + context 'つつがなく終わるとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) + end + it 'Trueを返す' do + r = @panel.store @attr, @author + r.should be_true + end + it '行が追加されている' do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) + lambda { + r = @panel.store @attr, @author + }.should change(Panel, :count) + end + end + context '従属データの検証に失敗したとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(false) + end + it 'エラーメッセージがセットされている' do + r = @panel.store @attr, @author + @panel.errors.should_not be_empty + end + end + context 'カラム値がFalseしたとき' do + before do + Panel.any_instance.stub(:validate_child).with(any_args).and_return(true) end + it 'エラーメッセージがセットされている' do + r = @panel.store false, @author + @panel.errors.should_not be_empty + end + end + end +=begin + describe 'id挿げ替え防止確認に於いて' 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 + end + it 'author,コマ要素を含んでいる' do + @panel2 = FactoryGirl.create :panel, :author_id => @author.id + @panel2.panel_pictures.create( + FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height) + ) + @panel2.save! + p @panel2 + p @panel2.panel_pictures end end describe 'id一致チェックに於いて' do @@ -890,236 +1284,5 @@ describe Panel do end end end - describe 'シリアライズチェックに於いて' do - context 'つつがなく終わるとき' do - it '0からシリアライズされているならTrueを返す' do - r = Panel.validate_t [0, 1, 2] - r.should be_true - end - it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do - r = Panel.validate_t [0, 2, 1] - r.should be_true - end - it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do - r = Panel.validate_t [ 2, 1, 4, 3, 0] - r.should be_true - end - end - context '異常なとき' do - it '0から始まらないならFalseを返す' do - r = Panel.validate_t [1, 2, 3] - r.should be_false - end - it '連続していないならFalseを返す' do - r = Panel.validate_t [0, 1, 2, 4] - r.should be_false - end - it '連続していないならFalseを返す' do - r = Panel.validate_t [0, 1, 2, 4, 5] - r.should be_false - end - end - end - describe 'tチェック単体に於いて' do - before do - end - context 'つつがなく終わるとき' do - it 'コマ絵とフキダシのtを収集依頼している' do - Panel.should_receive(:collect_element_value).with(any_args).exactly(1) - Panel.stub(:collect_element_value).with(any_args).and_return([]) - Panel.stub(:validate_t).with(any_args).and_return(true) - r = Panel.validate_element_t [], :t - end - it '収集したtをシリアライズチェック依頼している' do - Panel.stub(:collect_element_value).with(any_args).and_return([]) - Panel.should_receive(:validate_t).with(any_args).exactly(1) - Panel.stub(:validate_t).with(any_args).and_return(true) - r = Panel.validate_element_t [], :t - end - end - #実データでチェック - #依頼チェックだけでは不安なので最低限のチェックを - context '新規のとき' do - it 'コマ絵で正常通過している' do - @panel = FactoryGirl.build :panel, :author_id => @author.id - @panel.panel_pictures.build( - FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - it 'フキダシで正常通過している' do - @panel = FactoryGirl.build :panel, :author_id => @author.id - @panel.speech_balloons.build( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - end - context '既存のとき' do - it 'コマ絵で正常通過している' do - @panel = FactoryGirl.create :panel, :author_id => @author.id - @panel.panel_pictures.build( - FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - it 'フキダシで正常通過している' do - @panel = FactoryGirl.create :panel, :author_id => @author.id - @panel.speech_balloons.build( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0) - ) - r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t - r.should be_true - end - end - end - describe '複合チェックに於いて' do - context 'つつがなく終わるとき' do - it 'している' do - @panel = FactoryGirl.build :panel, :author_id => @author.id - @panel.panel_pictures.build( - FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0) - ) - @panel.panel_pictures.build( - FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1) - ) - sb1 = @panel.speech_balloons.build( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) - ) - sb1.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) - ) - sb1.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) - ) - sb2 = @panel.speech_balloons.build( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3) - ) - sb2.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) - ) - sb2.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) - ) - r = @panel.validate_child - r.should be_true - end - end - end - describe '複合チェックに於いて' do - context 'つつがなく終わるとき' do - it 'している' do - @panel = FactoryGirl.build :panel, :author_id => @author.id - @panel.panel_pictures.build( - FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0) - ) - @panel.panel_pictures.build( - FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1) - ) - sb1 = @panel.speech_balloons.build( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2) - ) - sb1.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id) - ) - sb1.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id) - ) - sb2 = @panel.speech_balloons.build( - FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3) - ) - sb2.balloons.build( - FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id) - ) - sb2.speeches.build( - FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id) - ) - r = @panel.validate_child - r.should be_true - end - end - end - describe '保存に於いて' do - context 'つつがなく終わるとき' do - it 'idチェックを依頼している' do - Panel.should_receive(:validate_elements_id).with(any_args).exactly(1) - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.build :panel, :author_id => @author.id - r = @panel.store - end - it '保存を依頼している' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - Panel.any_instance.should_receive(:save).with(any_args).exactly(1) - Panel.any_instance.stub(:save).with(any_args).and_return(true) - @panel = FactoryGirl.build :panel, :author_id => @author.id - r = @panel.store - end - it 'Trueを返す' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.build :panel, :author_id => @author.id - r = @panel.store - r.should be_true - end - it 'エラーメッセージがセットされていない' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.create :panel, :author_id => @author.id - r = @panel.store - @panel.errors.empty?.should be_true - end - context '新規のとき' do - it 'Trueを返す' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.build :panel, :author_id => @author.id - r = @panel.store - r.should be_true - end - it '行が追加されている' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.build :panel, :author_id => @author.id - lambda { - r = @panel.store - }.should change(Panel, :count) - end - end - context '更新のとき' do - it 'Trueを返す' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.create :panel, :author_id => @author.id - r = @panel.store - r.should be_true - end - it '行が追加されていない' do - Panel.stub(:validate_elements_id).with(any_args).and_return(true) - @panel = FactoryGirl.create :panel, :author_id => @author.id - lambda { - r = @panel.store - }.should_not change(Panel, :count) - end - end - end - context 'idチェックが失敗するとき' do - it 'Falseを返す' do - Panel.stub(:validate_elements_id).with(any_args).and_return(false) - @panel = FactoryGirl.create :panel, :author_id => @author.id - r = @panel.store - r.should be_false - end - it 'エラーメッセージがセットされている' do - Panel.stub(:validate_elements_id).with(any_args).and_return(false) - @panel = FactoryGirl.create :panel, :author_id => @author.id - r = @panel.store - @panel.errors.empty?.should be_false - end - it '行が追加されていない' do - Panel.stub(:validate_elements_id).with(any_args).and_return(false) - @panel = FactoryGirl.build :panel, :author_id => @author.id - lambda { - r = @panel.store - }.should_not change(Panel, :count) - end - end - end +=end end diff --git a/spec/models/story_spec.rb b/spec/models/story_spec.rb index bdda0156..dfd0e84a 100644 --- a/spec/models/story_spec.rb +++ b/spec/models/story_spec.rb @@ -7,11 +7,16 @@ describe Story do @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 @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 + @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 @@ -195,19 +200,19 @@ describe Story do end end it 'リストを返す' do - c = Story.list @comic, @author + c = Story.play_list @comic, @author c.should eq [@story] end it 't順で並んでいる' do #公開コミックの公開コマは(他人のコミックであっても)含んでいる v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1 - c = Story.list @comic, @author + c = Story.play_list @comic, @author c.should eq [ @story, v] end - it '非公開のコマは含まない' do + it '非公開のコマは含んでいる' do h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1 - c = Story.list @comic, @author - c.should eq [ @story] + c = Story.play_list @comic, @author + c.should eq [ @story, h] end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do @@ -218,15 +223,15 @@ describe Story do end it 'offset=0なら末尾2件を返す' do #時系列で並んでいる - c = Story.list( @comic, @author, 0, 2) + c = Story.play_list( @comic, @author, 0, 2) c.should eq [@story, @story2] end it 'offset=2なら中間2件を返す' do - c = Story.list(@comic, @author, 2, 2) + c = Story.play_list(@comic, @author, 2, 2) c.should eq [@story3, @story4] end it 'offset=4なら先頭1件を返す' do - c = Story.list(@comic, @author, 4, 2) + c = Story.play_list(@comic, @author, 4, 2) c.should eq [@story5] end end @@ -290,71 +295,17 @@ describe Story do end end describe 'json一覧出力オプションに於いて' do - it 'includeキーを含んでいる' do - r = Story.list_json_opt - r.has_key?(:include).should be_true - end - it '3つの項目を含んでいる' do - r = Story.list_json_opt[:include] - r.should have(3).items - end - it 'コミックを含んでいる' do - r = Story.list_json_opt[:include] - r.has_key?(:comic).should be_true - end - it 'コミックは作家を含んでいる' do - r = Story.list_json_opt[:include] - r[:comic].has_key?(:author).should be_true - end - it '作家を含んでいる' do - r = Story.list_json_opt[:include] - r.has_key?(:author).should be_true - end - it 'コマを含んでいる' do - r = Story.list_json_opt[:include] - r.has_key?(:panel).should be_true - end - it 'コマは作家を含んでいる' do - r = Story.list_json_opt[:include] - r[:panel].has_key?(:author).should be_true - end - it 'コマはコマ絵を含んでいる' do - r = Story.list_json_opt[:include] - r[:panel].has_key?(:panel_pictures).should be_true - end - it 'コマ絵は実素材を含んでいる' do - r = Story.list_json_opt[:include] - r[:panel][:panel_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Story.list_json_opt[:include] - r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Story.list_json_opt[:include] - r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true - end - it 'コマはフキダシを含んでいる' do - r = Story.list_json_opt[:include] - r[:panel].has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Story.list_json_opt[:include] - r[:panel][:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - r = Story.list_json_opt[:include] - r[:panel][:speech_balloons].has_key?(:speeches).should be_true - end end describe '自分のストーリー一覧取得に於いて' do before do - @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0 - @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1 + @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + @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 @@ -377,10 +328,10 @@ describe Story do sl = Story.mylist @author sl.should eq [@story] end - it '自分のストーリーはコマコミックともには非公開でも含んでいる' do - nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100 - cl = Comic.mylist @author - cl.should eq [nc, @story] + it '自分のストーリーはコマコミックともに非公開でも含んでいる' do + hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100 + sl = Story.mylist @author + sl.should eq [hs, @story] end context 'DBに5件あって1ページの件数を2件に変えたとして' do before do @@ -519,62 +470,70 @@ describe Story do end end describe 'json単体取得オプションに於いて' do - it 'includeキーを含んでいる' do - r = Story.show_json_opt - r.has_key?(:include).should be_true - end - it '3つの項目を含んでいる' do - r = Story.show_json_opt[:include] - r.should have(3).items - end - it 'コミックを含んでいる' do - r = Story.show_json_opt[:include] - r.has_key?(:comic).should be_true - end - it 'コミックは作家を含んでいる' do - r = Story.show_json_opt[:include] - r[:comic].has_key?(:author).should be_true - end - it '作家を含んでいる' do - r = Story.show_json_opt[:include] - r.has_key?(:author).should be_true - end - it 'コマを含んでいる' do - r = Story.show_json_opt[:include] - r.has_key?(:panel).should be_true - end - it 'コマは作家を含んでいる' do - r = Story.show_json_opt[:include] - r[:panel].has_key?(:author).should be_true - end - it 'コマはコマ絵を含んでいる' do - r = Story.show_json_opt[:include] - r[:panel].has_key?(:panel_pictures).should be_true - end - it 'コマ絵は実素材を含んでいる' do - r = Story.show_json_opt[:include] - r[:panel][:panel_pictures].has_key?(:picture).should be_true - end - it '実素材は絵師を含んでいる' do - r = Story.show_json_opt[:include] - r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true - end - it '実素材はライセンスを含んでいる' do - r = Story.show_json_opt[:include] - r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true - end - it 'コマはフキダシを含んでいる' do - r = Story.show_json_opt[:include] - r[:panel].has_key?(:speech_balloons).should be_true - end - it 'フキダシはフキダシ枠を含んでいる' do - r = Story.show_json_opt[:include] - r[:panel][:speech_balloons].has_key?(:balloons).should be_true - end - it 'フキダシはセリフを含んでいる' do - r = Story.show_json_opt[:include] - r[:panel][:speech_balloons].has_key?(:speeches).should be_true - end + 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 + @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 + context '事前チェックする' do + before do + Panel.any_instance.stub(:elements).and_return('{}') + 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) + 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 + context 'コマ閲覧許可のとき' 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 + context 'コマ閲覧不許可のとき' 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 describe 't補充値に於いて' do -- 2.11.0