OSDN Git Service

t#32046:add sheet
authoryasushiito <yas@pen-chan.jp>
Sun, 13 Oct 2013 00:15:29 +0000 (09:15 +0900)
committeryasushiito <yas@pen-chan.jp>
Sun, 13 Oct 2013 00:15:29 +0000 (09:15 +0900)
32 files changed:
app/assets/javascripts/sheets.js.coffee
app/controllers/home_controller.rb
app/controllers/stories_controller.rb
app/models/comic.rb
app/models/scroll.rb
app/models/sheet.rb
app/models/sheet_panel.rb
app/models/story.rb
app/models/story_sheet.rb
app/views/panels/_body.html.erb
app/views/sheets/_body.html.erb
app/views/stories/_list_item.html.erb
app/views/stories/_play_footer.html.erb
app/views/stories/edit.html.erb
app/views/stories/play.html.erb
app/views/stories/show.html.erb
app/views/story_sheets/_list_item.html.erb
config/locales/pettanr.ja.yml
db/migrate/20130914061319_restruct_comic.rb
spec/controllers/authors_controller_spec.rb
spec/controllers/home_controller_spec.rb
spec/controllers/sheet_panels_controller_spec.rb
spec/controllers/sheets_controller_spec.rb
spec/controllers/stories_controller_spec.rb
spec/controllers/story_sheets_controller_spec.rb
spec/factories.rb
spec/models/comic_spec.rb
spec/models/scroll_spec.rb
spec/models/sheet_panel_spec.rb
spec/models/sheet_spec.rb
spec/models/story_sheet_spec.rb
spec/models/story_spec.rb

index 7615679..634a64f 100644 (file)
@@ -1,3 +1,437 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
+$ ->
+  confirm_confirm_confirm = () ->
+    confirm(  )
+  editor = window.PettanrEditor
+  
+  $('.panel-editor').map ->
+    if $(@).attr('current') and parseInt($(@).attr('current')) > 0
+      editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
+  if editor.is_editting()
+    $('#tabs').tabs()
+    $('#elements-tabs').tabs()
+    $('#new-element-tabs').tabs()
+    $('#new-speech_balloon-tabs').tabs()
+    $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
+    $("#elements-tabs li").removeClass("ui-corner-top")
+    $("#elements-tabs li").addClass("ui-corner-left")
+    $("#elements-tabs li").map ->
+      $(@).mouseover -> 
+        switch $(@).attr('element_type')
+          when 'speech_balloon'
+            trace = editor.element_tag_id($(@)) 
+            t = $('img', $(trace))
+          when 'panel_picture'
+            trace = editor.element_tag_id($(@)) + 'img'
+            t = $(trace)
+          else
+            t = null
+        if t
+          $('.ui-resizable-handle', t.parent()).map ->
+            $(@).css('display', 'block')
+      $(@).mouseout -> 
+        switch $(@).attr('element_type')
+          when 'speech_balloon'
+            trace = editor.element_tag_id($(@)) 
+            t = $('img', $(trace))
+          when 'panel_picture'
+            trace = editor.element_tag_id($(@)) + 'img'
+            t = $(trace)
+          else
+            t = null
+        if t
+          $('.ui-resizable-handle', t.parent()).map ->
+            $(@).css('display', 'none')
+    
+    #destroy button
+    $('.ui-icon-destroy').map ->
+      $(@).button {
+        icons: {
+          primary: 'ui-icon-close', 
+          secondary: null
+        }, 
+        text: false
+      }
+      $(@).click -> 
+        if confirm('destroy ?')
+          trace = editor.element_tag_id($(@))
+          $(trace + '_destroy').val('true')
+          panel_trace = editor.panel_tag_id($(@))
+          update_t(panel_trace + 'tsort')
+          update_z(panel_trace + 'zsort')
+          # sync
+          $(trace + 'element_tab').css('display', 'none')
+          $(trace + 'tab_panel').css('display', 'none')
+          $(trace + 'zsort').css('display', 'none')
+          $(trace + 'tsort').css('display', 'none')
+          switch $(@).attr('element_type')
+            when 'panel_picture'
+              trace = trace + 'div'
+          $(trace).css('display', 'none')
+          
+    
+    $('#pettanr-panel-submit').focusin ->
+      editor.refresh_attribute($('#pettanr-panel-json'))
+    
+    # panel
+    $('.pettanr-comic-panel').map ->
+      if editor.is_editable($(@))
+        $(@).resizable {
+          stop: ( event, ui ) ->
+            trace = editor.panel_tag_id($(@))
+            w = parseInt($(@).width())
+            h = parseInt($(@).height())
+            $(trace + 'width').val(w)
+            $(trace + 'height').val(h)
+            $('.pettanr-comic-ground-picture').map ->
+              $(@).width(w)
+              $(@).height(h)
+            $('.pettanr-comic-ground-color').map ->
+              $(@).width(w)
+              $(@).height(h)
+          , autoHide: true
+        }
+    
+    # sync view 
+    $('input').map  ->
+      if $(@).attr('element_type')
+      else
+        if $(@).attr('panel_id')
+          $(@).focusout ->
+            switch $(@).attr('column')
+              when 'width'
+                trace = editor.panel_tag_id($(@))
+                $(trace).width(parseInt( $(@).val()))
+              when 'height'
+                trace = editor.panel_tag_id($(@))
+                $(trace).height(parseInt( $(@).val()))
+              when 'border'
+                trace = editor.panel_tag_id($(@))
+                $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
+    
+    # panel picture
+    PictureSizeHelper.add_helper()
+    
+    $('.pettanr-panel-picture-wrapper').map ->
+      $(@).draggable {
+        stop: ( event, ui ) ->
+          trace = editor.element_tag_id($(@))
+          img = $(trace + 'img')
+          left = img.parent().position().left + $(@).position().left
+          top = img.parent().position().top + $(@).position().top
+          $(trace + 'x').val(parseInt(left))
+          $(trace + 'y').val(parseInt(top))
+      }
+    
+    $('.panel-picture').map ->
+      $(@).resizable {
+        stop: ( event, ui ) ->
+          resize_div = $(@)
+          panel_picture_div = resize_div.parent()
+          trace = editor.element_tag_id(panel_picture_div)
+          
+          resize_div.css('top', '0px')
+          resize_div.css('left', '0px')
+          if ui.originalPosition.top != ui.position.top
+            t = panel_picture_div.position().top + ui.position.top
+            $(trace + 'y').val(Math.floor(t))
+            panel_picture_div.css('top', t.toString() + 'px')
+          if ui.originalPosition.left != ui.position.left
+            l = panel_picture_div.position().left + ui.position.left
+            $(trace + 'x').val(Math.floor(l))
+            panel_picture_div.css('left', l.toString() + 'px')
+          w = if $(trace + 'width').val() < 0
+            -ui.size.width
+          else
+            ui.size.width
+          h = if $(trace + 'height').val() < 0
+            -ui.size.height
+          else
+            ui.size.height
+          $(trace + 'width').val(w)
+          $(trace + 'height').val(h)
+        resize: ( event, ui ) ->
+          resize_div = $(@)
+          panel_picture_div = resize_div.parent()
+          trace = editor.element_tag_id(panel_picture_div)
+        handles: 'all',
+        autoHide: true
+      }
+    
+    # sync view 
+    $('input').map  ->
+      if editor.element_is('panel_picture', $(@))
+        $(@).focusout ->
+          switch $(@).attr('column')
+            when 'x'
+              trace = editor.element_tag_id($(@)) + 'div'
+              v = parseInt($(@).val()).toString() + 'px'
+              $(trace).css('left', v)
+            when 'y'
+              trace = editor.element_tag_id($(@)) + 'div'
+              v = parseInt($(@).val()).toString() + 'px'
+              $(trace).css('top', v)
+            when 'width'
+              trace = editor.element_tag_id($(@)) + 'img'
+              w = parseInt($(@).val())
+              $(trace).width(Math.abs(w))
+              $(trace).parent().width(Math.abs(w))
+              h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
+            when 'height'
+              trace = editor.element_tag_id($(@)) + 'img'
+              h = parseInt($(@).val())
+              $(trace).height(Math.abs(h))
+              $(trace).parent().height(Math.abs(h))
+              w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
+            else
+          PictureSizeHelper.refresh_picture($(trace), w, h)
+      else
+    
+    # speech_balloons
+    ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
+    
+    $('.pettanr-comic-balloon' ).map ->
+      $(@).draggable {
+        stop: ( event, ui ) ->
+          balloon = $('.pettanr-balloon', $(@))
+          trace = editor.element_part_tag_id(balloon)
+          left = $(@).position().left
+          top = $(@).position().top
+          $(trace + 'x').val(parseInt(left))
+          $(trace + 'y').val(parseInt(top))
+      }
+    
+    $('.pettanr-balloon' ).map ->
+      $(@).resizable {
+        stop: ( event, ui ) ->
+          resize_div = $(@)
+          speech_balloon_div = resize_div.parent()
+          balloon = $('.pettanr-balloon', $(@))
+          trace = editor.element_tag_id(speech_balloon_div)
+          trace_balloon = editor.element_part_tag_id(balloon)
+          
+          resize_div.css('top', '0px')
+          resize_div.css('left', '0px')
+          w = ui.size.width
+          h = ui.size.height
+          if ui.originalPosition.top != ui.position.top
+            t = speech_balloon_div.position().top + ui.position.top
+            $(trace_balloon + 'y').val(Math.floor(t))
+            speech_balloon_div.css('top', t.toString() + 'px')
+            speech_balloon_div.css('height', h + 'px')
+          if ui.originalPosition.left != ui.position.left
+            l = speech_balloon_div.position().left + ui.position.left
+            $(trace_balloon + 'x').val(Math.floor(l))
+            speech_balloon_div.css('left', l.toString() + 'px')
+            speech_balloon_div.css('width', w + 'px')
+          $(trace_balloon + 'width').val(w)
+          $(trace_balloon + 'height').val(h)
+          speech_balloon_div.css('width', w.toString() + 'px')
+          speech_balloon_div.css('height', h.toString() + 'px')
+       resize: ( event, ui ) ->
+          resize_div = $(@)
+          speech_balloon_div = resize_div.parent()
+          balloon = $('.pettanr-balloon', $(@))
+          trace = editor.element_tag_id(speech_balloon_div)
+          trace_balloon = editor.element_part_tag_id(balloon)
+        handles: 'all',
+        autoHide: true
+      }
+    
+    $('.pettanr-comic-speech-inner' ).map ->
+      $(@).mouseover -> 
+        outer = $(@).parent()
+        sb = outer.parent()
+        trace = editor.element_tag_id(sb)
+        img = $('.pettanr-balloon', $(trace))
+        $('.ui-resizable-handle', img.parent()).map ->
+          $(@).css('display', 'block')
+      $(@).mouseout -> 
+        outer = $(@).parent()
+        sb = outer.parent()
+        trace = editor.element_tag_id(sb)
+        img = $('.pettanr-balloon', $(trace))
+        $('.ui-resizable-handle', img.parent()).map ->
+          $(@).css('display', 'none')
+          
+    
+    # sync view 
+    $('input').map  ->
+      if editor.element_is('speech_balloon', $(@))
+        $(@).focusout ->
+          switch $(@).attr('column')
+            when 'x'
+              trace = editor.element_tag_id($(@))
+              v = parseInt($(@).val()).toString() + 'px'
+              $(trace).css('left', v)
+            when 'y'
+              trace = editor.element_tag_id($(@))
+              v = parseInt($(@).val()).toString() + 'px'
+              $(trace).css('top', v)
+            when 'width'
+              trace = editor.element_tag_id($(@))
+              v = parseInt($(@).val())
+              $(trace).width(Math.abs(v))
+              img = $('.pettanr-balloon', $(trace))
+              img.parent().width(v)
+              img.width(v)
+            when 'height'
+              trace = editor.element_tag_id($(@))
+              v = parseInt($(@).val())
+              $(trace).height(Math.abs(v))
+              img = $('.pettanr-balloon', $(trace))
+              img.parent().height(v)
+              img.height(v)
+            else
+      else
+    $('textarea').map  ->
+      if editor.element_is('speech_balloon', $(@))
+        $(@).focusout ->
+          switch $(@).attr('column')
+            when 'content'
+              trace = editor.element_part_tag_id($(@))
+              wf_sel = $(trace + 'writing_format_id')
+              wf_id = parseInt(wf_sel.val())
+              v = WritingFormat.render(wf_id, $(@).val())
+              $(trace).html(v)
+    $('textarea').map  ->
+      if editor.element_is('speech_balloon', $(@))
+        switch $(@).attr('column')
+          when 'content'
+            $(@).bind('textchange', (event, previousText) ->
+              trace = editor.element_part_tag_id($(@))
+              wf_sel = $(trace + 'writing_format_id')
+              wf_id = parseInt(wf_sel.val())
+              v = WritingFormat.render(wf_id, $(@).val())
+              $(trace).html(v)
+            )
+    $('select').map  ->
+      if editor.element_is('speech_balloon', $(@))
+        $(@).change ->
+          switch $(@).attr('column')
+            when 'font_size'
+              trace = editor.element_part_tag_id($(@))
+              $(trace).css('font-size', $(@).val() + 'em')
+            when 'text_align'
+              trace = editor.element_part_tag_id($(@))
+              v = parseInt($(@).val())
+              $(trace).css('text-align', editor.text_align_texts[v])
+      else
+    $('input').map  ->
+      if editor.element_is('speech_balloon', $(@))
+        if $(@).attr('column') == 'fore_color'
+          $(@).hide()
+
+    
+    # ground-picture
+    # sync view 
+    $('input').map  ->
+      if editor.element_is('ground_picture', $(@))
+        $(@).focusout ->
+          switch $(@).attr('column')
+            when 'x', 'y'
+              trace = editor.element_tag_id($(@))
+              x = parseInt($(trace + 'x').val()).toString() + 'px'
+              y = parseInt($(trace + 'y').val()).toString() + 'px'
+              $(trace).css('background-position', x + ' ' + y)
+    $('select').map  ->
+      if editor.element_is('ground_picture', $(@))
+        $(@).change ->
+          switch $(@).attr('column')
+            when 'repeat'
+              trace = editor.element_tag_id($(@))
+              v = parseInt($(@).val())
+              $(trace).css('background-repeat', editor.repeat_texts[v])
+      else
+    
+    
+    # ground_color
+    ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
+    
+    # sync view 
+    $('input').map  ->
+      if editor.element_is('ground_color', $(@))
+        if $(@).attr('column') == 'code'
+          $(@).hide()
+
+    update_t = (ultrace) -> 
+      t = 0
+      $(ultrace + ' li').map ->
+        trace = editor.element_tag_id($(@))
+        if $(trace + '_destroy').val().length < 1
+          $(trace + 't').val(t)
+          t++
+        else
+    
+    $('.tsort').map -> 
+      $(@).sortable {
+        update: ( event, ui ) ->
+          trace = editor.panel_tag_id($(@))
+          update_t(trace + 'tsort')
+      }
+    $('.t-sort li').map -> 
+      $(@).disableSelection()
+    
+    update_z = (ultrace) -> 
+      z = 1
+      $(ultrace + ' li').map ->
+        trace = editor.element_tag_id($(@))
+        # update panel
+        if $(trace + '_destroy').val().length < 1
+          $(trace + 'z').val(z)
+          switch $(@).attr('element_type')
+            when 'panel_picture'
+              trace = trace + 'div'
+          $(trace).css('zIndex', z)
+          z++
+        else
+    
+    $('.zsort').map -> 
+      $(@).sortable {
+        update: ( event, ui ) ->
+          trace = editor.panel_tag_id($(@))
+          update_z(trace + 'zsort')
+      }
+    $('.z-sort li').map -> 
+      $(@).disableSelection()
+    
+    # all
+    # disable form actions
+    # hide submit buttons
+    $('.edit_panel_picture' ).map ->
+      $(@).submit ->
+        false
+    $('.edit_speech_balloon' ).map ->
+      $(@).submit ->
+        false
+    $('.edit_ground_picture' ).map ->
+      $(@).submit ->
+        false
+    $('.edit_ground_color' ).map ->
+      $(@).submit ->
+        false
+    
+    $('.edit_panel' ).map ->
+      if $(@).attr('jqform')
+      else
+        $(@).submit ->
+          false
+    
+    $('.submit' ).map ->
+      $(@).hide()
+    
+    # disable form z t
+    $('input').map  ->
+      if editor.is_element($(@))
+        switch $(@).attr('column')
+          when 'z' , 't'
+            $(@).hide()
+            $(@).parent().hide() #label
+    
+    # add button on new form
+    $('.submit-new-form').map ->
+      $(@).html('<button class="new-element">add</button>')
+    
+    $('.new-element').map ->
+      $(@).click -> 
+        false
+    
index 26ddfc5..a09252f 100644 (file)
@@ -2,9 +2,9 @@ class HomeController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
   before_filter :authenticate_user, :only => [
     :index, :show, :profile, :configure, :create_token, :delete_token, 
-    :scrolls, :scroll_panels, :comics, :stories, :story_sheet, :sheets, :sheet_panels, :panels, :resource_pictures, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors
+    :scrolls, :scroll_panels, :comics, :stories, :story_sheets, :sheets, :sheet_panels, :panels, :resource_pictures, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors
   ]
-  before_filter :authenticate_author, :only => [:scrolls, :scroll_panels, :comics, :sheets, :sheet_panels, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
+  before_filter :authenticate_author, :only => [:scrolls, :scroll_panels, :comics, :stories, :story_sheets, :sheets, :sheet_panels, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
   before_filter :authenticate_artist, :only => [:resource_pictures]
   
   def index
index 3a4a41c..366c4a8 100644 (file)
@@ -28,12 +28,11 @@ class StoriesController < ApplicationController
 
     respond_to do |format|
       format.html { 
-        @sheet = StorySheet.play_sheet(@story, @author)
         if @author
           @new_sheets = Sheet.mylist(@author, 1, 5)
         end
       }
-      format.json { render json: @story.story_as_json(@author) }
+      format.json { render json: @story.to_json(Story.show_json_opt) }
     end
   end
   
@@ -48,7 +47,14 @@ class StoriesController < ApplicationController
           @new_sheets = Sheet.mylist(@author, 1, 5)
         end
       }
-      format.json {render text: StorySheet.list_as_json_text(@story_sheets, @author)}
+      format.json {
+        if @sheet
+          @story_sheets = SheetPanel.play_list @sheet, @author
+          render text: SheetPanel.list_as_json_text(@story_sheets, @author)
+        else
+          render text: ''
+        end
+      }
       format.jsonp {
         render :json => "callback(" + @story_sheets.to_json_list + ");"
       }
@@ -79,7 +85,7 @@ class StoriesController < ApplicationController
     respond_to do |format|
       format.html # new.html.erb
       format.js
-      format.json { render json: @story.story_as_json(@author) }
+      format.json { render json: @story.to_json(Story.show_json_opt) }
     end
   end
 
@@ -95,14 +101,14 @@ class StoriesController < ApplicationController
     @story = Story.new 
     @story.supply_default
     @story.attributes = params[:story]
-    @story.overwrite @author
+    @story.overwrite
     @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
     
     respond_to do |format|
-      if @story.store
+      if @story.store @author
         flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
-        format.html { redirect_to story_path(@story) }
-        format.json { render json: @story.story_as_json(@author) }
+        format.html { redirect_to play_story_path(@story, :page => @story.t.to_i + 1) }
+        format.json { render json: @story.to_json(Story.show_json_opt) }
       else
         flash[:notice] = I18n.t('flash.notice.not_created', :model => Story.model_name.human)
         format.html { render action: "new" }
@@ -115,11 +121,11 @@ class StoriesController < ApplicationController
     @story = Story.edit(params[:id], @author)
     ot = @story.t
     @story.attributes = params[:story]
-    @story.overwrite @author
+    @story.overwrite
     respond_to do |format|
-      if @story.store ot
+      if @story.store  @author, ot
         flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
-        format.html { redirect_to story_path(@story) }
+        format.html { redirect_to play_story_path(@story, :page => @story.t.to_i + 1) }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Story.model_name.human)
index 0c3527b..187385a 100644 (file)
@@ -5,6 +5,8 @@ class Comic < ActiveRecord::Base
   
   validates :title, :presence => true, :length => {:maximum => 100}
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+  validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
+  
   before_validation :valid_encode
   
   def valid_encode
index 5588f43..73409de 100644 (file)
@@ -4,6 +4,8 @@ class Scroll < ActiveRecord::Base
   
   validates :title, :presence => true, :length => {:maximum => 100}
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+  validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
+
   before_validation :valid_encode
   
   def valid_encode
index a3b8bff..eb9cd35 100644 (file)
@@ -4,11 +4,13 @@ class Sheet < ActiveRecord::Base
   belongs_to :author
   
   validates :caption, :presence => true, :length => {:maximum => 100}
+  validates :width, :presence => true, :numericality => true, :natural_number => true
+  validates :height, :presence => true, :numericality => true, :natural_number => true
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
   before_validation :valid_encode
   
   def valid_encode
-    ['caption', 'description'].each do |a|
+    ['caption'].each do |a|
       next if attributes[a] == nil
       raise Pettanr::BadRequest unless attributes[a].valid_encoding?
     end
index 74b8aa3..6eb7c72 100644 (file)
@@ -42,29 +42,6 @@ class SheetPanel < ActiveRecord::Base
     self.sheet.visible? roles
   end
   
-  def self.default_panel_size
-    30
-  end
-  
-  def self.max_panel_size
-    200
-  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.panel_count cnt, prm = self.default_panel_size
-    count = prm.to_i
-    count = self.max_panel_size if count > self.max_panel_size
-    count = self.default_panel_size if count < 1
-    count
-  end
-  
   def self.default_page_size
     25
   end
@@ -102,8 +79,8 @@ class SheetPanel < ActiveRecord::Base
     ['sheet_panels.author_id = ? and sheets.visible > 0', au.id]
   end
   
-  def self.play_list sheet, author, offset = 0, limit = SheetPanel.default_panel_size
-    SheetPanel.where(self.play_list_where(sheet.id)).includes(SheetPanel.list_opt).order('sheet_panels.t').offset(offset).limit(limit)
+  def self.play_list sheet, author
+    SheetPanel.where(self.play_list_where(sheet.id)).includes(SheetPanel.list_opt).order('sheet_panels.t')
   end
   
   def self.list page = 1, page_size = self.default_page_size
index b94b11d..7fadd62 100644 (file)
@@ -1,13 +1,11 @@
 #ストーリー
 class Story < ActiveRecord::Base
-  belongs_to :author
   has_many :story_sheets
   belongs_to :comic
   
   validates :comic_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :title, :presence => true, :length => {:maximum => 100}
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
-  validates :author_id, :presence => true, :numericality => true, :existence => {:both => false}
   validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
   before_validation :valid_encode
   
@@ -24,16 +22,14 @@ class Story < ActiveRecord::Base
     self.t = nil
   end
   
-  def overwrite au
-    return false unless au
-    self.author_id = au.id
+  def overwrite
   end
   
   def own? roles
     roles = [roles] unless roles.respond_to?(:each)
     au = Story.get_author_from_roles roles
     return false unless au
-    self.author_id == au.id
+    self.comic.author_id == au.id
   end
   
   def visible? roles
@@ -84,11 +80,11 @@ class Story < ActiveRecord::Base
   end
   
   def self.mylist_where au
-    ['stories.author_id = ?', au.id]
+    ['comics.author_id = ?', au.id]
   end
   
   def self.himlist_where au
-    ['stories.author_id = ? and stories.visible > 0', au.id]
+    ['comics.author_id = ? and stories.visible > 0', au.id]
   end
   
   def self.list page = 1, page_size = self.default_page_size
@@ -104,23 +100,23 @@ class Story < ActiveRecord::Base
   end
   
   def self.list_paginate page = 1, page_size = self.default_page_size
-    Kaminari.paginate_array(Array.new(Story.where(self.list_where()).count, nil)).page(page).per(page_size)
+    Kaminari.paginate_array(Array.new(Story.where(self.list_where()).includes(Story.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.mylist_paginate au, page = 1, page_size = Author.default_story_page_size
-    Kaminari.paginate_array(Array.new(Story.where(self.mylist_where(au)).count, nil)).page(page).per(page_size)
+    Kaminari.paginate_array(Array.new(Story.where(self.mylist_where(au)).includes(Story.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.himlist_paginate au, page = 1, page_size = Author.default_story_page_size
-    Kaminari.paginate_array(Array.new(Story.where(self.himlist_where(au)).count, nil)).page(page).per(page_size)
+    Kaminari.paginate_array(Array.new(Story.where(self.himlist_where(au)).includes(Story.list_opt).count, nil)).page(page).per(page_size)
   end
   
   def self.list_opt
-    {:author => {}, :story_sheets => {:sheet => {}, :author => {}} }
+    {:comic => {:author => {}} }
   end
   
   def self.list_json_opt
-    {:include => {:author => {}, :story_sheets => {:include => {:sheet => {}, :author => {}}} }}
+    {:include => {:comic => {:include => {:author => {}}} }}
   end
   
   def self.show sid, roles
@@ -140,11 +136,11 @@ class Story < ActiveRecord::Base
   end
   
   def self.show_opt
-    {:include => {:author => {}, :story_sheets => {:sheet => {}, :author => {}} }}
+    {:include => {:comic => {:author => {}} }}
   end
   
   def self.show_json_opt
-    {:include => {:author => {}, :story_sheets => {:include => {:sheet => {}, :author => {}}} }}
+    {:include => {:comic => {:include => {:author => {}}} }}
   end
   
   def self.visible_count
@@ -233,15 +229,15 @@ class Story < ActiveRecord::Base
     end
   end
   
-  def allow?
+  def allow? au
     return nil if self.comic_id == nil
-    self.comic.own?(self.author)
+    self.comic.own?(au)
   end
   
-  def store old_t = nil
+  def store au, old_t = nil
     res = false
     Story.transaction do
-      case self.allow?
+      case self.allow? au
       when true
         self.rotate old_t
       when false
index 699b444..2ab6e17 100644 (file)
@@ -73,7 +73,7 @@ class StorySheet < ActiveRecord::Base
     page_size
   end
   
-  def self.play_list_where sid
+  def self.play_sheet_where sid
     ['story_sheets.story_id = ?', sid]
   end
   
@@ -90,8 +90,16 @@ class StorySheet < ActiveRecord::Base
   end
   
   def self.play_sheet story, au, page = 1
-    ss = StorySheet.where(self.play_list_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
-    ss ? ss.sheet : nil
+    ss = StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(page -1).limit(1).first
+    if ss 
+      if ss.sheet
+        Sheet.show(ss.sheet.id, au)
+      else
+        nil
+      end
+    else
+      nil
+    end
   end
   
   def self.list page = 1, page_size = self.default_page_size
@@ -119,14 +127,13 @@ class StorySheet < ActiveRecord::Base
   end
   
   def self.play_paginate story, page
-    Kaminari.paginate_array(Array.new(StorySheet.where(self.play_list_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
+    Kaminari.paginate_array(Array.new(StorySheet.where(self.play_sheet_where(story.id)).includes(StorySheet.list_opt).count, nil)).page(page).per(1)
   end
   
   def self.list_opt
     {
       :author => {}, 
       :story => {
-        :author => {}
       }, 
       :sheet => {
         :author => {},
@@ -137,7 +144,7 @@ class StorySheet < ActiveRecord::Base
   def self.list_json_opt
     {:include => {
       :author => {}, 
-      :story => {:include => {:author => {}}} ,
+      :story => {} ,
       :sheet => {:include => {:author => {}}} 
     }}
   end
@@ -161,9 +168,7 @@ class StorySheet < ActiveRecord::Base
   def self.show_opt
     {:include => {
       :author => {}, 
-      :story => {
-        :author => {}
-      }, 
+      :story => {}, 
       :sheet => {
         :author => {} 
       }
@@ -173,11 +178,28 @@ class StorySheet < ActiveRecord::Base
   def self.show_json_opt
     {:include => {
       :author => {}, 
-      :story => {:include => {:author => {}}} ,
+      :story => {} ,
       :sheet => {:include => {:author => {}}} 
     }}
   end
   
+  def elements
+    self.panel.elements
+  end
+  
+  def story_sheet_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 => {:scroll => {:include => {:author => {}}}, :author => {}, :panel => panel_include}})
+  end
+  
+  def self.list_as_json_text ary, au
+    '[' + ary.map {|i| i.story_sheet_as_json(au) }.join(',') + ']'
+  end
+  
   def self.new_t story_id
     r = StorySheet.max_t(story_id)
     r.blank? ? 0 : r.to_i + 1
index 29103e0..1002028 100644 (file)
@@ -5,7 +5,11 @@
   <% end %>
 <% end %>
 <div id="<%= panel.tag_id -%>" panel_id="<%= panel.tag_panel_id -%>" class="pettanr-comic-panel" style="width:<%= panel.width %>px;height:<%= panel.height %>px;border-style: solid;border-width: <%= panel.border %>px;border-color:black; background-color:white;">
-  <% panel.panel_elements.each do |elm| %>
-    <%= render elm.class.to_s.tableize + '/element', :elm => elm, :spot => spot %>
+  <% if panel.visible? author -%>
+    <% panel.panel_elements.each do |elm| %>
+      <%= render elm.class.to_s.tableize + '/element', :elm => elm, :spot => spot %>
+    <% end %>
+  <% else %>
+    <h2><%= t('panels.hidden') %></h2>
   <% end %>
 </div>
index de9e841..d7f2ba9 100644 (file)
@@ -1,9 +1,13 @@
 <div id="sheet-<%= sheet.id -%>" class="sheet" style="width:<%= sheet.width %>px;height:<%= sheet.height %>px;">
-  <% sheet_panels.each do |sheet_panel| %>
-    <div id="sheet_panel-<%= sheet_panel.id -%>" class="sheet_panel" style="top:<%= sheet_panel.y %>px; left:<%= sheet_panel.x %>px; z-index:<%= sheet_panel.z %>;">
-      <% if sheet_panel.panel -%>
-        <%= render 'panels/body', :panel => sheet_panel.panel, :author => author, :spot => nil %>
-      <% end %>
-    </div>
+  <% if sheet.visible? author -%>
+    <% sheet_panels.each do |sheet_panel| %>
+      <div id="sheet_panel-<%= sheet_panel.id -%>" class="sheet_panel" style="top:<%= sheet_panel.y %>px; left:<%= sheet_panel.x %>px; z-index:<%= sheet_panel.z %>;">
+        <% if sheet_panel.panel -%>
+          <%= render 'panels/body', :panel => sheet_panel.panel, :author => author, :spot => nil %>
+        <% end %>
+      </div>
+    <% end %>
+  <% else %>
+    <h2><%= t('sheets.hidden') %></h2>
   <% end %>
 </div>
index ffc557c..4e9e7f4 100644 (file)
@@ -15,9 +15,6 @@
       <%= link_to h(story.title), play_story_path(story) %>
     </td>
     <td>
-      <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %>
-    </td>
-    <td>
       No.<%= story.t %>
     </td>
     <td>
index f68d13d..055a4cf 100644 (file)
@@ -5,10 +5,6 @@
         <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
         <%= link_to h(truncate(story.title, :length => 12)), play_story_path(story) %>
       </td>
-      <td>
-        <%= link_to author_icon(:object => story.author, :size => 25), author_path(story.author) %>
-        <%= link_to h(truncate(story.author.name, :length => 12)), author_path(story.author) %>
-      </td>
       <% if story.own? @author -%>
         <td>
           <%= form_for(story) do |f| %>
index 0ee86fd..1d67f75 100644 (file)
@@ -2,4 +2,3 @@
 <p id="notice"><%= notice %></p>
 
 <%= render 'form' %>
-<%= button_to 'Destroy', @story, confirm: 'Are you sure?', method: :delete %>
index 529d191..22e014f 100644 (file)
@@ -13,7 +13,7 @@
 <% else %>
   <h2><%= t('stories.play.empty') %></h2>
 <% end %>
-<%= render 'stories/play_footer', :story => @story, :sheet => @sheet, :author => @author %>
+<%= render 'stories/play_footer', :story => @story, :author => @author %>
 
 <% if @story.own? @author -%>
   <h3><%= t('story_sheets.append.new_sheets') -%></h3>
index 73b5cb3..d525d63 100644 (file)
 </p>
 
 <p>
-  <b><%= t_m 'Story.author_id' -%>:</b>
-  <%= link_to author_icon(:object => @story.author), author_path(@story.author) %>
-  <%= link_to h(@story.author.name), author_path(@story.author) %>
-</p>
-
-<p>
   <b><%= t_m 'Story.created_at' -%>:</b>
   <%= l @story.created_at %>
 </p>
index 81597b1..8c5f837 100644 (file)
@@ -6,9 +6,6 @@
       <%= link_to h(story_sheet.story.title), play_story_path(story_sheet.story) %>
     </td>
     <td>
-      <%= link_to author_icon(:object => story_sheet.story.author, :size => 17), author_path(story_sheet.story.author) %>
-    </td>
-    <td>
       <%= link_to story_sheet_icon(:object => story_sheet, :size => 25), story_sheet_path(story_sheet) %>
     </td>
     <td>
index 3eb8d47..4217dfc 100644 (file)
@@ -669,6 +669,7 @@ ja:
       title: 用紙 生一覧
     browse:
       title: 用紙 生単票
+    hidden: 権限がありません
   sheet_panels:
     index:
       title: 紙コマ一覧
@@ -720,6 +721,7 @@ ja:
     create_from_json: jsonデータからコマ作成する
     element_copy: つかんでいるコマにコピーしたい
     inspire: インスパイヤ
+    hidden: 権限がありません
   panel_pictures:
     index:
       title: コマ絵一覧
index 3e3838f..0177753 100644 (file)
@@ -15,7 +15,6 @@ class RestructComic < ActiveRecord::Migration
       t.string :title, :null => false, :limit => 100
       t.integer :visible, :null => false, :default => 0
       t.text :description
-      t.integer :author_id, :null => false, :default => 0
       t.integer :t, :null => false, :default => 0
 
       t.timestamps
index 8908447..950361c 100644 (file)
@@ -245,7 +245,7 @@ if MagicNumber['run_mode'] == 1
 =end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82³ã\83\9fã\83\83ã\82¯一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@@ -290,7 +290,7 @@ if MagicNumber['run_mode'] == 1
         Author.should_receive(:show).exactly(1)
         get :scrolls, :id => @other_author.id
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに一覧を問い合わせている' do
         Scroll.should_receive(:himlist).exactly(1)
         get :scrolls, :id => @other_author.id
       end
@@ -313,7 +313,7 @@ if MagicNumber['run_mode'] == 1
           get :scrolls, :id => @other_author.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにjson一覧出力オプションを問い合わせている' do
+        it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにjson一覧出力オプションを問い合わせている' do
           Scroll.should_receive(:list_json_opt).exactly(1)
           get :scrolls, :id => @other_author.id, :format => :json
         end
@@ -322,7 +322,7 @@ if MagicNumber['run_mode'] == 1
           json = JSON.parse response.body
           json.should have_at_least(3).items
         end
-        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82³ã\83\9fã\83\83ã\82¯っぽいものであって欲しい' do
+        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82¹ã\82¯ã\83­ã\83¼ã\83«っぽいものであって欲しい' do
           get :scrolls, :id => @other_author.id, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("title").should be_true
@@ -376,7 +376,7 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\82³ã\83\9e一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@@ -423,7 +423,7 @@ if MagicNumber['run_mode'] == 1
         Author.should_receive(:show).exactly(1)
         get :scroll_panels, :id => @other_author.id
       end
-      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81«ä»\96ä½\9c家ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81«ä»\96ä½\9c家ã\81®ã\82¹ã\82¯ã\82³ã\83\9e一覧を問い合わせている' do
         ScrollPanel.should_receive(:himlist).exactly(1)
         get :scroll_panels, :id => @other_author.id
       end
@@ -446,7 +446,7 @@ if MagicNumber['run_mode'] == 1
           get :scroll_panels, :id => @other_author.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルにjson一覧出力オプションを問い合わせている' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9eモデルにjson一覧出力オプションを問い合わせている' do
           ScrollPanel.should_receive(:list_json_opt).exactly(1)
           get :scroll_panels, :id => @other_author.id, :format => :json
         end
@@ -455,7 +455,7 @@ if MagicNumber['run_mode'] == 1
           json = JSON.parse response.body
           json.should have_at_least(3).items
         end
-        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82¹ã\83\88ã\83¼ã\83ªã\83¼っぽいものであって欲しい' do
+        it 'ã\83ªã\82¹ã\83\88ã\81®å\85\88é ­ã\81\8fã\82\89ã\81\84ã\81¯ã\82¹ã\82¯ã\82³ã\83\9eっぽいものであって欲しい' do
           get :scroll_panels, :id => @other_author.id, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("panel_id").should be_true
@@ -510,6 +510,403 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
+  describe '対象作家のコミック一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      Author.stub(:show).and_return(@other_author)
+      Comic.stub(:himlist).and_return([@comic, @comic, @comic])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :comics, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :comics, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :comics, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :comics, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.comic_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :comics, :id => @other_author.id
+      end
+      it 'コミックモデルに一覧を問い合わせている' do
+        Comic.should_receive(:himlist).exactly(1)
+        get :comics, :id => @other_author.id
+      end
+      it '@comicsにリストを取得している' do
+        get :comics, :id => @other_author.id
+        assigns(:comics).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :comics, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'comicsテンプレートを描画する' do
+          get :comics, :id => @other_author.id
+          response.should render_template("comics")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
+          Comic.should_receive(:list_json_opt).exactly(1)
+          get :comics, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :comics, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
+          get :comics, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("title").should be_true
+          json.first.has_key?("visible").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :comics, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :comics, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :comics, :id => @other_author.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comics, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '対象作家のストーリー一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+      Author.stub(:show).and_return(@other_author)
+      Story.stub(:himlist).and_return([@story, @story, @story])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :stories, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :stories, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :stories, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :stories, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_story_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :stories, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.story_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :stories, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_story_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :stories, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :stories, :id => @other_author.id
+      end
+      it 'ストーリーモデルに他作家のストーリー一覧を問い合わせている' do
+        Story.should_receive(:himlist).exactly(1)
+        get :stories, :id => @other_author.id
+      end
+      it '@storiesにリストを取得している' do
+        get :stories, :id => @other_author.id
+        assigns(:stories).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :stories, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'storiesテンプレートを描画する' do
+          get :stories, :id => @other_author.id
+          response.should render_template("stories")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :stories, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
+          Story.should_receive(:list_json_opt).exactly(1)
+          get :stories, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :stories, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+          get :stories, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("comic_id").should be_true
+          json.first.has_key?("title").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :stories, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :stories, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :stories, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :stories, :id => @other_author.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :stories, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :stories, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '対象作家のスト紙一覧表示に於いて' do
+    before do
+      @other_user = FactoryGirl.create( :user_yas)
+      @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+      @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+      Author.stub(:show).and_return(@other_author)
+      StorySheet.stub(:himlist).and_return([@story_sheet, @story_sheet, @story_sheet])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :story_sheets, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :story_sheets, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :story_sheets, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :story_sheets, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_story_sheet_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :story_sheets, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.story_sheet_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :story_sheets, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_story_sheet_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :story_sheets, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :story_sheets, :id => @other_author.id
+      end
+      it 'スト紙モデルに他作家のスト紙一覧を問い合わせている' do
+        StorySheet.should_receive(:himlist).exactly(1)
+        get :story_sheets, :id => @other_author.id
+      end
+      it '@story_sheetsにリストを取得している' do
+        get :story_sheets, :id => @other_author.id
+        assigns(:story_sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :story_sheets, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'story_sheetsテンプレートを描画する' do
+          get :story_sheets, :id => @other_author.id
+          response.should render_template("story_sheets")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スト紙モデルにjson一覧出力オプションを問い合わせている' do
+          StorySheet.should_receive(:list_json_opt).exactly(1)
+          get :story_sheets, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("story_id").should be_true
+          json.first.has_key?("sheet_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :story_sheets, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :story_sheets, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :story_sheets, :id => @other_author.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :story_sheets, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :story_sheets, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
   describe '対象作家の用紙一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
@@ -2041,7 +2438,7 @@ else
     end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82³ã\83\9fã\83\83ã\82¯一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
@@ -2091,7 +2488,7 @@ else
     end
   end
   
-  describe '対象ä½\9c家ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼一覧表示に於いて' do
+  describe '対象ä½\9c家ã\81®ã\82¹ã\82¯ã\82³ã\83\9e一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
       @other_author = FactoryGirl.create :author, :user_id => @other_user.id
index 4b3426a..69a4252 100644 (file)
@@ -230,6 +230,322 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
+  describe '自分のコミック一覧表示に於いて' do
+    before do
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      sign_in @user
+      Comic.stub(:mylist).and_return([@comic, @comic, @comic])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :comics, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :comics
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :comics, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :comics
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :page_size => 1500
+        assigns(:page_size).should eq Author.comic_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :comics, :page_size => 0
+        assigns(:page_size).should eq Author.default_comic_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :comics
+        response.should be_success 
+      end
+      it 'コミックモデルに一覧を問い合わせている' do
+        Comic.should_receive(:mylist).exactly(1)
+        get :comics
+      end
+      it '@comicsにリストを取得している' do
+        get :comics
+        assigns(:comics).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :comics
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'comicsテンプレートを描画する' do
+          get :comics
+          response.should render_template("comics")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :comics, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do
+          Comic.should_receive(:list_json_opt).exactly(1)
+          get :comics, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :comics, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do
+          get :comics, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("title").should be_true
+          json.first.has_key?("visible").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :comics
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :comics
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :comics, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :comics, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のストーリー一覧表示に於いて' do
+    before do
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+      sign_in @user
+      Story.stub(:mylist).and_return([@story, @story, @story])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :stories, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :stories
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :stories, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :stories
+        assigns(:page_size).should eq Author.default_story_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :stories, :page_size => 1500
+        assigns(:page_size).should eq Author.story_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :stories, :page_size => 0
+        assigns(:page_size).should eq Author.default_story_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :stories
+        response.should be_success 
+      end
+      it 'ストーリーモデルに一覧を問い合わせている' do
+        Story.should_receive(:mylist).exactly(1)
+        get :stories
+      end
+      it '@storiesにリストを取得している' do
+        get :stories
+        assigns(:stories).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :stories
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'storiesテンプレートを描画する' do
+          get :stories
+          response.should render_template("stories")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :stories, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do
+          Story.should_receive(:list_json_opt).exactly(1)
+          get :stories, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :stories, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+          get :stories, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("comic_id").should be_true
+          json.first.has_key?("title").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :stories
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :stories
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :stories, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :stories, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分のスト紙一覧表示に於いて' do
+    before do
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
+      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+      sign_in @user
+      StorySheet.stub(:mylist).and_return([@story_sheet, @story_sheet, @story_sheet])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :story_sheets, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :story_sheets
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :story_sheets, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :story_sheets
+        assigns(:page_size).should eq Author.default_story_sheet_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :story_sheets, :page_size => 1500
+        assigns(:page_size).should eq Author.story_sheet_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :story_sheets, :page_size => 0
+        assigns(:page_size).should eq Author.default_story_sheet_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :story_sheets
+        response.should be_success 
+      end
+      it 'スト紙モデルに一覧を問い合わせている' do
+        StorySheet.should_receive(:mylist).exactly(1)
+        get :story_sheets
+      end
+      it '@story_sheetsにリストを取得している' do
+        get :story_sheets
+        assigns(:story_sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :story_sheets
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'story_sheetsテンプレートを描画する' do
+          get :story_sheets
+          response.should render_template("story_sheets")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :story_sheets, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スト紙モデルにjson一覧出力オプションを問い合わせている' do
+          StorySheet.should_receive(:list_json_opt).exactly(1)
+          get :story_sheets, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :story_sheets, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
+          get :story_sheets, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("story_id").should be_true
+          json.first.has_key?("sheet_id").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :story_sheets
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :story_sheets
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :story_sheets, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :story_sheets, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
   describe '自分の用紙一覧表示に於いて' do
     before do
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
index 5040adf..91afb36 100644 (file)
@@ -507,7 +507,7 @@ if MagicNumber['run_mode'] == 1
 
   describe '編集フォーム表示に於いて' do
     before do
-      @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id
+      @sheet_panel = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
       sign_in @user
       SheetPanel.stub(:show).and_return(@sheet_panel)
     end
@@ -601,8 +601,8 @@ if MagicNumber['run_mode'] == 1
 
   describe '更新に於いて' do
     before do
-      @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @user.author.id
-      @attr = FactoryGirl.attributes_for(:sheet_panel, :author_id => @author.id)
+      @sheet_panel = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @user.author.id
+      @attr = FactoryGirl.attributes_for(:sheet_panel, :x => 5566, :author_id => @author.id)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -624,10 +624,11 @@ if MagicNumber['run_mode'] == 1
         SheetPanel.any_instance.should_receive(:store).exactly(1)
         put :update, :id => @sheet_panel.id, :sheet_panel => @attr
       end
-      it "@sheet_panelに作成された紙コマを保持していて、それがDBにある" do
+      it "@sheet_panelに更新された紙コマを保持していて、それがDBにある" do
         put :update, :id => @sheet_panel.id, :sheet_panel => @attr
         assigns(:sheet_panel).should be_a(SheetPanel)
         assigns(:sheet_panel).should be_persisted
+        assigns(:sheet_panel).x.should eq 5566
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
index 6f4d0ea..0109ad1 100644 (file)
@@ -276,39 +276,13 @@ if MagicNumber['run_mode'] == 1
       SheetPanel.stub(:play_list).with(any_args).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
       sign_in @user
     end
-    context 'パラメータチェックする' do
-      it '与えられたoffsetがセットされている' do
-        get :play, :id => @sheet.id, :offset => 5
-        assigns(:offset).should eq 5
-      end
-      it '省略されると@offsetに0値が入る' do
-        get :play, :id => @sheet.id
-        assigns(:offset).should eq 0
-      end
-      it '与えられたcountがセットされている' do
-        get :play, :id => @sheet.id, :count => 4
-        assigns(:panel_count).should eq 4
-      end
-      it '省略されると@panel_countにデフォルト値が入る' do
-        get :play, :id => @sheet.id
-        assigns(:panel_count).should eq SheetPanel.default_panel_size
-      end
-      it '最大を超えると@panel_countにデフォルト最大値が入る' do
-        get :play, :id => @sheet.id, :count => 1500
-        assigns(:panel_count).should eq SheetPanel.max_panel_size
-      end
-      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
-        get :play, :id => @sheet.id, :count => -1
-        assigns(:panel_count).should eq SheetPanel.default_panel_size
-      end
-    end
     context '事前チェックする' do
       it '用紙モデルに単体取得を問い合わせている' do
         Sheet.should_receive(:show).with(@sheet.id.to_s, [@user, nil]).exactly(1)
         get :play, :id => @sheet.id
       end
       it '紙コマモデルにプレイリスト取得を問い合わせている' do
-        SheetPanel.should_receive(:play_list).with(@sheet, @author, 0, 30).exactly(1)
+        SheetPanel.should_receive(:play_list).with(@sheet, @author).exactly(1)
         get :play, :id => @sheet.id
       end
     end
index 7e7a4d4..3f7656a 100644 (file)
@@ -10,14 +10,13 @@ describe StoriesController do
     @user = FactoryGirl.create :user_yas
     @author = FactoryGirl.create :author, :user_id => @user.id
     @comic = FactoryGirl.create :comic, :author_id => @user.author.id
-    @panel = FactoryGirl.create :panel, :author_id => @author.id
   end
   
 if MagicNumber['run_mode'] == 1
   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
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Story.stub(:list).and_return([@story, @story, @story])
     end
     context 'パラメータpageについて' do
@@ -86,7 +85,7 @@ if MagicNumber['run_mode'] == 1
         it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
           get :index, :format => :json
           json = JSON.parse response.body
-          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("title").should be_true
           json.first.has_key?("comic_id").should be_true
           json.first.has_key?("t").should be_true
         end
@@ -141,11 +140,9 @@ if MagicNumber['run_mode'] == 1
   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
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
-      Story.stub(:show).with(@story.id.to_s, [@user, nil]).and_return(@story)
-      Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
     end
     context 'つつがなく終わるとき' do
       it 'ストーリーモデルに単体取得を問い合わせている' do
@@ -175,16 +172,15 @@ if MagicNumber['run_mode'] == 1
           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)
+        it 'ストーリーモデルにjson単体出力オプションを問い合わせている' do
+          Story.should_receive(:show_json_opt).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?("title").should be_true
           json.has_key?("comic_id").should be_true
-          json.has_key?("author_id").should be_true
         end
       end
     end
@@ -236,88 +232,75 @@ if MagicNumber['run_mode'] == 1
   
   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).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
-      Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      Story.stub(:show).with(@story.id.to_s, [@user, nil]).and_return(@story)
+      Story.stub(:show).with(@story.id.to_s, [nil, @admin]).and_return(@story)
       Story.stub(:count).and_return(10)
-      Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
+      StorySheet.stub(:play_sheet).with(any_args).and_return(@sheet)
       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
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :play, :id => @story.id, :page => 5
+        assigns(:page).should eq 5
       end
-      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
-        get :comic, :id => @comic.id, :count => -1
-        assigns(:panel_count).should eq Story.default_panel_size
+      it '省略されると@pageに1値が入る' do
+        get :play, :id => @story.id
+        assigns(:page).should eq 1
       end
     end
     context '事前チェックする' do
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに単体取得を問い合わせている' do
-        Comic.should_receive(:show).with(@comic.id.to_s, [@user, nil]).exactly(1)
-        get :comic, :id => @comic.id
+      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルに単体取得を問い合わせている' do
+        Story.should_receive(:show).with(@story.id.to_s, [@user, nil]).exactly(1)
+        get :play, :id => @story.id
       end
-      it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
-        Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
-        get :comic, :id => @comic.id
+      it 'ストモデルにプレイリスト取得を問い合わせている' do
+        StorySheet.should_receive(:play_sheet).with(@story, @author, 1).exactly(1)
+        get :play, :id => @story.id
       end
     end
     context 'つつがなく終わるとき' do
-      it '@storiesにリストを取得している' do
-        get :comic, :id => @comic.id
-        assigns(:stories).should have_at_least(3).items
+      it '@sheetに用紙を取得している' do
+        get :play, :id => @story.id
+        assigns(:sheet).should eq @sheet
       end
       context 'html形式' do
         it 'ステータスコード200 OKを返す' do
-          get :comic, :id => @comic.id
+          get :play, :id => @story.id
           response.should be_success 
         end
-        it 'comicテンプレートを描画する' do
-          get :comic, :id => @comic.id
-          response.should render_template("comic")
+        it 'playテンプレートを描画する' do
+          get :play, :id => @story.id
+          response.should render_template("play")
         end
       end
       context 'json形式' do
         it 'ステータスコード200 OKを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           response.should be_success 
         end
         it 'jsonデータを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
-          Story.should_receive(:list_as_json_text).exactly(1)
-          get :comic, :id => @comic.id, :format => :json
+        it '紙コマモデルに紙コマリストのjson出力を問い合わせている' do
+          SheetPanel.should_receive(:list_as_json_text).exactly(1)
+          get :play, :id => @story.id, :format => :json
         end
         it 'データがリスト構造になっている' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           json = JSON.parse response.body
-          json.should have_at_least(3).items
+          json.should have_at_least(1).items
         end
-        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
-          get :comic, :id => @comic.id, :format => :json
+        it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
+          get :play, :id => @story.id, :format => :json
           json = JSON.parse response.body
+          json.first.has_key?("sheet_id").should be_true
           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
@@ -327,21 +310,21 @@ if MagicNumber['run_mode'] == 1
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          get :comic, :id => @comic.id
+          get :play, :id => @story.id
           response.status.should eq 302
         end
         it 'サインインページへ遷移する' do
-          get :comic, :id => @comic.id
+          get :play, :id => @story.id
           response.should redirect_to '/users/sign_in'
         end
       end
       context 'json形式' do
         it 'ステータスコード401 Unauthorizedを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           response.status.should eq 401
         end
         it '応答メッセージにUnauthorizedを返す' do
-          get :comic, :id => @comic.id, :format => :json
+          get :play, :id => @story.id, :format => :json
           response.message.should match(/Unauthorized/)
         end
       end
@@ -352,7 +335,7 @@ if MagicNumber['run_mode'] == 1
         sign_in @admin
       end
       it 'ステータスコード200 OKを返す' do
-        get :comic, :id => @comic.id
+        get :play, :id => @story.id
         response.should be_success 
       end
     end
@@ -361,7 +344,7 @@ if MagicNumber['run_mode'] == 1
         @author.destroy
       end
       it 'ステータスコード200 OKを返す' do
-        get :comic, :id => @comic.id
+        get :play, :id => @story.id
         response.should be_success 
       end
     end
@@ -409,16 +392,15 @@ if MagicNumber['run_mode'] == 1
           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)
+        it 'ストーリーモデルのjson単体出力オプションを問い合わせている' do
+          Story.should_receive(:show_json_opt).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?("title").should be_true
           json.has_key?("comic_id").should be_true
-          json.has_key?("author_id").should be_true
         end
       end
     end
@@ -482,7 +464,7 @@ if MagicNumber['run_mode'] == 1
   
   describe '新規作成に於いて' do
     before do
-      @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+      @attr = FactoryGirl.attributes_for(:story, :t => 0, :comic_id => @comic.id)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -491,10 +473,9 @@ if MagicNumber['run_mode'] == 1
         post :create, :story => @attr
       end
       it 'POSTデータから、カラム値を復元している' do
-        Story.any_instance.stub(:store).and_return(true)
+#        Story.any_instance.stub(:store).and_return(true)
         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)
@@ -504,29 +485,25 @@ if MagicNumber['run_mode'] == 1
         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
       end
-      it "@storyã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9eを保持していて、それがDBにある" do
+      it "@storyã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\83\88ã\83¼ã\83ªã\83¼を保持していて、それがDBにある" do
         post :create, :story => @attr
         assigns(:story).should be_a(Story)
         assigns(:story).should be_persisted
       end
       context 'html形式' do
         it 'ステータスコード302 Foundを返す' do
-          Story.any_instance.stub(:store).and_return(true)
+#          Story.any_instance.stub(:store).and_return(true)
           post :create, :story => @attr
           response.status.should eq 302
         end
-        it 'コミックのストーリー表示へ遷移する' do
+        it '作成されたストーリーの表示へページ位置を指定して遷移する' do
 #          Story.any_instance.stub(:store).and_return(true)
           post :create, :story => @attr
-          response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
+          response.should redirect_to(play_story_path(assigns(:story), :page => 1))
         end
       end
       context 'json形式' do
@@ -539,8 +516,8 @@ if MagicNumber['run_mode'] == 1
           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)
+        it 'ストーリーモデルのjson単体出力オプションを問い合わせている' do
+          Story.should_receive(:show_json_opt).exactly(1)
           post :create, :story => @attr, :format => :json
         end
         it 'データがアレになっている' do
@@ -639,7 +616,7 @@ if MagicNumber['run_mode'] == 1
 
   describe '編集フォーム表示に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:show).and_return(@story)
     end
@@ -733,8 +710,8 @@ if MagicNumber['run_mode'] == 1
 
   describe '更新に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @user.author.id
-      @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
+      @attr = FactoryGirl.attributes_for(:story, :t => 0)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -767,10 +744,10 @@ if MagicNumber['run_mode'] == 1
           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 => :comic, :id => @attr[:comic_id])
+          response.should redirect_to(play_story_path(@story, :page => 1))
         end
       end
       context 'json形式' do
@@ -870,7 +847,7 @@ if MagicNumber['run_mode'] == 1
 
   describe '削除に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:edit).and_return(@story)
     end
@@ -901,9 +878,9 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @story.id
           response.status.should eq 302
         end
-        it '閲覧ページへ遷移する' do
+        it 'コミック単体表示ページへ遷移する' do
           delete :destroy, :id => @story.id
-          response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
+          response.should redirect_to(comic_path(@comic))
         end
       end
       context 'json形式' do
@@ -1006,7 +983,7 @@ else
   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
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Story.stub(:list).and_return([@story, @story, @story])
     end
     context 'つつがなく終わるとき' do
@@ -1053,7 +1030,7 @@ else
   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
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Comic.stub(:show).with(@comic.id.to_s, [nil, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
@@ -1112,7 +1089,7 @@ else
   
   describe '閲覧に於いて' do
     before do
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       Comic.stub(:show).with(@comic.id.to_s, [nil, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [@user, nil]).and_return(@comic)
       Comic.stub(:show).with(@comic.id.to_s, [nil, @admin]).and_return(@comic)
@@ -1234,7 +1211,7 @@ else
   
   describe '新規作成に於いて' do
     before do
-      @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+      @attr = FactoryGirl.attributes_for :story, :t => nil, :comic_id => @comic.id
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -1291,7 +1268,7 @@ else
 
   describe '編集フォーム表示に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:show).and_return(@story)
     end
@@ -1346,8 +1323,8 @@ else
 
   describe '更新に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @user.author.id
-      @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
+      @attr = FactoryGirl.attributes_for(:story)
       sign_in @user
     end
     context 'つつがなく終わるとき' do
@@ -1400,7 +1377,7 @@ else
 
   describe '削除に於いて' do
     before do
-      @story = FactoryGirl.create :story, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       sign_in @user
       Story.stub(:edit).and_return(@story)
     end
index 9751c55..a170d68 100644 (file)
@@ -10,7 +10,7 @@ describe StorySheetsController do
     @user = FactoryGirl.create :user_yas
     @author = FactoryGirl.create :author, :user_id => @user.id
     @comic = FactoryGirl.create :comic, :author_id => @user.author.id
-    @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id
+    @story = FactoryGirl.create :story, :comic_id => @comic.id
     @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
   end
   
index c35f33c..fd19cfa 100644 (file)
@@ -96,7 +96,6 @@ FactoryGirl.define do
     story.description 'scroll description'
     story.visible 1
     story.t 0
-    story.author_id 1
   end
 
   factory :story_sheet, :class => StorySheet do |story_sheet|
index ce70711..755c7d0 100644 (file)
@@ -46,6 +46,7 @@ describe Comic do
         @comic.should_not be_valid
       end
     end
+    
     context 'visibleを検証するとき' do
       it 'nullなら失敗する' do
         @comic.visible = nil
@@ -60,6 +61,22 @@ describe Comic do
         @comic.should_not be_valid
       end
     end
+    
+    context 'author_idを検証するとき' do
+      it 'nullなら失敗する' do
+        @comic.author_id = nil
+        @comic.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @comic.author_id = 'a'
+        @comic.should_not be_valid
+      end
+      it '存在する作家でなければ失敗する' do
+        @comic.author_id = 0
+        @comic.should_not be_valid
+      end
+    end
+    
   end
   
   describe '文字コード検証に於いて' do
@@ -635,7 +652,7 @@ describe Comic do
       @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
       @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
     end
     it 'ストーリーを含んでいる' do
       r = Comic.list.to_json Comic.list_json_opt
@@ -750,7 +767,7 @@ describe Comic do
       @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
       @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
     end
     it 'ストーリーを含んでいる' do
       r = Comic.show(@comic.id, @author).to_json Comic.show_json_opt
@@ -769,9 +786,9 @@ describe Comic do
   describe '削除に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       @other_comic = FactoryGirl.create :comic, :author_id => @author.id
-      @other_story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @other_comic.id
+      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id
     end
     context 'つつがなく終わるとき' do
       it '自身を削除する' do
index 7479689..9128dc7 100644 (file)
@@ -60,6 +60,21 @@ describe Scroll do
         @scroll.should_not be_valid
       end
     end
+    
+    context 'author_idを検証するとき' do
+      it 'nullなら失敗する' do
+        @scroll.author_id = nil
+        @scroll.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @scroll.author_id = 'a'
+        @scroll.should_not be_valid
+      end
+      it '存在する作家でなければ失敗する' do
+        @scroll.author_id = 0
+        @scroll.should_not be_valid
+      end
+    end
   end
   
   describe '文字コード検証に於いて' do
index 33cba57..5eadaa5 100644 (file)
@@ -321,48 +321,6 @@ describe SheetPanel do
       @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
       @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
     end
-    context 'offset補正について' do
-      it '文字列から数値に変換される' do
-        SheetPanel.offset(100, '8').should eq 8
-      end
-      it 'nilの場合は0になる' do
-        SheetPanel.offset(100).should eq 0
-      end
-      #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
-      #最後のコマとは、コマ数‐1.
-      it '1件のときオフセット1なら0になる' do
-        SheetPanel.offset(1, '1').should eq 0
-      end
-      it '5件のときオフセット5なら4になる' do
-        SheetPanel.offset(5, '5').should eq 4
-      end
-      # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
-      #-4のときは、最後から4つのコマを表示する。 
-      it '2件のときオフセット-1なら1になる' do
-        SheetPanel.offset(2, '-1').should eq 1
-      end
-      it '5件のときオフセット-2なら3になる' do
-        SheetPanel.offset(5, '-2').should eq 3
-      end
-      # 最終的なが負になるなど、不正な値が入ったときは0となる。 
-      it '2件のときオフセット-5なら0になる' do
-        SheetPanel.offset(2, '-5').should eq 0
-      end
-    end
-    context 'panel_count補正について' do
-      it '文字列から数値に変換される' do
-        SheetPanel.panel_count(100, '7').should eq 7
-      end
-      it 'nilの場合はSheetPanel.default_panel_sizeになる' do
-        SheetPanel.panel_count(100).should eq SheetPanel.default_panel_size
-      end
-      it '0以下の場合はSheetPanel.default_panel_sizeになる' do
-        SheetPanel.panel_count(100, '0').should eq SheetPanel.default_panel_size
-      end
-      it 'SheetPanel.max_panel_sizeを超えた場合はSheetPanel.max_panel_sizeになる' do
-        SheetPanel.panel_count(100, '1000').should eq SheetPanel.max_panel_size
-      end
-    end
     it 'リストを返す' do
       c = SheetPanel.play_list @sheet, @author
       c.should eq [@sheet_panel]
@@ -378,27 +336,6 @@ describe SheetPanel do
       c = SheetPanel.play_list @sheet, @author
       c.should eq [ @sheet_panel, h]
     end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        @sheet_panel2 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
-        @sheet_panel3 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 2
-        @sheet_panel4 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 3
-        @sheet_panel5 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 4
-      end
-      it 'offset=0なら末尾2件を返す' do
-        #時系列で並んでいる
-        c = SheetPanel.play_list( @sheet, @author, 0, 2)
-        c.should eq [@sheet_panel, @sheet_panel2]
-      end
-      it 'offset=2なら中間2件を返す' do
-        c = SheetPanel.play_list(@sheet, @author, 2, 2)
-        c.should eq [@sheet_panel3, @sheet_panel4]
-      end
-      it 'offset=4なら先頭1件を返す' do
-        c = SheetPanel.play_list(@sheet, @author, 4, 2)
-        c.should eq [@sheet_panel5]
-      end
-    end
   end
   
   describe '一覧取得に於いて' do
index 2076823..4cec7ed 100644 (file)
@@ -26,11 +26,15 @@ describe Sheet do
     context 'オーソドックスなデータのとき' do
       it '下限データが通る' do
         @sheet.caption = 'a'
+        @sheet.width = 1
+        @sheet.height = 1
         @sheet.visible = 0
         @sheet.should be_valid
       end
       it '上限データが通る' do
         @sheet.caption = 'a'*100
+        @sheet.width = 99999
+        @sheet.height = 99999
         @sheet.visible = 1
         @sheet.should be_valid
       end
@@ -46,6 +50,42 @@ describe Sheet do
         @sheet.should_not be_valid
       end
     end
+    context 'widthを検証するとき' do
+      it 'nullなら失敗する' do
+        @sheet.width = nil
+        @sheet.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @sheet.width = 'a'
+        @sheet.should_not be_valid
+      end
+      it '0なら失敗する' do
+        @sheet.width = '0'
+        @sheet.should_not be_valid
+      end
+      it '負でも失敗する' do
+        @sheet.width = -1
+        @sheet.should_not be_valid
+      end
+    end
+    context 'heightを検証するとき' do
+      it 'nullなら失敗する' do
+        @sheet.height = nil
+        @sheet.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @sheet.height = 'a'
+        @sheet.should_not be_valid
+      end
+      it '0なら失敗する' do
+        @sheet.height = '0'
+        @sheet.should_not be_valid
+      end
+      it '負でも失敗する' do
+        @sheet.height = -1
+        @sheet.should_not be_valid
+      end
+    end
     context 'visibleを検証するとき' do
       it 'nullなら失敗する' do
         @sheet.visible = nil
index b00d8a9..c708a7e 100644 (file)
@@ -23,7 +23,7 @@ describe StorySheet do
   describe '検証に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.build :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
     end
@@ -105,7 +105,7 @@ describe StorySheet do
   describe 'デフォルト値補充に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     
@@ -121,7 +121,7 @@ describe StorySheet do
   describe '上書き補充に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     
@@ -139,11 +139,11 @@ describe StorySheet do
   describe '所持判定に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
       @comico = FactoryGirl.create :comic, :author_id => @other_author.id
-      @storyo = FactoryGirl.create :story, :comic_id => @comico.id, :author_id => @other_author.id
+      @storyo = FactoryGirl.create :story, :comic_id => @comico.id
       @sheeto = FactoryGirl.create :sheet, :author_id => @other_author.id
       @story_sheeto = FactoryGirl.create :story_sheet, :author_id => @other_author.id, :story_id => @storyo.id, :sheet_id => @sheeto.id
     end
@@ -180,7 +180,7 @@ describe StorySheet do
   describe '閲覧許可に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
     end
@@ -260,90 +260,47 @@ describe StorySheet do
   describe 'プレイリスト取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
-      @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :visible => 1
-      @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
     end
-    context 'offset補正について' do
-      it '文字列から数値に変換される' do
-        StorySheet.offset(100, '8').should eq 8
-      end
-      it 'nilの場合は0になる' do
-        StorySheet.offset(100).should eq 0
-      end
-      #投稿された用紙数以上の値が指定されたときは、最後の用紙だけになる
-      #最後の用紙とは、用紙数‐1.
-      it '1件のときオフセット1なら0になる' do
-        StorySheet.offset(1, '1').should eq 0
-      end
-      it '5件のときオフセット5なら4になる' do
-        StorySheet.offset(5, '5').should eq 4
-      end
-      # 負の値が指定されたときは、最後の用紙から数えて用紙を飛ばして表示する。
-      #-4のときは、最後から4つの用紙を表示する。 
-      it '2件のときオフセット-1なら1になる' do
-        StorySheet.offset(2, '-1').should eq 1
-      end
-      it '5件のときオフセット-2なら3になる' do
-        StorySheet.offset(5, '-2').should eq 3
-      end
-      # 最終的なが負になるなど、不正な値が入ったときは0となる。 
-      it '2件のときオフセット-5なら0になる' do
-        StorySheet.offset(2, '-5').should eq 0
-      end
-    end
-    context 'sheet_count補正について' do
-      it '文字列から数値に変換される' do
-        StorySheet.sheet_count(100, '7').should eq 7
-      end
-      it 'nilの場合はStorySheet.default_sheet_sizeになる' do
-        StorySheet.sheet_count(100).should eq StorySheet.default_sheet_size
+    context 'つつがなく終わるとき' do
+      it '用紙に単体取得を問い合わせている' do
+        Sheet.stub(:show).with(any_args).and_return(@sheet)
+        Sheet.should_receive(:show).with(any_args).exactly(1)
+        r = StorySheet.play_sheet @story, @author
       end
-      it '0以下の場合はStorySheet.default_sheet_sizeになる' do
-        StorySheet.sheet_count(100, '0').should eq StorySheet.default_sheet_size
+      it '用紙を返す' do
+        c = StorySheet.play_sheet @story, @author
+        c.should eq @sheet
       end
-      it 'StorySheet.max_sheet_sizeを超えた場合はStorySheet.max_sheet_sizeになる' do
-        StorySheet.sheet_count(100, '1000').should eq StorySheet.max_sheet_size
+      it '削除された用紙は含んでいない' do
+        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
+        h = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet2.id, :t => 1
+        @sheet2.destroy
+        c = StorySheet.play_sheet @story, @author, 2
+        c.should eq nil
       end
     end
-    it 'リストを返す' do
-      c = StorySheet.play_list @story, @author
-      c.should eq [@story_sheet]
-    end
-    it 't順で並んでいる' do
-      #公開ストーリーの公開用紙は(他人のストーリーであっても)含んでいる
-      v = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id, :t => 1
-      c = StorySheet.play_list @story, @author
-      c.should eq [ @story_sheet, v]
-    end
-    it '非公開の用紙は含んでいる' do
-      h = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet2.id, :t => 1
-      c = StorySheet.play_list @story, @author
-      c.should eq [ @story_sheet, h]
-    end
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
+    context 'DBに5件あったとして' do
       before do
-        @story_sheet2 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id, :t => 1
-        @story_sheet3 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id, :t => 2
-        @story_sheet4 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id, :t => 3
-        @story_sheet5 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id, :t => 4
-      end
-      it 'offset=0なら末尾2件を返す' do
+        @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
+        @story_sheet2 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet2.id, :t => 1
+        @sheet3 = FactoryGirl.create :sheet, :author_id => @author.id
+        @story_sheet3 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet3.id, :t => 2
+        @sheet4 = FactoryGirl.create :sheet, :author_id => @author.id
+        @story_sheet4 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet4.id, :t => 3
+        @sheet5 = FactoryGirl.create :sheet, :author_id => @author.id
+        @story_sheet5 = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet5.id, :t => 4
+      end
+      it 'page=1なら先頭を返す' do
         #時系列で並んでいる
-        c = StorySheet.play_list( @story, @author, 0, 2)
-        c.should eq [@story_sheet, @story_sheet2]
+        c = StorySheet.play_sheet( @story, @author, 1)
+        c.should eq @sheet
       end
-      it 'offset=2なら中間2件を返す' do
-        c = StorySheet.play_list(@story, @author, 2, 2)
-        c.should eq [@story_sheet3, @story_sheet4]
-      end
-      it 'offset=4なら先頭1件を返す' do
-        c = StorySheet.play_list(@story, @author, 4, 2)
-        c.should eq [@story_sheet5]
+      it 'page=5なら末尾を返す' do
+        c = StorySheet.play_sheet(@story, @author, 5)
+        c.should eq @sheet5
       end
     end
   end
@@ -351,14 +308,14 @@ describe StorySheet do
   describe '一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
       @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :visible => 1
+      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :visible => 1
       @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id
       @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id
-      @hidden_story = FactoryGirl.create :story, :author_id => @author.id, :visible => 0
+      @hidden_story = FactoryGirl.create :story, :visible => 0
     end
     context 'page補正について' do
       it '文字列から数値に変換される' do
@@ -430,14 +387,14 @@ describe StorySheet do
   describe '自分のスト紙一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
       @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :visible => 1
+      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :visible => 1
       @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
       @hcomic = FactoryGirl.create :comic, :author_id => @author.id
-      @hstory = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 0
+      @hstory = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 0
       @hsheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
     end
     context 'つつがなく終わるとき' do
@@ -497,11 +454,11 @@ describe StorySheet do
   describe '他作家のスト紙一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
       @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :visible => 1
+      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :visible => 1
       @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
       @other_story_sheet = FactoryGirl.create :story_sheet, :author_id => @other_author.id, :story_id => @other_story.id, :sheet_id => @other_sheet.id
     end
@@ -515,7 +472,7 @@ describe StorySheet do
       r.should eq [ns, @other_story_sheet]
     end
     it '公開ストーリーのスト紙' do
-      @hstory = FactoryGirl.create :story, :author_id => @other_author.id, :visible => 0
+      @hstory = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 0
       ns = FactoryGirl.create :story_sheet, :author_id => @other_author.id, :story_id => @hstory.id, :sheet_id => @other_sheet.id, :t => 1, :updated_at => Time.now + 100
       r = StorySheet.himlist @other_author
       r.should eq [@other_story_sheet]
@@ -617,10 +574,6 @@ describe StorySheet do
       r = StorySheet.list_opt
       r.has_key?(:story).should be_true
     end
-      it 'ストーリーは作家を含んでいる' do
-        r = StorySheet.list_opt
-        r[:story].has_key?(:author).should be_true
-      end
     it '作家を含んでいる' do
       r = StorySheet.list_opt
       r.has_key?(:author).should be_true
@@ -637,7 +590,7 @@ describe StorySheet do
   describe 'json一覧出力オプションに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
     end
@@ -647,13 +600,6 @@ describe StorySheet do
       i = j.first
       i.has_key?('story').should be_true
     end
-      it 'ストーリーは作家を含んでいる' do
-        r = StorySheet.list.to_json StorySheet.list_json_opt
-        j = JSON.parse r
-        i = j.first
-        s = i['story']
-        s.has_key?('author').should be_true
-      end
     it '用紙を含んでいる' do
       r = StorySheet.list.to_json StorySheet.list_json_opt
       j = JSON.parse r
@@ -678,7 +624,7 @@ describe StorySheet do
   describe '単体取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
     end
@@ -718,7 +664,7 @@ describe StorySheet do
   describe '編集取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
     end
@@ -768,10 +714,6 @@ describe StorySheet do
       r = StorySheet.show_opt[:include]
       r.has_key?(:story).should be_true
     end
-      it 'ストーリーは作家を含んでいる' do
-        r = StorySheet.show_opt[:include]
-        r[:story].has_key?(:author).should be_true
-      end
     it '作家を含んでいる' do
       r = StorySheet.show_opt[:include]
       r.has_key?(:author).should be_true
@@ -788,7 +730,7 @@ describe StorySheet do
   describe 'json単体取得オプションに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
     end
@@ -798,13 +740,6 @@ describe StorySheet do
       i = j
       i.has_key?('story').should be_true
     end
-      it 'ストーリーは作家を含んでいる' do
-        r = StorySheet.show(@story_sheet.id, @author).to_json StorySheet.show_json_opt
-        j = JSON.parse r
-        i = j
-        s = i['story']
-        s.has_key?('author').should be_true
-      end
     it '用紙を含んでいる' do
       r = StorySheet.show(@story_sheet.id, @author).to_json StorySheet.show_json_opt
       j = JSON.parse r
@@ -826,10 +761,102 @@ describe StorySheet do
     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 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+      @speech = @sb.build_speech(
+        FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+      )
+      @balloon = @sb.build_balloon(
+        FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+      )
+      @sb.boost
+      @sb.save!
+      @gc = @panel.ground_colors.create(
+        FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
+      )
+      @gp = @panel.ground_pictures.create(
+        FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
+      )
+      @panel.reload
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.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 = @scroll_panel.scroll_panel_as_json @author
+      end
+    end
+    it 'json textを返している' do
+      r = JSON.parse @scroll_panel.scroll_panel_as_json(@author)
+      r.is_a?(Hash).should be_true
+    end
+    it 'scroll,author,panel,コマ要素を含んでいる' do
+      r = JSON.parse @scroll_panel.scroll_panel_as_json(@author)
+      r.has_key?('scroll').should be_true
+      r['scroll'].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 @scroll_panel.scroll_panel_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 @scroll_panel.scroll_panel_as_json(@author)
+        r['panel'].has_key?('elements').should be_false
+      end
+    end
+  end
+  
+  describe 'スクコマリストのjson出力に於いて' do
+    before do
+      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
+      ScrollPanel.any_instance.stub(:scroll_panel_as_json).with(@author).and_return('{"s": 5}')
+    end
+    context 'つつがなく終わるとき' do
+      it 'スクコマのjson出力を依頼している' do
+        ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).with(@author).exactly(1)
+        r = ScrollPanel.list_as_json_text [@scroll_panel], @author
+      end
+    end
+    it 'json textを返している' do
+      r = ScrollPanel.list_as_json_text [@scroll_panel], @author
+      j = JSON.parse r
+      j.is_a?(Array).should be_true
+    end
+    it 'スクコマを含んでいる' do
+      r = ScrollPanel.list_as_json_text [@scroll_panel], @author
+      j = JSON.parse r
+      j.first.has_key?('s').should be_true
+    end
+  end
+  
   describe 't補充値に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     
@@ -894,10 +921,10 @@ describe StorySheet do
   describe 't収集に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
-      @story2 = FactoryGirl.create :story, :author_id => @author.id
+      @story2 = FactoryGirl.create :story
       @c2story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
     end
     context 'つつがなく終わるとき' do
@@ -924,7 +951,7 @@ describe StorySheet do
   describe 'tチェックに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.build :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
     end
@@ -963,7 +990,7 @@ describe StorySheet do
   describe '挿入シフトに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     context '依頼チェック' do
@@ -1020,7 +1047,7 @@ describe StorySheet do
     end
     context '先ほどのケース+他のストーリー1件で挿入したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1045,7 +1072,7 @@ describe StorySheet do
   describe '少ない方に移動に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     context '依頼チェック' do
@@ -1137,7 +1164,7 @@ describe StorySheet do
     end
     context '先ほどのケース+他のストーリー1件で挿入したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1207,7 +1234,7 @@ describe StorySheet do
   describe '大きい方に移動に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     context '依頼チェック' do
@@ -1299,7 +1326,7 @@ describe StorySheet do
     end
     context '先ほどのケース+他のストーリー1件で挿入したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1370,7 +1397,7 @@ describe StorySheet do
   describe '入れ替えに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
       @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1397,7 +1424,7 @@ describe StorySheet do
   describe '順序入れ替えに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
     end
     context 'オブジェクトが新規でtが空のとき' do
@@ -1437,7 +1464,7 @@ describe StorySheet do
   describe '編集許可に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.build :story_sheet, :t => nil, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
     end
@@ -1481,7 +1508,7 @@ describe StorySheet do
   describe '保存に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.build :story_sheet, :t => nil, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
     end
@@ -1516,7 +1543,7 @@ describe StorySheet do
     #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
     context 'テーブルに5件(t:0,1,2,3,4)+他のストーリー1件で2に挿入したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1564,7 +1591,7 @@ describe StorySheet do
     end
     context 'テーブルに5件(t:0,1,2,3,4)+他のストーリー1件で3を1に移動したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1607,7 +1634,7 @@ describe StorySheet do
     end
     context 'テーブルに5件(t:0,1,2,3,4)+他のストーリー1件で1を3に移動したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1652,7 +1679,7 @@ describe StorySheet do
     context 'テーブルに5件(t:0,1,2,3,4)+他のストーリー1件で2に挿入したが保存に失敗したとき' do
       before do
         StorySheet.any_instance.stub(:save).with(any_args).and_return(false)
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1684,7 +1711,7 @@ describe StorySheet do
     context 'テーブルに5件(t:0,1,2,3,4)+他のストーリー1件で3を1に移動したがシリアルチェックに失敗したとき' do
       before do
         StorySheet.stub(:validate_t).with(any_args).and_return(false)
-        @story2 = FactoryGirl.create :story, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id
         @story_sheetc2 = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story2.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
         @story_sheet2 = FactoryGirl.create :story_sheet, :t => 1, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
@@ -1734,7 +1761,7 @@ describe StorySheet do
   describe '切り詰め処理つき削除に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
     end
index de0452b..5cc830f 100644 (file)
@@ -20,7 +20,7 @@ describe Story do
   describe '検証に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.build :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.build :story, :comic_id => @comic.id
     end
     
     context 'オーソドックスなデータのとき' do
@@ -38,6 +38,21 @@ describe Story do
       end
     end
     
+    context 'comic_idを検証するとき' do
+      it 'nullなら失敗する' do
+        @story.comic_id = nil
+        @story.should_not be_valid
+      end
+      it '数値でなければ失敗する' do
+        @story.comic_id = 'a'
+        @story.should_not be_valid
+      end
+      it '存在するコミックでなければ失敗する' do
+        @story.comic_id = 0
+        @story.should_not be_valid
+      end
+    end
+    
     context 'titleを検証するとき' do
       it 'nullなら失敗する' do
         @story.title = nil
@@ -48,6 +63,7 @@ describe Story do
         @story.should_not be_valid
       end
     end
+    
     context 'visibleを検証するとき' do
       it 'nullなら失敗する' do
         @story.visible = nil
@@ -62,6 +78,7 @@ describe Story do
         @story.should_not be_valid
       end
     end
+    
     context 'tを検証するとき' do
       it 'nullなら失敗する' do
         @story.t = nil
@@ -81,7 +98,7 @@ describe Story do
   describe '文字コード検証に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.build :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.build :story, :comic_id => @comic.id
     end
     
     context 'titleを検証するとき' do
@@ -112,16 +129,12 @@ describe Story do
   end
   
   describe '上書き補充に於いて' do
-    it '作家idが設定されている' do
-      @story = FactoryGirl.build :story, :author_id => nil
-      @story.overwrite @author
-      @story.author_id.should eq @author.id
-    end
   end
   
   describe '所持判定に於いて' do
     before do
-      @story = FactoryGirl.build :story, :author_id => @author.id
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.build :story, :comic_id => @comic.id
     end
     context '事前チェックする' do
       it '自身にロールリストからの作家取得を依頼している' do
@@ -132,12 +145,12 @@ describe Story do
     context 'ロール内作家が取得できるとき' do
       before do
       end
-      it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
+      it 'ロール内作家のidが自身のコミックの作家idと一致するなら許可する' do
         Story.stub(:get_author_from_roles).with(any_args).and_return(@author)
         r = @story.own?([@author])
         r.should be_true
       end
-      it 'ロール内作家のidが自身の作家idと一致しないならno' do
+      it 'ロール内作家のidが自身のコミックの作家idと一致しないならno' do
         Story.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
         @story.own?(@other_author).should be_false
       end
@@ -155,7 +168,8 @@ describe Story do
   
   describe '閲覧許可に於いて' do
     before do
-      @story = FactoryGirl.build :story, :author_id => @author.id
+      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @story = FactoryGirl.build :story, :comic_id => @comic.id
     end
     context 'オープンモードのとき' do
       before do
@@ -227,7 +241,7 @@ describe Story do
   describe '一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
     end
     context 'page補正について' do
       it '文字列から数値に変換される' do
@@ -266,23 +280,23 @@ describe Story do
       c.should eq [@story]
     end
     it '非公開ストーリーは(自分のストーリーであっても)含んでいない' do
-      FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 0
+      FactoryGirl.create :story, :comic_id => @comic.id, :visible => 0
       c = Story.list
       c.should eq [@story]
     end
     it '時系列で並んでいる' do
       #公開ストーリーは(他人のストーリーであっても)含んでいる
       other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      v = FactoryGirl.create :story, :comic_id => other_comic.id, :author_id => @other_author.id, :updated_at => Time.now + 100
+      v = FactoryGirl.create :story, :comic_id => other_comic.id, :updated_at => Time.now + 100
       c = Story.list
       c.should eq [v, @story]
     end
     context 'DBに5件あって1ページの件数を2件に変えたとして' do
       before do
-        @story2 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 100
-        @story3 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 200
-        @story4 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 300
-        @story5 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 400
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 100
+        @story3 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 200
+        @story4 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 300
+        @story5 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 400
         Story.stub(:default_page_size).and_return(2)
       end
       it '通常は2件を返す' do
@@ -308,7 +322,7 @@ describe Story do
   describe '自分のストーリー一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
       it '一覧取得オプションを利用している' do
@@ -322,27 +336,27 @@ describe Story do
       c.should eq [@story]
     end
     it '時系列で並んでいる' do
-      nc = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 100
+      nc = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 100
       cl = Story.mylist @author
       cl.should eq [nc, @story]
     end
     it '他人のストーリーは公開でも含まない' do
       other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      nc = FactoryGirl.create :story, :comic_id => other_comic.id, :author_id => @other_author.id, :visible => 1
+      nc = FactoryGirl.create :story, :comic_id => other_comic.id, :visible => 1
       cl = Story.mylist @author
       cl.should eq [@story]
     end
     it '自分のストーリーは非公開でも含んでいる' do
-      nc = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
+      nc = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 0, :updated_at => Time.now + 100
       cl = Story.mylist @author
       cl.should eq [nc, @story]
     end
     context 'DBに5件あって1ページの件数を2件に変えたとして' do
       before do
-        @story2 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 100
-        @story3 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 200
-        @story4 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 300
-        @story5 = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :updated_at => Time.now + 400
+        @story2 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 100
+        @story3 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 200
+        @story4 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 300
+        @story5 = FactoryGirl.create :story, :comic_id => @comic.id, :updated_at => Time.now + 400
       end
       it '通常は2件を返す' do
         c = Story.mylist @author, 1, 2
@@ -367,9 +381,9 @@ describe Story do
   describe '他作家のストーリー一覧取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id
-      @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id
-      @other_story = FactoryGirl.create :story, :author_id => @other_author.id, :visible => 1
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
+      @other_comic = FactoryGirl.create :comic, :visible => 1, :author_id => @other_author.id
+      @other_story = FactoryGirl.create :story, :visible => 1, :comic_id => @other_comic.id
     end
     context 'つつがなく終わるとき' do
       it '一覧取得オプションを利用している' do
@@ -383,21 +397,21 @@ describe Story do
       r.should eq [@other_story]
     end
     it '時系列で並んでいる' do
-      nc = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :updated_at => Time.now + 100
+      nc = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 100
       r = Story.himlist @other_author
       r.should eq [nc, @other_story]
     end
     it '公開ストーリーに限る ' do
-      hidden = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :visible => 0
+      hidden = FactoryGirl.create :story, :comic_id => @other_comic.id, :visible => 0
       r = Story.himlist @other_author
       r.should eq [@other_story]
     end
     context 'DBに5件あって1ページの件数を2件に変えたとして' do
       before do
-        @other_story2 = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :updated_at => Time.now + 100
-        @other_story3 = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :updated_at => Time.now + 200
-        @other_story4 = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :updated_at => Time.now + 300
-        @other_story5 = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @other_author.id, :updated_at => Time.now + 400
+        @other_story2 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 100
+        @other_story3 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 200
+        @other_story4 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 300
+        @other_story5 = FactoryGirl.create :story, :comic_id => @other_comic.id, :updated_at => Time.now + 400
       end
       it '通常は2件を返す' do
         c = Story.himlist @other_author, 1, 2
@@ -480,66 +494,43 @@ describe Story do
   end
   
   describe '一覧取得オプションに於いて' do
-    it '2つの項目を含んでいる' do
+    it '1つの項目を含んでいる' do
       r = Story.list_opt
-      r.should have(2).items
+      r.should have(1).items
     end
-    it 'ã\82¹ã\83\88ç´\99を含んでいる' do
+    it 'ã\82³ã\83\9fã\83\83ã\82¯を含んでいる' do
       r = Story.list_opt
-      r.has_key?(:story_sheets).should be_true
+      r.has_key?(:comic).should be_true
     end
-      it 'スト紙は用紙を含んでいる' do
-        r = Story.list_opt
-        r[:story_sheets].has_key?(:sheet).should be_true
-      end
-      it 'スト紙は作家を含んでいる' do
+      it 'コミックは作家を含んでいる' do
         r = Story.list_opt
-        r[:story_sheets].has_key?(:author).should be_true
+        r[:comic].has_key?(:author).should be_true
       end
-    it '作家を含んでいる' do
-      r = Story.list_opt
-      r.has_key?(:author).should be_true
-    end
   end
   describe 'json一覧出力オプションに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
     end
-    it 'ã\82¹ã\83\88ç´\99を含んでいる' do
+    it 'ã\82³ã\83\9fã\83\83ã\82¯を含んでいる' do
       r = Story.list.to_json Story.list_json_opt
       j = JSON.parse r
       i = j.first
-      i.has_key?('story_sheets').should be_true
+      i.has_key?('comic').should be_true
     end
-      it 'スト紙は用紙を含んでいる' do
-        r = Story.list.to_json Story.list_json_opt
-        j = JSON.parse r
-        i = j.first
-        s = i['story_sheets'].first
-        s.has_key?('sheet').should be_true
-      end
-      it 'スト紙は作家を含んでいる' do
+      it 'コミックは作家を含んでいる' do
         r = Story.list.to_json Story.list_json_opt
         j = JSON.parse r
         i = j.first
-        s = i['story_sheets'].first
+        s = i['comic']
         s.has_key?('author').should be_true
       end
-    it '作家を含んでいる' do
-      r = Story.list.to_json Story.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('author').should be_true
-    end
   end
   
   describe '単体取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
       it '単体取得オプションを利用している' do
@@ -577,7 +568,7 @@ describe Story do
   describe '編集取得に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
       it '単体取得オプションを利用している' do
@@ -617,60 +608,37 @@ describe Story do
       r = Story.show_opt
       r.has_key?(:include).should be_true
     end
-    it '2つの項目を含んでいる' do
+    it '1つの項目を含んでいる' do
       r = Story.show_opt[:include]
-      r.should have(2).items
+      r.should have(1).items
     end
-    it '作家を含んでいる' do
+    it 'コミックを含んでいる' do
       r = Story.show_opt[:include]
-      r.has_key?(:author).should be_true
+      r.has_key?(:comic).should be_true
     end
-    it 'スト紙を含んでいる' do
-      r = Story.show_opt[:include]
-      r.has_key?(:story_sheets).should be_true
-    end
-      it 'スト紙は用紙を含んでいる' do
-        r = Story.show_opt[:include]
-        r[:story_sheets].has_key?(:sheet).should be_true
-      end
-      it 'スト紙は作家を含んでいる' do
+      it 'コミックは作家を含んでいる' do
         r = Story.show_opt[:include]
-        r[:story_sheets].has_key?(:author).should be_true
+        r[:comic].has_key?(:author).should be_true
       end
   end
   describe 'json単体出力オプションに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :visible => 1
-      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
-      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id, :visible => 1
     end
-    it 'ã\82¹ã\83\88ç´\99を含んでいる' do
+    it 'ã\82³ã\83\9fã\83\83ã\82¯を含んでいる' do
       r = Story.show(@story.id, @author).to_json Story.show_json_opt
       j = JSON.parse r
       i = j
-      i.has_key?('story_sheets').should be_true
+      i.has_key?('comic').should be_true
     end
-      it 'ã\82¹ã\83\88ç´\99ã\81¯ç\94¨ç´\99を含んでいる' do
+      it 'ã\82³ã\83\9fã\83\83ã\82¯ã\81¯ä½\9c家を含んでいる' do
         r = Story.show(@story.id, @author).to_json Story.show_json_opt
         j = JSON.parse r
         i = j
-        s = i['story_sheets'].first
-        s.has_key?('sheet').should be_true
-      end
-      it 'スト紙は作家を含んでいる' do
-        r = Story.show(@story.id, @author).to_json Story.show_json_opt
-        j = JSON.parse r
-        i = j
-        s = i['story_sheets'].first
+        s = i['comic']
         s.has_key?('author').should be_true
       end
-    it '作家を含んでいる' do
-      r = Story.show(@story.id, @author).to_json Story.show_json_opt
-      j = JSON.parse r
-      i = j
-      i.has_key?('author').should be_true
-    end
   end
   
   describe 't補充値に於いて' do
@@ -680,7 +648,7 @@ describe Story do
     
     context 'コミック初のコマなら' do
       it '0を補充値とする' do
-        @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id
+        @story = FactoryGirl.build :story, :comic_id => @comic.id
         @story.t = nil
         r = Story.new_t @story.comic_id
         r.should eq 0
@@ -688,8 +656,8 @@ describe Story do
     end
     context 'コミックに一個コマがあるとき' do
       it '1を補充値とする' do
-        FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :t => 0
-        @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id
+        FactoryGirl.create :story, :comic_id => @comic.id, :t => 0
+        @story = FactoryGirl.build :story, :comic_id => @comic.id
         @story.t = nil
         r = Story.new_t @story.comic_id
         r.should eq 1
@@ -697,9 +665,9 @@ describe Story do
     end
     context 'コミックに2個コマがあるとき' do
       it '2を補充値とする' do
-        FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :t => 0
-        FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :t => 1
-        @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id
+        FactoryGirl.create :story, :comic_id => @comic.id, :t => 0
+        FactoryGirl.create :story, :comic_id => @comic.id, :t => 1
+        @story = FactoryGirl.build :story, :comic_id => @comic.id
         @story.t = nil
         r = Story.new_t @story.comic_id
         r.should eq 2
@@ -739,9 +707,9 @@ describe Story do
   describe 't収集に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
       @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-      @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
+      @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
     end
     context 'つつがなく終わるとき' do
       it 'ストーリーから同一コミックのtだけを収集している' do
@@ -751,14 +719,14 @@ describe Story do
     end
     context '複数コマのとき' do
       it 'ストーリーから同一コミックのtだけを収集している' do
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         r = Story.collect_t @story
         r.sort.should eq [0, 1]
       end
     end
     context '複数ストーリーでヨソのコミックも混じっているとき' do
       it 'ストーリーから同一コミックのtだけを収集している' do
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         r = Story.collect_t @story
         r.sort.should eq [0, 1]
       end
@@ -767,7 +735,7 @@ describe Story do
   describe 'tチェックに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
       it 't収集を依頼している' do
@@ -787,15 +755,15 @@ describe Story do
     #依頼チェックだけでは不安なので最低限のチェックを
     context '新規のとき' do
       it '一件だけで正常通過している' do
-        @story = FactoryGirl.build :story, :comic_id => @comic.id, :author_id => @author.id, :t => 0
+        @story = FactoryGirl.build :story, :comic_id => @comic.id, :t => 0
         r = Story.validate_t @story
         r.should be_true 
       end
     end
     context '既存のとき' do
       it '2件目を作っても正常通過している' do
-        @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id, :t => 0
-        @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :author_id => @author.id, :t => 1
+        @story = FactoryGirl.create :story, :comic_id => @comic.id, :t => 0
+        @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :t => 1
         r = Story.validate_t @story2
         r.should be_true 
       end
@@ -810,14 +778,14 @@ describe Story do
       it 'Updateを依頼している' do
         Story.stub(:update_all).with(any_args)
         Story.should_receive(:update_all).with(any_args).exactly(1)
-        @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id
         @story.insert_shift
       end
     end
     context 'テーブルに1件(t:0)で0に挿入したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id
       end
       it '既存の行を1にシフトしている' do
         @story2.insert_shift
@@ -832,9 +800,9 @@ describe Story do
     end
     context 'テーブルに2件(t:0,1)で1に挿入したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id
       end
       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
         @story3.insert_shift
@@ -844,12 +812,12 @@ describe Story do
     end
     context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
-        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
       end
       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
         @story6.insert_shift
@@ -860,13 +828,13 @@ describe Story do
     context '先ほどのケース+他のコミック1件で挿入したとき' do
       before do
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
-        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
       end
       it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
         @story6.insert_shift
@@ -883,12 +851,12 @@ describe Story do
   end
   describe '少ない方に移動に於いて' do
     before do
-      @comic = FactoryGirl.create :comic, :author_id => @author.id
+      @comic = FactoryGirl.create :comic
     end
     context '依頼チェック' do
       it 'Updateを依頼している' do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         Story.stub(:update_all).with(any_args)
         Story.should_receive(:update_all).with(any_args).exactly(1)
         ot = @story2.t
@@ -898,8 +866,8 @@ describe Story do
     end
     context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         @ot = @story2.t
         @story2.t = 0
       end
@@ -917,9 +885,9 @@ describe Story do
     end
     context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
         @ot = @story3.t
         @story3.t = 1
       end
@@ -937,11 +905,11 @@ describe Story do
     end
     context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story4.t
         @story4.t = 1
       end
@@ -974,13 +942,13 @@ describe Story do
     end
     context '先ほどのケース+他のコミック1件で挿入したとき' do
       before do
-        @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @comic2 = FactoryGirl.create :comic
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story4.t
         @story4.t = 1
       end
@@ -1019,8 +987,8 @@ describe Story do
     #負のときは0として正常扱い
     context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         @ot = @story2.t
         @story2.t = -1
       end
@@ -1047,8 +1015,8 @@ describe Story do
     end
     context '依頼チェック' do
       it 'Updateを依頼している' do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         Story.stub(:update_all).with(any_args)
         Story.should_receive(:update_all).with(any_args).exactly(1)
         ot = @story.t
@@ -1058,8 +1026,8 @@ describe Story do
     end
     context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         @ot = @story.t
         @story.t = 1
       end
@@ -1077,9 +1045,9 @@ describe Story do
     end
     context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
         @ot = @story.t
         @story.t = 1
       end
@@ -1097,11 +1065,11 @@ describe Story do
     end
     context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story2.t
         @story2.t = 3
       end
@@ -1135,12 +1103,12 @@ describe Story do
     context '先ほどのケース+他のコミック1件で挿入したとき' do
       before do
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story2.t
         @story2.t = 3
       end
@@ -1180,8 +1148,8 @@ describe Story do
     #max超えたときはmaxとして正常扱い
     context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
       before do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         @ot = @story.t
         @story.t = 2
       end
@@ -1205,8 +1173,8 @@ describe Story do
   describe '入れ替えに於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-      @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+      @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
     end
     context '新tが旧tより小さいとき' do
       it '少ない方に移動を依頼している' do
@@ -1233,7 +1201,7 @@ describe Story do
     end
     context 'オブジェクトが新規でtが空のとき' do
       it '末尾追加としてtを補充依頼している' do
-        @story = FactoryGirl.build :story, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.build :story, :comic_id => @comic.id
         Story.stub(:new_t).with(any_args).and_return(0)
         Story.should_receive(:new_t).with(any_args).exactly(1)
         @story.t = nil
@@ -1242,7 +1210,7 @@ describe Story do
     end
     context 'オブジェクトが新規でtが設定されているとき' do
       it '挿入追加として挿入シフトを依頼している' do
-        @story = FactoryGirl.build :story, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.build :story, :comic_id => @comic.id
         Story.any_instance.stub(:insert_shift).with(any_args)
         Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
         @story.t = 0
@@ -1251,8 +1219,8 @@ describe Story do
     end
     context 'オブジェクトが新規でなくtが設定されているとき' do
       it '移動として入れ替えを依頼している' do
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
         Story.any_instance.stub(:update_shift).with(any_args)
         Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
         @story2.t = 0
@@ -1268,20 +1236,18 @@ describe Story do
   describe '編集許可に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @panel = FactoryGirl.create :panel, :author_id => @author.id
-      @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
       it 'trueを返す' do
-        r = @story.allow?
+        r = @story.allow? @author
         r.should be_true
       end
     end
     context 'コミックで引っかかるとき' do
       it 'falseを返す' do
-        Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
         Comic.any_instance.stub(:own?).with(any_args).and_return(false)
-        r = @story.allow?
+        r = @story.allow? @other_author
         r.should be_false
       end
     end
@@ -1289,7 +1255,7 @@ describe Story do
       it 'nilを返す' do
         Comic.any_instance.stub(:own?).with(any_args).and_return(true)
         @story.comic_id = nil
-        r = @story.allow?
+        r = @story.allow? @author
         r.should eq nil
       end
     end
@@ -1297,81 +1263,81 @@ describe Story do
   describe '保存に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
       it '編集許可チェックを依頼している' do
         Story.any_instance.stub(:allow?).with(any_args).and_return(true)
         Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
-        r = @story.store
+        r = @story.store @author
       end
       it '順序入れ替えを依頼している' do
         Story.any_instance.stub(:rotate).with(any_args).and_return(0)
         Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
         Story.any_instance.stub(:save).with(any_args).and_return(true)
         Story.stub(:validate_t).with(any_args).and_return(true)
-        r = @story.store 
+        r = @story.store @author
       end
       it '保存を依頼している' do
         Story.stub(:new_t).with(any_args).and_return(0)
         Story.any_instance.stub(:save).with(any_args).and_return(true)
         Story.any_instance.should_receive(:save).with(any_args).exactly(1)
         Story.stub(:validate_t).with(any_args).and_return(true)
-        r = @story.store
+        r = @story.store @author
       end
       it 'tのシリアライズチェックを依頼している' do
         Story.stub(:new_t).with(any_args).and_return(0)
         Story.any_instance.stub(:save).with(any_args).and_return(true)
         Story.stub(:validate_t).with(any_args).and_return(true)
         Story.should_receive(:validate_t).with(any_args).exactly(1)
-        r = @story.store
+        r = @story.store @author
       end
     end
     #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
     context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
       before do
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
-        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
       end
       it '既存のt0には変化がない' do
-        @story6.store
+        @story6.store @author
         @story.reload
         @story.t.should eq 0
       end
       it '既存のt1には変化がない' do
-        @story6.store
+        @story6.store @author
         @story2.reload
         @story2.t.should eq 1
       end
       it '既存のt2を3にシフトしている' do
-        @story6.store
+        @story6.store @author
         @story3.reload
         @story3.t.should eq 3
       end
       it '既存のt3を4にシフトしている' do
-        @story6.store
+        @story6.store @author
         @story4.reload
         @story4.t.should eq 4
       end
       it '既存のt5を5にシフトしている' do
-        @story6.store
+        @story6.store @author
         @story5.reload
         @story5.t.should eq 5
       end
       it '新規のt2が作成されている' do
-        @story6.store
+        @story6.store @author
         @story6.reload
         @story6.t.should eq 2
       end
       it '他のコミックに影響がない' do
         @ot = @storyc2.t
-        @story6.store
+        @story6.store @author
         @storyc2.reload
         @storyc2.t.should eq @ot
       end
@@ -1379,42 +1345,42 @@ describe Story do
     context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
       before do
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story4.t
         @story4.t = 1
       end
       it '既存のt0には変化がない' do
-        @story4.store @ot
+        @story4.store  @author, @ot
         @story.reload
         @story.t.should eq 0
       end
       it '既存のt4には変化がない' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @story5.reload
         @story5.t.should eq 4
       end
       it '既存のt1を2にシフトしている' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @story2.reload
         @story2.t.should eq 2
       end
       it '既存のt2を3にシフトしている' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @story3.reload
         @story3.t.should eq 3
       end
       it '既存のt3を1にシフトしている' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @story4.reload
         @story4.t.should eq 1
       end
       it '他のコミックに影響がない' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @storyc2.reload
         @storyc2.t.should eq 0
       end
@@ -1422,42 +1388,42 @@ describe Story do
     context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
       before do
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story2.t
         @story2.t = 3
       end
       it '既存のt0には変化がない' do
-        @story2.store @ot
+        @story2.store @author, @ot
         @story.reload
         @story.t.should eq 0
       end
       it '既存のt4には変化がない' do
-        @story2.store @ot
+        @story2.store @author, @ot
         @story5.reload
         @story5.t.should eq 4
       end
       it '既存のt1を3にシフトしている' do
-        @story2.store @ot
+        @story2.store @author, @ot
         @story2.reload
         @story2.t.should eq 3
       end
       it '既存のt2を1にシフトしている' do
-        @story2.store @ot
+        @story2.store @author, @ot
         @story3.reload
         @story3.t.should eq 1
       end
       it '既存のt3を2にシフトしている' do
-        @story2.store @ot
+        @story2.store @author, @ot
         @story4.reload
         @story4.t.should eq 2
       end
       it '他のコミックに影響がない' do
-        @story2.store @ot
+        @story2.store @author, @ot
         @storyc2.reload
         @storyc2.t.should eq 0
       end
@@ -1467,16 +1433,16 @@ describe Story do
       before do
         Story.any_instance.stub(:save).with(any_args).and_return(false)
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
-        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
+        @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id
       end
       it '既存のtに変化がない' do
-        @story6.store
+        @story6.store @author
         @story.reload
         @story.t.should eq 0
         @story2.reload
@@ -1491,7 +1457,7 @@ describe Story do
         @storyc2.t.should eq 0
       end
       it 'falseを返す' do
-        r = @story6.store
+        r = @story6.store @author
         r.should be_false
       end
     end
@@ -1499,17 +1465,17 @@ describe Story do
       before do
         Story.stub(:validate_t).with(any_args).and_return(false)
         @comic2 = FactoryGirl.create :comic, :author_id => @author.id
-        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :author_id => @author.id
-        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id
+        @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
         @ot = @story4.t
         @story4.t = 1
       end
       it '既存のtに変化がない' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @story.reload
         @story.t.should eq 0
         @story2.reload
@@ -1524,23 +1490,23 @@ describe Story do
         @storyc2.t.should eq 0
       end
       it 'falseを返す' do
-        r = @story4.store @ot
+        r = @story4.store @author, @ot
         r.should be_false
       end
       it 'tにエラーメッセージが入っている' do
-        @story4.store @ot
+        @story4.store @author, @ot
         @story4.errors[:t].should_not be_empty
         @story4.valid?.should be_true
       end
     end
     context '編集不可だったとき' do
       before do
-        @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
+        @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id
         Story.any_instance.stub(:allow?).and_return(false)
       end
       it '403Forbidden例外を返す' do
         lambda{
-          @story.store
+          @story.store @author
         }.should raise_error(ActiveRecord::Forbidden)
       end
     end
@@ -1548,9 +1514,14 @@ describe Story do
   describe '切り詰め処理つき削除に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id
     end
     context 'つつがなく終わるとき' do
+      it '削除を依頼している' do
+        Story.any_instance.stub(:destroy_with_story_sheet).with(any_args).and_return(true)
+        Story.any_instance.should_receive(:destroy_with_story_sheet).with(any_args).exactly(1)
+        r = @story.destroy_and_shorten
+      end
       it '削除される' do
         lambda{
           @story.destroy_and_shorten
@@ -1563,7 +1534,7 @@ describe Story do
     end
     context '削除に失敗したとき' do
       before do
-        Story.any_instance.stub(:destroy).and_return(false)
+        Story.any_instance.stub(:destroy_with_story_sheet).and_return(false)
       end
       it 'ロールバックされる' do
         lambda{
@@ -1578,7 +1549,7 @@ describe Story do
     #連携テスト。切り詰めが直接DBをいじる
     context '2件で先頭を削除したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
       end
       it '行が削除される' do
         lambda{
@@ -1599,8 +1570,8 @@ describe Story do
     end
     context '3件で先頭を削除したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
       end
       it '行が削除される' do
         lambda{
@@ -1626,10 +1597,10 @@ describe Story do
     end
     context '5件で3件目を削除したとき' do
       before do
-        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :author_id => @author.id
-        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :author_id => @author.id
-        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :author_id => @author.id
-        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :author_id => @author.id
+        @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id
+        @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id
+        @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id
+        @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id
       end
       it '行が削除される' do
         lambda{
@@ -1668,11 +1639,11 @@ describe Story do
   describe '削除に於いて' do
     before do
       @comic = FactoryGirl.create :comic, :author_id => @author.id
-      @story = FactoryGirl.create :story, :comic_id => @comic.id, :author_id => @author.id
+      @story = FactoryGirl.create :story, :comic_id => @comic.id
       @sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @story.id, :sheet_id => @sheet.id
       @other_comic = FactoryGirl.create :comic, :author_id => @author.id
-      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id, :author_id => @author.id
+      @other_story = FactoryGirl.create :story, :comic_id => @other_comic.id
       @other_sheet = FactoryGirl.create :sheet, :author_id => @author.id
       @other_story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id, :story_id => @other_story.id, :sheet_id => @other_sheet.id
     end