OSDN Git Service

t#32046:
authoryasushiito <yas@pen-chan.jp>
Mon, 30 Sep 2013 02:06:48 +0000 (11:06 +0900)
committeryasushiito <yas@pen-chan.jp>
Mon, 30 Sep 2013 02:06:48 +0000 (11:06 +0900)
113 files changed:
app/assets/images/sheet.gif [new file with mode: 0644]
app/assets/images/story_sheet.gif [new file with mode: 0644]
app/assets/stylesheets/test.css.scss
app/controllers/authors_controller.rb
app/controllers/comics_controller.rb
app/controllers/home_controller.rb
app/controllers/panels_controller.rb
app/controllers/scroll_panels_controller.rb
app/controllers/scrolls_controller.rb
app/controllers/sheet_panels_controller.rb
app/controllers/sheets_controller.rb
app/controllers/stories_controller.rb
app/controllers/story_sheets_controller.rb
app/helpers/application_helper.rb
app/models/comic.rb
app/models/sheet_panel.rb
app/models/story.rb
app/models/story_sheet.rb
app/views/authors/comics.html.erb [new file with mode: 0644]
app/views/authors/sheet_panels.html.erb [new file with mode: 0644]
app/views/authors/sheets.html.erb [new file with mode: 0644]
app/views/authors/show.html.erb
app/views/authors/stories.html.erb [new file with mode: 0644]
app/views/authors/story_sheets.html.erb [new file with mode: 0644]
app/views/comics/_list_item.html.erb
app/views/comics/show.html.erb
app/views/home/comics.html.erb [new file with mode: 0644]
app/views/home/index.html.erb
app/views/home/sheet_panels.html.erb [new file with mode: 0644]
app/views/home/sheets.html.erb [new file with mode: 0644]
app/views/home/stories.html.erb [new file with mode: 0644]
app/views/home/story_sheets.html.erb [new file with mode: 0644]
app/views/layouts/test.html.erb
app/views/panels/_body.html.erb
app/views/panels/show.html.erb
app/views/scroll_panels/_append_panel.html.erb
app/views/scroll_panels/_append_scroll.html.erb [moved from app/views/panels/_append_scroll.html.erb with 80% similarity]
app/views/scroll_panels/_list_item.html.erb
app/views/scroll_panels/_scroll_header.html.erb
app/views/scroll_panels/edit.html.erb
app/views/scroll_panels/scroll.html.erb [deleted file]
app/views/scroll_panels/show.html.erb
app/views/scrolls/_list_item.html.erb
app/views/scrolls/play.html.erb
app/views/scrolls/show.html.erb
app/views/sheet_panels/_append_panel.html.erb [new file with mode: 0644]
app/views/sheet_panels/_append_sheet.html.erb [new file with mode: 0644]
app/views/sheet_panels/_form.html.erb [new file with mode: 0644]
app/views/sheet_panels/_licensed_pictures.html.erb [moved from app/views/stories/_licensed_pictures.html.erb with 100% similarity]
app/views/sheet_panels/_list_item.html.erb [new file with mode: 0644]
app/views/sheet_panels/_order.html.erb [new file with mode: 0644]
app/views/sheet_panels/_play_footer.html.erb [new file with mode: 0644]
app/views/sheet_panels/_play_header.html.erb [new file with mode: 0644]
app/views/sheet_panels/browse.html.erb [new file with mode: 0644]
app/views/sheet_panels/edit.html.erb [new file with mode: 0644]
app/views/sheet_panels/edit.js.erb [new file with mode: 0644]
app/views/sheet_panels/index.html.erb [new file with mode: 0644]
app/views/sheet_panels/list.html.erb [new file with mode: 0644]
app/views/sheet_panels/new.html.erb [new file with mode: 0644]
app/views/sheet_panels/show.html.erb [new file with mode: 0644]
app/views/sheets/_body.html.erb [new file with mode: 0644]
app/views/sheets/_form.html.erb [new file with mode: 0644]
app/views/sheets/_list_item.html.erb [new file with mode: 0644]
app/views/sheets/_standard.html.erb [new file with mode: 0644]
app/views/sheets/browse.html.erb [new file with mode: 0644]
app/views/sheets/edit.html.erb [new file with mode: 0644]
app/views/sheets/edit.js.erb [new file with mode: 0644]
app/views/sheets/index.html.erb [new file with mode: 0644]
app/views/sheets/list.html.erb [new file with mode: 0644]
app/views/sheets/new.html.erb [new file with mode: 0644]
app/views/sheets/new.js.erb [new file with mode: 0644]
app/views/sheets/play.html.erb [new file with mode: 0644]
app/views/sheets/show.html.erb [new file with mode: 0644]
app/views/stories/_append_panel.html.erb [deleted file]
app/views/stories/_comic_header.html.erb [deleted file]
app/views/stories/_footer.html.erb [deleted file]
app/views/stories/_form.html.erb
app/views/stories/_list_item.html.erb
app/views/stories/_order.html.erb
app/views/stories/_play_footer.html.erb [new file with mode: 0644]
app/views/stories/browse.html.erb
app/views/stories/comic.html.erb [deleted file]
app/views/stories/edit.html.erb
app/views/stories/list.html.erb
app/views/stories/play.html.erb [new file with mode: 0644]
app/views/stories/show.html.erb
app/views/story_sheets/_append_sheet.html.erb [new file with mode: 0644]
app/views/story_sheets/_append_story.html.erb [new file with mode: 0644]
app/views/story_sheets/_form.html.erb [new file with mode: 0644]
app/views/story_sheets/_list_item.html.erb [new file with mode: 0644]
app/views/story_sheets/_order.html.erb [new file with mode: 0644]
app/views/story_sheets/_play_footer.html.erb [new file with mode: 0644]
app/views/story_sheets/_play_header.html.erb [new file with mode: 0644]
app/views/story_sheets/browse.html.erb [new file with mode: 0644]
app/views/story_sheets/edit.html.erb [new file with mode: 0644]
app/views/story_sheets/edit.js.erb [new file with mode: 0644]
app/views/story_sheets/index.html.erb [new file with mode: 0644]
app/views/story_sheets/list.html.erb [new file with mode: 0644]
app/views/story_sheets/new.html.erb [new file with mode: 0644]
app/views/story_sheets/show.html.erb [new file with mode: 0644]
app/views/top/index.html.erb
config/locales/pettanr.ja.yml
config/magic_number.yml
config/routes.rb
spec/controllers/authors_controller_spec.rb
spec/controllers/comics_controller_spec.rb [new file with mode: 0644]
spec/controllers/home_controller_spec.rb
spec/controllers/scroll_panels_controller_spec.rb
spec/controllers/scrolls_controller_spec.rb
spec/controllers/sheet_panels_controller_spec.rb
spec/controllers/sheets_controller_spec.rb
spec/controllers/stories_controller_spec.rb [new file with mode: 0644]
spec/controllers/story_sheets_controller_spec.rb

diff --git a/app/assets/images/sheet.gif b/app/assets/images/sheet.gif
new file mode 100644 (file)
index 0000000..cff7dfa
Binary files /dev/null and b/app/assets/images/sheet.gif differ
diff --git a/app/assets/images/story_sheet.gif b/app/assets/images/story_sheet.gif
new file mode 100644 (file)
index 0000000..0707502
Binary files /dev/null and b/app/assets/images/story_sheet.gif differ
index efff5fe..74983c8 100644 (file)
@@ -16,6 +16,24 @@ div.md5 {
   text-align: left;
 }
 
+.sheet {
+  position:    relative;
+  overflow:    hidden;
+  float: left;
+  clear: left;
+}
+
+.sheet-data {
+  float: left;
+}
+
+.sheet-break {
+  clear: both;
+}
+
+.sheet_panel {
+  position:    absolute;
+}
 .pettanr-comic-wrapper {
   margin:  1em auto;
 }
index 75fa2d0..7f70b72 100644 (file)
@@ -4,7 +4,7 @@ class AuthorsController < ApplicationController
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
     before_filter :authenticate_author, :only => [:edit, :update]
   else
-    before_filter :authenticate_reader, :only => [:index, :show, :scrolls, :scroll_panels, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
+    before_filter :authenticate_reader, :only => [:index, :show, :scrolls, :scroll_panels, :comics, :stories, :story_sheets, :sheets, :sheet_panels, :panels, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update]
     before_filter :authenticate_author, :only => [:edit, :update]
   end
@@ -62,6 +62,81 @@ class AuthorsController < ApplicationController
     end
   end
   
+  def comics
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.comic_page_size params[:page_size]
+    @comics = Comic.himlist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = Comic.himlist_paginate(@au, @page, @page_size)
+      }
+      format.json { render json: @comics.to_json(Comic.list_json_opt) }
+    end
+  end
+  
+  def stories
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.story_page_size params[:page_size]
+    @stories = Story.himlist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = Story.himlist_paginate(@au, @page, @page_size)
+      }
+      format.json { render json: @stories.to_json(Story.list_json_opt) }
+    end
+  end
+  
+  def story_sheets
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.sheet_page_size params[:page_size]
+    @story_sheets = StorySheet.himlist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = StorySheet.himlist_paginate(@au, @page, @page_size)
+      }
+      format.json { render json: @story_sheets.to_json(StorySheet.list_json_opt) }
+    end
+  end
+  
+  def sheets
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.sheet_page_size params[:page_size]
+    @sheets = Sheet.himlist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = Sheet.himlist_paginate(@au, @page, @page_size)
+      }
+      format.json { render json: @sheets.to_json(Sheet.list_json_opt) }
+    end
+  end
+  
+  def sheet_panels
+    @au = Author.show(params[:id], [@user, @admin])
+
+    @page = Author.page params[:page]
+    @page_size = Author.sheet_page_size params[:page_size]
+    @sheet_panels = SheetPanel.himlist(@au, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = SheetPanel.himlist_paginate(@au, @page, @page_size)
+      }
+      format.json { render json: @sheet_panels.to_json(SheetPanel.list_json_opt) }
+    end
+  end
+  
   def panels
     @au = Author.show(params[:id], [@user, @admin])
 
index c5f8546..d8729a3 100644 (file)
@@ -28,7 +28,7 @@ class ComicsController < ApplicationController
     @comic = Comic.show(params[:id], [@user, @admin])
 
     respond_to do |format|
-      format.html # show.html.erb
+      format.html 
       format.json { render json: @comic.to_json(Comic.show_json_opt) }
       format.atom 
       format.rss 
index 7cb4331..26ddfc5 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, :panels, :resource_pictures, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors
+    :scrolls, :scroll_panels, :comics, :stories, :story_sheet, :sheets, :sheet_panels, :panels, :resource_pictures, :panel_pictures, :speech_balloons, :ground_pictures, :ground_colors
   ]
-  before_filter :authenticate_author, :only => [:scrolls, :scroll_panels, :panels, :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_artist, :only => [:resource_pictures]
   
   def index
@@ -62,7 +62,72 @@ class HomeController < ApplicationController
       format.html {
         @paginate = ScrollPanel.mylist_paginate(@author, @page, @page_size)
       }
-      format.json { render text: ScrollPanel.list_as_json_text(@scroll_panels) }
+      format.json { render json: @scroll_panels.to_json(ScrollPanel.list_json_opt) }
+    end
+  end
+  
+  def comics
+    @page = Author.page params[:page]
+    @page_size = Author.comic_page_size params[:page_size]
+    @comics = Comic.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = Comic.mylist_paginate(@author, @page, @page_size)
+      }
+      format.json { render json: @comics.to_json(Comic.list_json_opt) }
+    end
+  end
+  
+  def stories
+    @page = Author.page params[:page]
+    @page_size = Author.story_page_size params[:page_size]
+    @stories = Story.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = Story.mylist_paginate(@author, @page, @page_size)
+      }
+      format.json { render json: @stories.to_json(Story.list_json_opt) }
+    end
+  end
+  
+  def story_sheets
+    @page = Author.page params[:page]
+    @page_size = Author.story_sheet_page_size params[:page_size]
+    @story_sheets = StorySheet.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = StorySheet.mylist_paginate(@author, @page, @page_size)
+      }
+      format.json { render json: @story_sheets.to_json(StorySheet.list_json_opt) }
+    end
+  end
+  
+  def sheets
+    @page = Author.page params[:page]
+    @page_size = Author.sheet_page_size params[:page_size]
+    @sheets = Sheet.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = Sheet.mylist_paginate(@author, @page, @page_size)
+      }
+      format.json { render json: @sheets.to_json(Sheet.list_json_opt) }
+    end
+  end
+  
+  def sheet_panels
+    @page = Author.page params[:page]
+    @page_size = Author.sheet_panel_page_size params[:page_size]
+    @sheet_panels = SheetPanel.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = SheetPanel.mylist_paginate(@author, @page, @page_size)
+      }
+      format.json { render json: @sheet_panels.to_json(SheetPanel.list_json_opt) }
     end
   end
   
index 8f55827..28a03fe 100644 (file)
@@ -35,6 +35,8 @@ class PanelsController < ApplicationController
         if @author
           @new_scrolls = Scroll.mylist(@author, 1, 5)
           @fresh_scrolls = ScrollPanel.mylist(@author, 1, 5).map {|sp| sp.scroll}
+          @new_sheets = Sheet.mylist(@author, 1, 5)
+          @fresh_sheets = SheetPanel.mylist(@author, 1, 5).map {|sp| sp.sheet}
         end
       }
       format.json { render json: @panel.panel_elements_as_json }
index 5e0b739..f694433 100644 (file)
@@ -32,39 +32,6 @@ class ScrollPanelsController < ApplicationController
     end
   end
   
-  def scroll
-    @scroll = Scroll.show(params[:id], [@user, @admin])
-    cnt = ScrollPanel.count(:conditions => ['scroll_id = ?', @scroll.id]).to_i
-    @offset = ScrollPanel.offset cnt, params[:offset]
-    @panel_count = ScrollPanel.panel_count cnt, params[:count]
-    @scroll_panels = ScrollPanel.play_list(@scroll, @author, @offset, @panel_count)
-    respond_to do |format|
-      format.html {
-        @prev_offset = if @offset > 0
-          if @offset - @panel_count < 0
-            0
-          else
-            @offset - @panel_count
-          end
-        else
-          nil
-        end
-        @next_offset = if @offset + @panel_count > cnt
-          nil
-        else
-          @offset + @panel_count
-        end
-        if @author
-          @new_panels = Panel.mylist(@author, 1, 5)
-        end
-      }
-      format.json {render text: ScrollPanel.list_as_json_text(@scroll_panels, @author)}
-      format.jsonp {
-        render :json => "callback(" + @scroll_panels.to_json_list + ");"
-      }
-    end
-  end
-  
   def list
     @scroll_panels = ScrollPanel.all
 
@@ -112,7 +79,7 @@ class ScrollPanelsController < ApplicationController
     respond_to do |format|
       if @scroll_panel.store
         flash[:notice] = I18n.t('flash.notice.created', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to action: :scroll, id: @scroll_panel.scroll_id }
+        format.html { redirect_to play_scroll_path(@scroll) }
         format.json { render json: @scroll_panel.scroll_panel_as_json(@author) }
       else
         flash[:notice] = I18n.t('flash.notice.not_created', :model => ScrollPanel.model_name.human)
@@ -127,10 +94,11 @@ class ScrollPanelsController < ApplicationController
     ot = @scroll_panel.t
     @scroll_panel.attributes = params[:scroll_panel]
     @scroll_panel.overwrite @author
+    @scroll = Scroll.edit(@scroll_panel.scroll_id, @author) if @scroll_panel.scroll_id
     respond_to do |format|
       if @scroll_panel.store ot
         flash[:notice] = I18n.t('flash.notice.updated', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to action: :scroll, id: @scroll_panel.scroll_id }
+        format.html { redirect_to play_scroll_path(@scroll) }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_updated', :model => ScrollPanel.model_name.human)
@@ -142,10 +110,11 @@ class ScrollPanelsController < ApplicationController
 
   def destroy
     @scroll_panel = ScrollPanel.edit(params[:id], @author)
+    @scroll = Scroll.edit(@scroll_panel.scroll_id, @author) if @scroll_panel.scroll_id
     respond_to do |format|
       if @scroll_panel.destroy_and_shorten
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => ScrollPanel.model_name.human)
-        format.html { redirect_to :controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll_id }
+        format.html { redirect_to play_scroll_path(@scroll) }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => ScrollPanel.model_name.human)
index 1bf5dc5..62a8413 100644 (file)
@@ -4,7 +4,7 @@ class ScrollsController < ApplicationController
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [:top, :index, :show]
+    before_filter :authenticate_reader, :only => [:top, :index, :show, :play]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
@@ -28,7 +28,11 @@ class ScrollsController < ApplicationController
     @scroll = Scroll.show(params[:id], [@user, @admin])
 
     respond_to do |format|
-      format.html # show.html.erb
+      format.html {
+        if @author
+          @new_panels = Panel.mylist(@author, 1, 5)
+        end
+      }
       format.json { render json: @scroll.to_json(Scroll.show_json_opt) }
       format.atom 
       format.rss 
index cece2c7..23320d6 100644 (file)
@@ -1,2 +1,126 @@
 class SheetPanelsController < ApplicationController
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+  else
+    before_filter :authenticate_reader, :only => [:index, :show]
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+  end
+  before_filter :authenticate_admin!, :only => [:list, :browse]
+
+  def index
+    @page = SheetPanel.page params[:page]
+    @page_size = SheetPanel.page_size params[:page_size]
+    @sheet_panels = SheetPanel.list(@page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = SheetPanel.list_paginate(@page, @page_size)
+      }
+      format.json { render :json => @sheet_panels.to_json(SheetPanel.list_json_opt) }
+    end
+  end
+
+  def show
+    @sheet_panel = SheetPanel.show(params[:id], [@user, @admin])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render json: @sheet_panel.sheet_panel_as_json(@author) }
+    end
+  end
+  
+  def list
+    @sheet_panels = SheetPanel.all
+
+    respond_to do |format|
+      format.html { render layout: 'system' }# index.html.erb
+      format.json { render json: @sheet_panels }
+    end
+  end
+
+  def browse
+    @sheet_panel = SheetPanel.find(params[:id])
+
+    respond_to do |format|
+      format.html { render layout: 'system' } # show.html.erb
+      format.json { render json: @sheet_panel }
+    end
+  end
+  
+  def new
+    @sheet_panel = SheetPanel.new 
+    @sheet_panel.supply_default
+    respond_to do |format|
+      format.html # new.html.erb
+      format.js
+      format.json { render json: @sheet_panel.sheet_panel_as_json(@author) }
+    end
+  end
+
+  def edit
+    @sheet_panel = SheetPanel.edit(params[:id], @author)
+    respond_to do |format|
+      format.html 
+      format.js
+    end
+  end
+
+  def create
+    @sheet_panel = SheetPanel.new 
+    @sheet_panel.supply_default
+    @sheet_panel.attributes = params[:sheet_panel]
+    @sheet_panel.overwrite @author
+    @sheet = Sheet.edit(@sheet_panel.sheet_id, @author) if @sheet_panel.sheet_id
+    @panel = Panel.show(@sheet_panel.panel_id, @author) if @sheet_panel.panel_id
+    
+    respond_to do |format|
+      if @sheet_panel.store
+        flash[:notice] = I18n.t('flash.notice.created', :model => SheetPanel.model_name.human)
+        format.html { redirect_to play_sheet_path(@sheet) }
+        format.json { render json: @sheet_panel.sheet_panel_as_json(@author) }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_created', :model => SheetPanel.model_name.human)
+        format.html { render action: "new" }
+        format.json { render json: @sheet_panel.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+  
+  def update
+    @sheet_panel = SheetPanel.edit(params[:id], @author)
+    ot = @sheet_panel.t
+    @sheet_panel.attributes = params[:sheet_panel]
+    @sheet_panel.overwrite @author
+    @sheet = Sheet.edit(@sheet_panel.sheet_id, @author) if @sheet_panel.sheet_id
+    respond_to do |format|
+      if @sheet_panel.store ot
+        flash[:notice] = I18n.t('flash.notice.updated', :model => SheetPanel.model_name.human)
+        format.html { redirect_to play_sheet_path(@sheet) }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => SheetPanel.model_name.human)
+        format.html { render action: "edit" }
+        format.json { render json: @sheet_panel.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def destroy
+    @sheet_panel = SheetPanel.edit(params[:id], @author)
+    @sheet = Sheet.edit(@sheet_panel.sheet_id, @author) if @sheet_panel.sheet_id
+    respond_to do |format|
+      if @sheet_panel.destroy_and_shorten
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => SheetPanel.model_name.human)
+        format.html { redirect_to play_sheet_path(@sheet) }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => SheetPanel.model_name.human)
+        format.html { redirect_to sheet_panel_path(@sheet_panel) }
+        format.json { render json: @sheet_panel.errors, status: :unprocessable_entity }
+      end
+    end
+  end
 end
index b24b423..6ab261d 100644 (file)
@@ -1,2 +1,151 @@
 class SheetsController < ApplicationController
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+  else
+    before_filter :authenticate_reader, :only => [:index, :show, :play]
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+  end
+  before_filter :authenticate_admin!, :only => [:list, :browse]
+
+  def index
+    @page = Sheet.page params[:page]
+    @page_size = Sheet.page_size params[:page_size]
+    @sheets = Sheet.list(@page, @page_size)
+    respond_to do |format|
+      format.html {
+        @paginate = Sheet.list_paginate(@page, @page_size)
+      }
+      format.json { render json: @sheets.to_json(Sheet.list_json_opt) }
+      format.atom 
+      format.rss
+    end
+  end
+
+  def show
+    @sheet = Sheet.show(params[:id], [@user, @admin])
+
+    respond_to do |format|
+      format.html {
+        if @author
+          @new_panels = Panel.mylist(@author, 1, 5)
+        end
+      }
+      format.json { render json: @sheet.to_json(Sheet.show_json_opt) }
+      format.atom 
+      format.rss 
+    end
+  end
+
+  def play
+    @sheet = Sheet.show(params[:id], [@user, @admin])
+    @sheet_panels = SheetPanel.play_list(@sheet, @author)
+    respond_to do |format|
+      format.html {
+        if @author
+          @new_panels = Panel.mylist(@author, 1, 5)
+        end
+      }
+      format.json {render text: SheetPanel.list_as_json_text(@sheet_panels, @author)}
+      format.jsonp {
+        render :json => "callback(" + @sheet_panels.to_json_list + ");"
+      }
+    end
+  end
+  
+  def count
+    @sheet = {:count => Sheet.visible_count}
+    respond_to do |format|
+      format.json { render json: @sheet.to_json }
+    end
+  end
+  
+  def list
+    @sheets = Sheet.all
+
+    respond_to do |format|
+      format.html { render layout: 'system' }# index.html.erb
+      format.json { render json: @sheets }
+    end
+  end
+
+  def browse
+    @sheet = Sheet.find(params[:id])
+
+    respond_to do |format|
+      format.html { render layout: 'system' } # show.html.erb
+      format.json { render json: @sheet }
+    end
+  end
+  
+  def new
+    @sheet = Sheet.new
+    @sheet.supply_default
+    respond_to do |format|
+      format.html # new.html.erb
+      format.js
+      format.json { render json: @sheet.to_json(Sheet.show_json_opt) }
+    end
+  end
+
+  def edit
+    @sheet = Sheet.edit(params[:id], @author)
+    respond_to do |format|
+      format.html 
+      format.js
+    end
+  end
+
+  def create
+    @sheet = Sheet.new
+    @sheet.supply_default 
+    @sheet.attributes = params[:sheet]
+    @sheet.overwrite @author
+
+    respond_to do |format|
+      if @sheet.save
+        flash[:notice] = I18n.t('flash.notice.created', :model => Sheet.model_name.human)
+        format.html { redirect_to @sheet }
+        format.json { render json: @sheet.to_json(Sheet.show_json_opt), status: :created, location: @sheet }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_created', :model => Sheet.model_name.human)
+        format.html { render action: "new" }
+        format.json { render json: @sheet.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def update
+    @sheet = Sheet.edit(params[:id], @author)
+    @sheet.attributes = params[:sheet]
+    @sheet.overwrite @author
+    respond_to do |format|
+      if @sheet.save
+        flash[:notice] = I18n.t('flash.notice.updated', :model => Sheet.model_name.human)
+        format.html { redirect_to @sheet }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => Sheet.model_name.human)
+        format.html { render action: "edit" }
+        format.json { render json: @sheet.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def destroy
+    @sheet = Sheet.edit(params[:id], @author)
+    respond_to do |format|
+      if @sheet.destroy_with_sheet_panel
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => Sheet.model_name.human)
+        format.html { redirect_to '/home/sheets' }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Sheet.model_name.human)
+        format.html { redirect_to @sheet }
+        format.json { render json: @sheet.errors, status: :unprocessable_entity }
+      end
+    end
+  end
 end
index ca77f0d..3a4a41c 100644 (file)
@@ -4,7 +4,7 @@ class StoriesController < ApplicationController
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   else
-    before_filter :authenticate_reader, :only => [:index, :show, :comic]
+    before_filter :authenticate_reader, :only => [:index, :show, :play]
     before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
     before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
   end
@@ -27,40 +27,30 @@ class StoriesController < ApplicationController
     @story = Story.show(params[:id], [@user, @admin])
 
     respond_to do |format|
-      format.html # show.html.erb
+      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) }
     end
   end
   
-  def comic
-    @comic = Comic.show(params[:id], [@user, @admin])
-    cnt = Story.count(:conditions => ['comic_id = ?', @comic.id]).to_i
-    @offset = Story.offset cnt, params[:offset]
-    @panel_count = Story.panel_count cnt, params[:count]
-    @stories = Story.play_list(@comic, @author, @offset, @panel_count)
+  def play
+    @story = Story.show(params[:id], [@user, @admin])
+    @page = StorySheet.page params[:page]
+    @sheet = StorySheet.play_sheet(@story, @author, @page)
     respond_to do |format|
       format.html {
-        @prev_offset = if @offset > 0
-          if @offset - @panel_count < 0
-            0
-          else
-            @offset - @panel_count
-          end
-        else
-          nil
-        end
-        @next_offset = if @offset + @panel_count > cnt
-          nil
-        else
-          @offset + @panel_count
-        end
+        @paginate = StorySheet.play_paginate(@story, @page)
         if @author
-          @new_panels = Panel.mylist(@author, 1, 5)
+          @new_sheets = Sheet.mylist(@author, 1, 5)
         end
       }
-      format.json {render text: Story.list_as_json_text(@stories, @author)}
+      format.json {render text: StorySheet.list_as_json_text(@story_sheets, @author)}
       format.jsonp {
-        render :json => "callback(" + @stories.to_json_list + ");"
+        render :json => "callback(" + @story_sheets.to_json_list + ");"
       }
     end
   end
@@ -107,12 +97,11 @@ class StoriesController < ApplicationController
     @story.attributes = params[:story]
     @story.overwrite @author
     @comic = Comic.edit(@story.comic_id, @author) if @story.comic_id
-    @panel = Panel.show(@story.panel_id, @author) if @story.panel_id
     
     respond_to do |format|
       if @story.store
         flash[:notice] = I18n.t('flash.notice.created', :model => Story.model_name.human)
-        format.html { redirect_to action: :comic, id: @story.comic_id }
+        format.html { redirect_to story_path(@story) }
         format.json { render json: @story.story_as_json(@author) }
       else
         flash[:notice] = I18n.t('flash.notice.not_created', :model => Story.model_name.human)
@@ -130,7 +119,7 @@ class StoriesController < ApplicationController
     respond_to do |format|
       if @story.store ot
         flash[:notice] = I18n.t('flash.notice.updated', :model => Story.model_name.human)
-        format.html { redirect_to action: :comic, id: @story.comic_id }
+        format.html { redirect_to story_path(@story) }
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_updated', :model => Story.model_name.human)
@@ -145,7 +134,7 @@ class StoriesController < ApplicationController
     respond_to do |format|
       if @story.destroy_and_shorten
         flash[:notice] = I18n.t('flash.notice.destroyed', :model => Story.model_name.human)
-        format.html { redirect_to :controller => 'stories', :action => :comic, :id => @story.comic_id }
+        format.html { redirect_to comic_path(@story.comic)}
         format.json { head :ok }
       else
         flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => Story.model_name.human)
index 55d1259..cefa5a0 100644 (file)
@@ -1,2 +1,126 @@
 class StorySheetsController < ApplicationController
+  layout 'test' if MagicNumber['test_layout']
+  if MagicNumber['run_mode'] == 0
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+  else
+    before_filter :authenticate_reader, :only => [:index, :show]
+    before_filter :authenticate_user, :only => [:new, :create, :edit, :update, :destroy]
+    before_filter :authenticate_author, :only => [:new, :create, :edit, :update, :destroy]
+  end
+  before_filter :authenticate_admin!, :only => [:list, :browse]
+
+  def index
+    @page = StorySheet.page params[:page]
+    @page_size = StorySheet.page_size params[:page_size]
+    @story_sheets = StorySheet.list(@page, @page_size)
+
+    respond_to do |format|
+      format.html {
+        @paginate = StorySheet.list_paginate(@page, @page_size)
+      }
+      format.json { render :json => @story_sheets.to_json(StorySheet.list_json_opt) }
+    end
+  end
+
+  def show
+    @story_sheet = StorySheet.show(params[:id], [@user, @admin])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render json: @story_sheet.to_json(StorySheet.show_json_opt) }
+    end
+  end
+  
+  def list
+    @story_sheets = StorySheet.all
+
+    respond_to do |format|
+      format.html { render layout: 'system' }# index.html.erb
+      format.json { render json: @story_sheets }
+    end
+  end
+
+  def browse
+    @story_sheet = StorySheet.find(params[:id])
+
+    respond_to do |format|
+      format.html { render layout: 'system' } # show.html.erb
+      format.json { render json: @story_sheet }
+    end
+  end
+  
+  def new
+    @story_sheet = StorySheet.new 
+    @story_sheet.supply_default
+    respond_to do |format|
+      format.html # new.html.erb
+      format.js
+      format.json { render json: @story_sheet.to_json(StorySheet.show_json_opt) }
+    end
+  end
+
+  def edit
+    @story_sheet = StorySheet.edit(params[:id], @author)
+    respond_to do |format|
+      format.html 
+      format.js
+    end
+  end
+
+  def create
+    @story_sheet = StorySheet.new 
+    @story_sheet.supply_default
+    @story_sheet.attributes = params[:story_sheet]
+    @story_sheet.overwrite @author
+    @story = Story.edit(@story_sheet.story_id, @author) if @story_sheet.story_id
+    @sheet = Sheet.show(@story_sheet.sheet_id, @author) if @story_sheet.sheet_id
+    
+    respond_to do |format|
+      if @story_sheet.store
+        flash[:notice] = I18n.t('flash.notice.created', :model => StorySheet.model_name.human)
+        format.html { redirect_to play_story_path(@story) }
+        format.json { render json: @story_sheet.to_json(StorySheet.show_json_opt) }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_created', :model => StorySheet.model_name.human)
+        format.html { render action: "new" }
+        format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+  
+  def update
+    @story_sheet = StorySheet.edit(params[:id], @author)
+    ot = @story_sheet.t
+    @story_sheet.attributes = params[:story_sheet]
+    @story_sheet.overwrite @author
+    @story = Story.edit(@story_sheet.story_id, @author) if @story_sheet.story_id
+    respond_to do |format|
+      if @story_sheet.store ot
+        flash[:notice] = I18n.t('flash.notice.updated', :model => StorySheet.model_name.human)
+        format.html { redirect_to play_story_path(@story) }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_updated', :model => StorySheet.model_name.human)
+        format.html { render action: "edit" }
+        format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  def destroy
+    @story_sheet = StorySheet.edit(params[:id], @author)
+    @story = Story.edit(@story_sheet.story_id, @author) if @story_sheet.story_id
+    respond_to do |format|
+      if @story_sheet.destroy_and_shorten
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => StorySheet.model_name.human)
+        format.html { redirect_to play_story_path(@story) }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => StorySheet.model_name.human)
+        format.html { redirect_to story_sheet_path(@story_sheet) }
+        format.json { render json: @story_sheet.errors, status: :unprocessable_entity }
+      end
+    end
+  end
 end
index e1eb266..c5a6899 100644 (file)
@@ -46,6 +46,26 @@ module ApplicationHelper
     icon_tag :ScrollPanel, opt
   end
   
+  def comic_icon opt = {}
+    icon_tag :Comic, opt
+  end
+  
+  def story_icon opt = {}
+    icon_tag :Story, opt
+  end
+  
+  def story_sheet_icon opt = {}
+    icon_tag :StorySheet, opt
+  end
+  
+  def sheet_icon opt = {}
+    icon_tag :Sheet, opt
+  end
+  
+  def sheet_panel_icon opt = {}
+    icon_tag :Sheet, opt
+  end
+  
   def panel_icon opt = {}
     icon_tag :Panel, opt
   end
index 7ae8ba8..0c3527b 100644 (file)
@@ -1,6 +1,6 @@
 #コミック
 class Comic < ActiveRecord::Base
-  has_many :stories
+  has_many :stories, :order => 't'
   belongs_to :author
   
   validates :title, :presence => true, :length => {:maximum => 100}
@@ -145,7 +145,7 @@ class Comic < ActiveRecord::Base
     res = false
     Comic.transaction do
       self.stories.each do |story|
-        raise ActiveRecord::Rollback unless story.destroy
+        raise ActiveRecord::Rollback unless story.destroy_and_shorten
       end
       raise ActiveRecord::Rollback unless self.destroy
       res = true
index 39d251b..74b8aa3 100644 (file)
@@ -14,6 +14,9 @@ class SheetPanel < ActiveRecord::Base
   def supply_default
     self.sheet_id = nil
     self.panel_id = nil
+    self.x = 15
+    self.y = 15
+    self.z = 1
     self.t = nil
   end
   
index b655b67..b94b11d 100644 (file)
@@ -46,6 +46,10 @@ class Story < ActiveRecord::Base
     self.visible > 0
   end
   
+  def disp_t
+    self.t + 1
+  end
+  
   def self.default_page_size
     25
   end
index f988d29..699b444 100644 (file)
@@ -52,13 +52,6 @@ class StorySheet < ActiveRecord::Base
     offset
   end
   
-  def self.sheet_count cnt, prm = self.default_sheet_size
-    count = prm.to_i
-    count = self.max_sheet_size if count > self.max_sheet_size
-    count = self.default_sheet_size if count < 1
-    count
-  end
-  
   def self.default_page_size
     25
   end
@@ -80,8 +73,8 @@ class StorySheet < ActiveRecord::Base
     page_size
   end
   
-  def self.play_list_where cid
-    ['story_sheets.story_id = ?', cid]
+  def self.play_list_where sid
+    ['story_sheets.story_id = ?', sid]
   end
   
   def self.list_where
@@ -96,8 +89,9 @@ class StorySheet < ActiveRecord::Base
     ['story_sheets.author_id = ? and stories.visible > 0', au.id]
   end
   
-  def self.play_list story, author, offset = 0, limit = StorySheet.default_sheet_size
-    StorySheet.where(self.play_list_where(story.id)).includes(StorySheet.list_opt).order('story_sheets.t').offset(offset).limit(limit)
+  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
   end
   
   def self.list page = 1, page_size = self.default_page_size
@@ -124,6 +118,10 @@ class StorySheet < ActiveRecord::Base
     Kaminari.paginate_array(Array.new(StorySheet.where(self.himlist_where(au)).includes(StorySheet.list_opt).count, nil)).page(page).per(page_size)
   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)
+  end
+  
   def self.list_opt
     {
       :author => {}, 
@@ -185,6 +183,10 @@ class StorySheet < ActiveRecord::Base
     r.blank? ? 0 : r.to_i + 1
   end
   
+  def self.top_sheet story, author
+    StorySheet.play_list(story, author).first
+  end
+  
   def self.max_t story_id
     StorySheet.maximum(:t, :conditions => ['story_id = ?', story_id])
   end
diff --git a/app/views/authors/comics.html.erb b/app/views/authors/comics.html.erb
new file mode 100644 (file)
index 0000000..0d1c9b3
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @comics.each do |comic| %>
+    <%= render 'comics/list_item', :comic => comic, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('comics.new.title'), new_comic_path %>
diff --git a/app/views/authors/sheet_panels.html.erb b/app/views/authors/sheet_panels.html.erb
new file mode 100644 (file)
index 0000000..ce33010
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @sheet_panels.each do |sheet_panel| %>
+    <%= render 'sheet_panels/list_item', :sheet_panel => sheet_panel, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('sheet_panels.new.title'), new_sheet_panel_path %>
diff --git a/app/views/authors/sheets.html.erb b/app/views/authors/sheets.html.erb
new file mode 100644 (file)
index 0000000..fbc5851
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @sheets.each do |sheet| %>
+    <%= render 'sheets/list_item', :sheet => sheet, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('sheets.new.title'), new_sheet_path %>
index 9f2d3f2..2ffcf81 100644 (file)
 </p>
 
 <p>
+  <%= link_to t('authors.show.to_comics'), comics_author_path(@au) %>
+</p>
+
+<p>
+  <%= link_to t('authors.show.to_stories'), stories_author_path(@au) %>
+</p>
+
+<p>
+  <%= link_to t('authors.show.to_story_sheets'), story_sheets_author_path(@au) %>
+</p>
+
+<p>
+  <%= link_to t('authors.show.to_sheets'), sheets_author_path(@au) %>
+</p>
+
+<p>
+  <%= link_to t('authors.show.to_sheet_panels'), sheet_panels_author_path(@au) %>
+</p>
+
+<p>
   <%= link_to t('authors.show.to_panels'), panels_author_path(@au) %>
 </p>
 
diff --git a/app/views/authors/stories.html.erb b/app/views/authors/stories.html.erb
new file mode 100644 (file)
index 0000000..a99f490
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @stories.each do |story| %>
+    <%= render 'stories/list_item', :story => story, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('stories.new.title'), new_story_path %>
diff --git a/app/views/authors/story_sheets.html.erb b/app/views/authors/story_sheets.html.erb
new file mode 100644 (file)
index 0000000..52af722
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @story_sheets.each do |story_sheet| %>
+    <%= render 'story_sheets/list_item', :story_sheet => story_sheet, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('story_sheets.new.title'), new_story_sheet_path %>
index 2e9d719..059b727 100644 (file)
@@ -1,14 +1,14 @@
 <tr>
   <td>
     <%= link_to comic_icon(:object => comic, :size => 25), comic_path(comic) %>
-    <%= link_to h(truncate(comic.title, :length => 40)), :controller => 'stories', :action => :comic, :id => comic.id %>
+    <%= link_to h(truncate(comic.title, :length => 40)), comic_path(comic) %>
     (<%= comic.stories.size -%>)
   </td>
   <td>
     <%= distance_of_time_in_words_to_now comic.updated_at %>
   </td>
   <td>
-    <%= link_to author_icon(:object => comic.author, :size => 25), comic_path(comic.author) %>
+    <%= link_to author_icon(:object => comic.author, :size => 25), author_path(comic.author) %>
     <%= link_to h(truncate(comic.author.name, :length => 12)), author_path(comic.author) %>
   </td>
   <td>
index 81a1bbf..4b73f49 100644 (file)
@@ -4,7 +4,7 @@
 
 <p>
   <b><%= t_m 'Comic.title' -%>:</b>
-  <%= link_to h(@comic.title), :controller => 'stories', :action => :comic, :id => @comic.id %>
+  <%= link_to h(@comic.title), comic_path(@comic) %>
 </p>
 
 <p>
   <%= link_to h(@comic.author.name), author_path(@comic.author) %>
 </p>
 
+<% @comic.stories.each do |story| %>
+  <% if story.visible? @author -%>
+    <div>
+      <%= link_to t('stories.show.t', :t => story.disp_t), story_path(story) %>
+      <%= link_to h(story.title), play_story_path(story) %>
+    </div>
+  <% end %>
+<% end %>
 <p>
   <b><%= t_m 'Comic.created_at' -%>:</b>
   <%= l @comic.created_at %>
   <%= l @comic.updated_at %>
 </p>
 
-<%= link_to t('link.edit'), edit_comic_path(@comic) %>
+<% if @comic.own? @author -%>
+  <%= link_to t('link.edit'), edit_comic_path(@comic) %>
+  <%= link_to t('link.destroy'), comic_path(@comic), :method => :delete %>
+
+  <h2>
+    <%= t('stories.index.new') %>
+  </h2>
+  <% @story = Story.new -%>
+  <% @story.supply_default -%>
+  <% @story.attributes = {:comic_id => @comic.id} -%>
+  <%= render 'stories/form' %>
+<% end %>
diff --git a/app/views/home/comics.html.erb b/app/views/home/comics.html.erb
new file mode 100644 (file)
index 0000000..9d0287d
--- /dev/null
@@ -0,0 +1,10 @@
+<h1><%= t '.title' -%></h1>
+<p id="notice"><%= notice %></p>
+
+<table>
+  <% @comics.each do |comic| %>
+    <%= render 'comics/list_item', :comic => comic, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('comics.new.title'), new_comic_path %>
index 1f47cb1..345ca40 100644 (file)
       <%= link_to t_m('ScrollPanel'), '/home/scroll_panels' %>
     </td>
     <td width="200px" align="center" valign="middle">
-      <%= link_to t_m('Panel'), '/home/panels' %>
+      <%= link_to t_m('Comic'), '/home/comics' %>
+    </td>
+    <td width="200px" align="center" valign="middle">
+      <%= link_to t_m('Story'), '/home/stories' %>
+    </td>
+  </tr>
+  <tr height="100px">
+    <td width="200px" align="center" valign="middle">
+      <%= link_to t_m('StorySheet'), '/home/story_sheets' %>
+    </td>
+    <td width="200px" align="center" valign="middle">
+      <%= link_to t_m('Sheet'), '/home/sheets' %>
     </td>
     <td width="200px" align="center" valign="middle">
+      <%= link_to t_m('SheetPanel'), '/home/sheet_panels' %>
+    </td>
+    <td width="200px" align="center" valign="middle">
+      <%= link_to t_m('Panel'), '/home/panels' %>
     </td>
   </tr>
 </table>
diff --git a/app/views/home/sheet_panels.html.erb b/app/views/home/sheet_panels.html.erb
new file mode 100644 (file)
index 0000000..ce33010
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @sheet_panels.each do |sheet_panel| %>
+    <%= render 'sheet_panels/list_item', :sheet_panel => sheet_panel, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('sheet_panels.new.title'), new_sheet_panel_path %>
diff --git a/app/views/home/sheets.html.erb b/app/views/home/sheets.html.erb
new file mode 100644 (file)
index 0000000..1ccf0d3
--- /dev/null
@@ -0,0 +1,10 @@
+<h1><%= t '.title' -%></h1>
+<p id="notice"><%= notice %></p>
+
+<table>
+  <% @sheets.each do |sheet| %>
+    <%= render 'sheets/list_item', :sheet => sheet, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('sheets.new.title'), new_sheet_path %>
diff --git a/app/views/home/stories.html.erb b/app/views/home/stories.html.erb
new file mode 100644 (file)
index 0000000..a99f490
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @stories.each do |story| %>
+    <%= render 'stories/list_item', :story => story, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('stories.new.title'), new_story_path %>
diff --git a/app/views/home/story_sheets.html.erb b/app/views/home/story_sheets.html.erb
new file mode 100644 (file)
index 0000000..52af722
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @story_sheets.each do |story_sheet| %>
+    <%= render 'story_sheets/list_item', :story_sheet => story_sheet, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('story_sheets.new.title'), new_story_sheet_path %>
index 618f32c..6e89624 100644 (file)
@@ -52,6 +52,7 @@
 </div>\r
 <div width="100%" style="background-color: #ddfadd; padding: 5px;">\r
   <%= link_to t('tab.reader.title'), '/' %>\r
+  <%= link_to t_m('Comic'), main_app.comics_path %>\r
   <%= link_to t_m('Scroll'), main_app.scrolls_path %>\r
   <%= link_to t_m('Panel'), main_app.panels_path %>\r
   <%= link_to t_m('ResourcePicture'), main_app.resource_pictures_path %>\r
@@ -63,6 +64,9 @@
 <% if @author %>\r
   <div width="100%" style="background-color: #fadddd; padding: 5px;">\r
     <%= link_to t('tab.creator.home'), '/home' %>\r
+    <%= link_to t('tab.creator.comic'), '/home/comics' %>\r
+    <%= link_to t('tab.creator.story'), '/home/stories' %>\r
+    <%= link_to t('tab.creator.sheet'), '/home/sheets' %>\r
     <%= link_to t('tab.creator.scroll'), '/home/scrolls' %>\r
     <%= link_to t('tab.creator.panel'), '/home/panels' %>\r
     <% if @artist %>\r
index 89e4abb..29103e0 100644 (file)
@@ -5,7 +5,7 @@
   <% 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 %>
-    <% end %>
+  <% panel.panel_elements.each do |elm| %>
+    <%= render elm.class.to_s.tableize + '/element', :elm => elm, :spot => spot %>
+  <% end %>
 </div>
index d947d08..c939c1c 100644 (file)
 
 
 <% if @author %>
-  <h2><%= t('panels.show.new_scrolls') -%></h2>
-  <table>
-    <% @new_scrolls.each do |scroll| %>
-      <%= render 'append_scroll', :panel => @panel, :scroll => scroll, :author => @author %>
-    <% end %>
-  </table>
-  <h2><%= t('panels.show.fresh_scrolls') -%></h2>
-  <table>
-    <% @fresh_scrolls.each do |scroll| %>
-      <%= render 'append_scroll', :panel => @panel, :scroll => scroll, :author => @author %>
-    <% end %>
-  </table>
   <h2><%= t('panels.show.copy') -%></h2>
   <%= form_for(Panel.new, :html => {:jqform => 'pettanr-panel-form'}) do |f| %>
 
       <%= submit_tag t('panels.show.inspire') -%>
     </div>
   <% end %>
+  
+  <h2><%= t('scroll_panels.append.new_scrolls') -%></h2>
+  <table>
+    <% @new_scrolls.each do |scroll| %>
+      <%= render 'scroll_panels/append_scroll', :panel => @panel, :scroll => scroll, :author => @author %>
+    <% end %>
+  </table>
+  <h2><%= t('scroll_panels.append.fresh_scrolls') -%></h2>
+  <table>
+    <% @fresh_scrolls.each do |scroll| %>
+      <%= render 'scroll_panels/append_scroll', :panel => @panel, :scroll => scroll, :author => @author %>
+    <% end %>
+  </table>
+  <h2><%= t('sheet_panels.append.new_sheets') -%></h2>
+  <table>
+    <% @new_sheets.each do |sheet| %>
+      <%= render 'sheet_panels/append_sheet', :panel => @panel, :sheet => sheet, :author => @author %>
+    <% end %>
+  </table>
+  <h2><%= t('sheet_panels.append.fresh_sheets') -%></h2>
+  <table>
+    <% @fresh_sheets.each do |sheet| %>
+      <%= render 'sheet_panels/append_sheet', :panel => @panel, :sheet => sheet, :author => @author %>
+    <% end %>
+  </table>
 <% end %>
index a7d84bc..136ac11 100644 (file)
@@ -4,7 +4,7 @@
     <%= link_to author_icon(:object => panel.author, :size => 17), author_path(panel.author) %>
   </td>
   <td>
-    <%= link_to h(truncate(h(panel.caption), :length => 40)), :controller => 'scroll_panels', :action => :scroll, :id => scroll.id %>
+    <%= link_to h(truncate(h(panel.caption), :length => 40)), panel_path(panel) %>
   </td>
   <td>
     <%= l panel.updated_at %>
@@ -15,7 +15,7 @@
       <%= f.hidden_field :scroll_id %>
       <%= f.hidden_field :t %>
       <%= f.hidden_field :panel_id %>
-      <%= f.submit t('scroll_panels.scroll.append') %>
+      <%= f.submit t('scroll_panels.append.panel') %>
     <% end %>
   </td>
 </tr>
similarity index 80%
rename from app/views/panels/_append_scroll.html.erb
rename to app/views/scroll_panels/_append_scroll.html.erb
index 83aef11..1813b38 100644 (file)
@@ -1,14 +1,14 @@
 <tr>
   <td>
     <%= link_to scroll_icon(:object => scroll, :size => 25), scroll_path(scroll) %>
-    <%= link_to h(truncate(scroll.title, :length => 40)), :controller => 'scroll_panels', :action => :scroll, :id => scroll.id %>
+    <%= link_to h(truncate(scroll.title, :length => 40)), play_scroll_path(scroll) %>
     (<%= scroll.scroll_panels.size -%>)
   </td>
   <td>
     <%= distance_of_time_in_words_to_now scroll.updated_at %>
   </td>
   <td>
-    <%= link_to author_icon(:object => scroll.author, :size => 25), scroll_path(scroll.author) %>
+    <%= link_to author_icon(:object => scroll.author, :size => 25), author_path(scroll.author) %>
     <%= link_to h(truncate(scroll.author.name, :length => 12)), author_path(scroll.author) %>
   </td>
   <td>
@@ -19,7 +19,7 @@
         <%= f.hidden_field :t %>
         <%= f.hidden_field :panel_id %>
         <div class="actions">
-          <%= f.submit t('panels.show.append') %>
+          <%= f.submit t('scroll_panels.append.scroll') %>
         </div>
       <% end %>
     <% end %>
index 719097a..96125c5 100644 (file)
@@ -3,7 +3,7 @@
       <%= link_to scroll_icon(:object => scroll_panel.scroll, :size => 25), scroll_path(scroll_panel.scroll) %>
     </td>
     <td>
-      <%= link_to h(scroll_panel.scroll.title), :controller => 'scroll_panels', :action => :scroll, :id => scroll_panel.scroll.id %>
+      <%= link_to h(scroll_panel.scroll.title), play_scroll_path(scroll_panel.scroll) %>
     </td>
     <td>
       <%= link_to author_icon(:object => scroll_panel.scroll.author, :size => 17), author_path(scroll_panel.scroll.author) %>
index a176605..cd1d37d 100644 (file)
@@ -1,6 +1,6 @@
 <h1>
   <%= link_to scroll_icon, scroll_path(scroll) %>
-  <%= link_to h(scroll.title), :controller => 'scroll_panels', :action => :scroll, :id => scroll.id %>
+  <%= link_to h(scroll.title), play_scroll_path(scroll) %>
 </h1>
 <% if scroll.own? author -%>
   <%= form_for(scroll) do |f| %>
index 91bdcac..dc72ec5 100644 (file)
@@ -2,4 +2,4 @@
 <p id="notice"><%= notice %></p>
 
 <%= render 'form' %>
-<%= button_to 'Destroy', @scroll_panel.panel, confirm: 'Are you sure?', method: :delete %>
+<%= button_to 'Destroy', @scroll_panel, confirm: 'Are you sure?', method: :delete %>
diff --git a/app/views/scroll_panels/scroll.html.erb b/app/views/scroll_panels/scroll.html.erb
deleted file mode 100644 (file)
index b25cca2..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<% @page_title = @scroll.title %>
-<h1><%= t '.title' -%></h1>
-<p id="notice"><%= notice %></p>
-<%= render 'scroll_header', :scroll => @scroll, :author => @author %>
-
-<% if @scroll_panels.empty? -%>
-  <h2><%= t('scroll_panels.scroll.empty') %></h2>
-<% else %>
-  <% @scroll_panels.each do |scroll_panel| %>
-    <% if scroll_panel.panel -%>
-      <%= render 'panels/body', :panel => scroll_panel.panel, :author => @author, :spot => nil %>
-    <% end %>
-    <%= render 'footer', :scroll_panel => scroll_panel, :author => @author %>
-  <% end %>
-  <%= render 'licensed_pictures', :licensed_pictures => ScrollPanel.licensed_pictures(@scroll_panels) %>
-
-  <% if @prev_offset -%>
-    <%= link_to h('<<prev'), scroll_scroll_panel_path(@scroll, {:offset => @prev_offset, :count => @panel_count}) %>
-  <% end %>
-
-  <% if @next_offset -%>
-    <%= link_to h('next>>'), scroll_scroll_panel_path(@scroll, {:offset => @next_offset, :count => @panel_count}) %>
-  <% end %>
-
-<% end %>
-<% if @scroll.own? @author -%>
-  <h3><%= t('scroll_panels.scroll.new_panels') -%></h3>
-  <table>
-    <% @new_panels.each do |panel| %>
-      <%= render 'append_panel', :scroll => @scroll, :panel => panel, :author => @author %>
-    <% end %>
-  </table>
-<% end %>
index a883094..bdd9edf 100644 (file)
@@ -4,7 +4,7 @@
 <p>
   <b><%= t_m 'ScrollPanel.scroll_id' -%>:</b>
   <%= link_to scroll_icon(:object => @scroll_panel.scroll), scroll_path(@scroll_panel.scroll) %>
-  <%= link_to h(@scroll_panel.scroll.title), :controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll.id %>
+  <%= link_to h(@scroll_panel.scroll.title), play_scroll_path(@scroll_panel.scroll) %>
 </p>
 
 <p>
index eb97447..0bae33a 100644 (file)
@@ -8,7 +8,7 @@
     <%= distance_of_time_in_words_to_now scroll.updated_at %>
   </td>
   <td>
-    <%= link_to author_icon(:object => scroll.author, :size => 25), scroll_path(scroll.author) %>
+    <%= link_to author_icon(:object => scroll.author, :size => 25), author_path(scroll.author) %>
     <%= link_to h(truncate(scroll.author.name, :length => 12)), author_path(scroll.author) %>
   </td>
   <td>
index 7689289..5efd909 100644 (file)
@@ -4,7 +4,7 @@
 <%= render 'scroll_panels/scroll_header', :scroll => @scroll, :author => @author %>
 
 <% if @scroll_panels.empty? -%>
-  <h2><%= t('scroll_panels.scroll.empty') %></h2>
+  <h2><%= t('scrolls.play.empty') %></h2>
 <% else %>
   <% @scroll_panels.each do |scroll_panel| %>
     <% if scroll_panel.panel -%>
@@ -24,7 +24,7 @@
 
 <% end %>
 <% if @scroll.own? @author -%>
-  <h3><%= t('scroll_panels.scroll.new_panels') -%></h3>
+  <h3><%= t('scroll_panels.append.new_panels') -%></h3>
   <table>
     <% @new_panels.each do |panel| %>
       <%= render 'scroll_panels/append_panel', :scroll => @scroll, :panel => panel, :author => @author %>
index 48b0d62..18320c4 100644 (file)
@@ -4,7 +4,7 @@
 
 <p>
   <b><%= t_m 'Scroll.title' -%>:</b>
-  <%= link_to h(@scroll.title), :controller => 'scroll_panels', :action => :scroll, :id => @scroll.id %>
+  <%= link_to h(@scroll.title), play_scroll_path(@scroll) %>
 </p>
 
 <p>
 </p>
 
 <%= link_to t('link.edit'), edit_scroll_path(@scroll) %>
+<% if @scroll.own? @author -%>
+  <h3><%= t('scroll_panels.append.new_panels') -%></h3>
+  <table>
+    <% @new_panels.each do |panel| %>
+      <%= render 'scroll_panels/append_panel', :scroll => @scroll, :panel => panel, :author => @author %>
+    <% end %>
+  </table>
+<% end %>
diff --git a/app/views/sheet_panels/_append_panel.html.erb b/app/views/sheet_panels/_append_panel.html.erb
new file mode 100644 (file)
index 0000000..64f7a00
--- /dev/null
@@ -0,0 +1,26 @@
+<tr>
+  <td>
+    <%= link_to panel_icon(:object => panel, :size => 25), panel_path(panel) %>
+    <%= link_to author_icon(:object => panel.author, :size => 17), author_path(panel.author) %>
+  </td>
+  <td>
+    <%= link_to h(truncate(h(panel.caption), :length => 40)), panel_path(panel) %>
+  </td>
+  <td>
+    <%= l panel.updated_at %>
+  </td>
+  <td>
+    <% @sheet_panel = SheetPanel.new -%>
+    <% @sheet_panel.supply_default -%>
+    <% @sheet_panel.attributes = {:sheet_id => sheet.id, :panel_id => panel.id} -%>
+    <%= form_for(@sheet_panel) do |f| %>
+      <%= f.hidden_field :sheet_id %>
+      <%= f.hidden_field :x %>
+      <%= f.hidden_field :y %>
+      <%= f.hidden_field :z %>
+      <%= f.hidden_field :t %>
+      <%= f.hidden_field :panel_id %>
+      <%= f.submit t('sheet_panels.append.panel') %>
+    <% end %>
+  </td>
+</tr>
diff --git a/app/views/sheet_panels/_append_sheet.html.erb b/app/views/sheet_panels/_append_sheet.html.erb
new file mode 100644 (file)
index 0000000..7bbc797
--- /dev/null
@@ -0,0 +1,29 @@
+<tr>
+  <td>
+    <%= link_to sheet_icon(:object => sheet, :size => 25), sheet_path(sheet) %>
+    <%= link_to h(truncate(sheet.caption, :length => 40)), play_sheet_path(sheet) %>
+    (<%= sheet.sheet_panels.size -%>)
+  </td>
+  <td>
+    <%= distance_of_time_in_words_to_now sheet.updated_at %>
+  </td>
+  <td>
+    <%= link_to author_icon(:object => sheet.author, :size => 25), sheet_path(sheet.author) %>
+    <%= link_to h(truncate(sheet.author.name, :length => 12)), author_path(sheet.author) %>
+  </td>
+  <td>
+    <% if sheet.own? author %>
+      <% @sheet_panel = SheetPanel.new %>
+      <% @sheet_panel.supply_default -%>
+      <% @sheet_panel.attributes = {:sheet_id => sheet.id, :panel_id => panel.id} -%>
+      <%= form_for(@sheet_panel) do |f| %>
+        <%= f.hidden_field :sheet_id %>
+        <%= f.hidden_field :t %>
+        <%= f.hidden_field :panel_id %>
+        <div class="actions">
+          <%= f.submit t('sheet_panels.append.sheet') %>
+        </div>
+      <% end %>
+    <% end %>
+  </td>
+</tr>
diff --git a/app/views/sheet_panels/_form.html.erb b/app/views/sheet_panels/_form.html.erb
new file mode 100644 (file)
index 0000000..238fe21
--- /dev/null
@@ -0,0 +1,32 @@
+<%= form_for(@sheet_panel) do |f| %>
+  <%= render 'system/error_explanation', :obj => @sheet_panel %>
+
+  <div class="field">
+    <%= f.label :sheet_id %><br />
+    <%= f.number_field :sheet_id %>
+  </div>
+  <div class="field">
+    <%= f.label :x %><br />
+    <%= f.number_field :x %>
+  </div>
+  <div class="field">
+    <%= f.label :y %><br />
+    <%= f.number_field :y %>
+  </div>
+  <div class="field">
+    <%= f.label :z %><br />
+    <%= f.number_field :z %>
+  </div>
+  <div class="field">
+    <%= f.label :t %><br />
+    <%= f.number_field :t %>
+  </div>
+  <div class="field">
+    <%= f.label :panel_id %><br />
+    <%= f.number_field :panel_id %>
+  </div>
+
+  <div class="actions">
+    <%= f.submit %>
+  </div>
+<% end %>
diff --git a/app/views/sheet_panels/_list_item.html.erb b/app/views/sheet_panels/_list_item.html.erb
new file mode 100644 (file)
index 0000000..3879017
--- /dev/null
@@ -0,0 +1,28 @@
+  <tr>
+    <td>
+      <%= link_to sheet_icon(:object => sheet_panel.sheet, :size => 25), sheet_path(sheet_panel.sheet) %>
+    </td>
+    <td>
+      <%= link_to h(sheet_panel.sheet.caption), play_sheet_path(sheet_panel.sheet) %>
+    </td>
+    <td>
+      <%= link_to author_icon(:object => sheet_panel.sheet.author, :size => 17), author_path(sheet_panel.sheet.author) %>
+    </td>
+    <td>
+      <%= link_to sheet_panel_icon(:object => sheet_panel, :size => 25), sheet_panel_path(sheet_panel) %>
+    </td>
+    <td>
+      <%= link_to author_icon(:object => sheet_panel.author, :size => 17), author_path(sheet_panel.author) %>
+    </td>
+    <td>
+      No.<%= sheet_panel.t %>
+    </td>
+    <td>
+      <%= l sheet_panel.updated_at %>
+    </td>
+    <td>
+      <% if sheet_panel.panel %>
+        <%= h sheet_panel.panel.caption %>
+      <% end %>
+    </td>
+  </tr>
diff --git a/app/views/sheet_panels/_order.html.erb b/app/views/sheet_panels/_order.html.erb
new file mode 100644 (file)
index 0000000..ace4b13
--- /dev/null
@@ -0,0 +1,15 @@
+<%= form_for(sheet_panel) do |f| %>
+  <table class="no-border">
+    <tr>
+      <td>
+        No.
+        <%= f.number_field :t, :size => 3 %>
+        <%= f.hidden_field :panel_id %>
+        <%= f.hidden_field :sheet_id %>
+      </td>
+      <td>
+        <%= f.submit t 'sheet_panels.move' %>
+      </td>
+    </tr>
+  </table>
+<% end %>
diff --git a/app/views/sheet_panels/_play_footer.html.erb b/app/views/sheet_panels/_play_footer.html.erb
new file mode 100644 (file)
index 0000000..c2dd438
--- /dev/null
@@ -0,0 +1,21 @@
+<table class="no-border" style="margin: 0px; padding: 0px; width=100%">
+  <tr>
+    <td>
+      <% if sheet_panel.panel -%>
+        <%= link_to panel_icon(:object => sheet_panel.panel, :size => 25), panel_path(sheet_panel.panel) %>
+        <%= link_to author_icon(:object => sheet_panel.panel.author, :size => 17), author_path(sheet_panel.panel.author) %>
+      <% end %>
+    </td>
+    <td>
+      <%= link_to sheet_panel_icon(:object => sheet_panel, :size => 25), sheet_panel_path(sheet_panel) %>
+      <%= link_to author_icon(:object => sheet_panel.author, :size => 17), author_path(sheet_panel.author) %>
+    </td>
+    <td>
+      <% if sheet_panel.own? author %>
+        <%= render 'sheet_panels/order', :sheet_panel => sheet_panel %>
+      <% else %>
+        No.<%= sheet_panel.t %>
+      <% end %>
+    </td>
+  </tr>
+</table>
diff --git a/app/views/sheet_panels/_play_header.html.erb b/app/views/sheet_panels/_play_header.html.erb
new file mode 100644 (file)
index 0000000..09251ee
--- /dev/null
@@ -0,0 +1,21 @@
+<% if sheet.own? author -%>
+  <%= form_for(sheet) do |f| %>
+    <div class="field">
+      <%= f.label :caption %><br />
+      <%= f.text_field :caption %>
+    </div>
+    <div class="field">
+      <%= f.label :visible %><br />
+      <%= f.collection_select :visible, t_select_items(MagicNumber['sheet_visible_items']), :last, :first, :html => {:selected => @sheet.visible} %>
+    </div>
+    <div class="actions">
+      <%= f.submit %>
+    </div>
+  <% end %>
+<% else %>
+<% end %>
+
+<div>
+  <%= link_to author_icon(:object => sheet.author, :size => 25), author_path(sheet.author) %>
+  <%= link_to h(truncate(sheet.author.name, :length => 12)), author_path(sheet.author) %>
+</div>
diff --git a/app/views/sheet_panels/browse.html.erb b/app/views/sheet_panels/browse.html.erb
new file mode 100644 (file)
index 0000000..6772579
--- /dev/null
@@ -0,0 +1,28 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b>sheet_id:</b>
+  <%= @sheet_panel.sheet_id %>
+</p>
+
+<p>
+  <b>panel_id:</b>
+  <%= @sheet_panel.panel_id %>
+</p>
+
+<p>
+  <b>t:</b>
+  <%= @sheet_panel.t %>
+</p>
+
+<p>
+  <b>author_id:</b>
+  <%= @sheet_panel.author_id %>
+</p>
+
+<p>
+  <b>updated_at:</b>
+  <%= @sheet_panel.updated_at %>
+</p>
+
+<%= link_to 'Back', :action => :list %>
diff --git a/app/views/sheet_panels/edit.html.erb b/app/views/sheet_panels/edit.html.erb
new file mode 100644 (file)
index 0000000..1d67f75
--- /dev/null
@@ -0,0 +1,4 @@
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<%= render 'form' %>
diff --git a/app/views/sheet_panels/edit.js.erb b/app/views/sheet_panels/edit.js.erb
new file mode 100644 (file)
index 0000000..d7bfe9f
--- /dev/null
@@ -0,0 +1 @@
+$("#sheet_panel-update-<%= @sheet_panel.id -%>").html("<%= escape_javascript(render('editform')) -%>");
diff --git a/app/views/sheet_panels/index.html.erb b/app/views/sheet_panels/index.html.erb
new file mode 100644 (file)
index 0000000..24da388
--- /dev/null
@@ -0,0 +1,8 @@
+<h1><%= t '.title' -%></h1>
+<table>
+  <% @sheet_panels.each do |sheet_panel| %>
+    <%= render 'list_item', :sheet_panel => sheet_panel, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('sheet_panels.new.title'), new_sheet_panel_path %>
diff --git a/app/views/sheet_panels/list.html.erb b/app/views/sheet_panels/list.html.erb
new file mode 100644 (file)
index 0000000..7790abc
--- /dev/null
@@ -0,0 +1,29 @@
+<h1>Listing SheetPanel</h1>
+
+<table>
+  <tr>
+    <th>id</th>
+    <th>sheet_id</th>
+    <th>panel_id</th>
+    <th>t</th>
+    <th>author_id</th>
+    <th>created_at</th>
+    <th>updated_at</th>
+    <th></th>
+  </tr>
+
+<%  @sheet_panels.each do |sheet_panel| %>
+  <tr>
+    <td><%= link_to sheet_panel.id, :action => :browse, :id => sheet_panel.id %></td>
+    <td><%= sheet_panel.sheet_id %></td>
+    <td><%= sheet_panel.panel_id %></td>
+    <td><%= sheet_panel.t %></td>
+    <td><%= link_to sheet_panel.author_id, :controller => '/authors', :action => :browse, :id => sheet_panel.author_id %></td>
+    <td><%= sheet_panel.created_at %></td>
+    <td><%= sheet_panel.updated_at %></td>
+    <td>
+    </td>
+  </tr>
+<% end %>
+</table>
+
diff --git a/app/views/sheet_panels/new.html.erb b/app/views/sheet_panels/new.html.erb
new file mode 100644 (file)
index 0000000..f33a2f8
--- /dev/null
@@ -0,0 +1,3 @@
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
diff --git a/app/views/sheet_panels/show.html.erb b/app/views/sheet_panels/show.html.erb
new file mode 100644 (file)
index 0000000..9b2c05f
--- /dev/null
@@ -0,0 +1,56 @@
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b><%= t_m 'SheetPanel.sheet_id' -%>:</b>
+  <%= link_to sheet_icon(:object => @sheet_panel.sheet), sheet_path(@sheet_panel.sheet) %>
+  <%= link_to h(@sheet_panel.sheet.caption), play_sheet_path(@sheet_panel.sheet) %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.panel_id' -%>:</b>
+  <%= link_to panel_icon(:object => @sheet_panel.panel), panel_path(@sheet_panel.panel) %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.x' -%>:</b>
+  <%= @sheet_panel.x %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.y' -%>:</b>
+  <%= @sheet_panel.y %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.z' -%>:</b>
+  <%= @sheet_panel.z %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.t' -%>:</b>
+  <%= @sheet_panel.t %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.author_id' -%>:</b>
+  <%= link_to author_icon(:object => @sheet_panel.author), author_path(@sheet_panel.author) %>
+  <%= link_to h(@sheet_panel.author.name), author_path(@sheet_panel.author) %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.created_at' -%>:</b>
+  <%= l @sheet_panel.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'SheetPanel.updated_at' -%>:</b>
+  <%= l @sheet_panel.updated_at %>
+</p>
+<% if @sheet_panel.own? @author -%>
+  <%= link_to t('link.edit'), edit_sheet_panel_path(@sheet_panel) %>
+  <%= link_to t('link.destroy'), sheet_panel_path(@sheet_panel), :method => :delete %>
+<% end %>
+
+<hr>
+<%= render 'panels/standard', :panel => @sheet_panel.panel, :author => @author %>
diff --git a/app/views/sheets/_body.html.erb b/app/views/sheets/_body.html.erb
new file mode 100644 (file)
index 0000000..de9e841
--- /dev/null
@@ -0,0 +1,9 @@
+<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>
+  <% end %>
+</div>
diff --git a/app/views/sheets/_form.html.erb b/app/views/sheets/_form.html.erb
new file mode 100644 (file)
index 0000000..83c147f
--- /dev/null
@@ -0,0 +1,27 @@
+<%= form_for(@sheet) do |f| %>
+  <%= render 'system/error_explanation', :obj => @sheet %>
+
+  <div class="field">
+    <%= f.label :caption %><br />
+    <%= f.text_field :caption %>
+  </div>
+  <div class="field">
+    <%= f.label :width %><br />
+    <%= f.number_field :width %>
+  </div>
+  <div class="field">
+    <%= f.label :height %><br />
+    <%= f.number_field :height %>
+  </div>
+  <div class="field">
+    <%= f.label :visible %><br />
+    <%= f.collection_select :visible, t_select_items(MagicNumber['sheet_visible_items']), :last, :first, :html => {:selected => @sheet.visible} %>
+  </div>
+  <div class="field">
+    <%= f.label :author_id %><br />
+    <%= h @author.name %>
+  </div>
+  <div class="actions">
+    <%= f.submit %>
+  </div>
+<% end %>
diff --git a/app/views/sheets/_list_item.html.erb b/app/views/sheets/_list_item.html.erb
new file mode 100644 (file)
index 0000000..c7c9b2f
--- /dev/null
@@ -0,0 +1,20 @@
+<tr>
+  <td>
+    <%= link_to sheet_icon(:object => sheet, :size => 25), sheet_path(sheet) %>
+    <%= link_to h(truncate(sheet.caption, :length => 40)), play_sheet_path(sheet) %>
+    (<%= sheet.sheet_panels.size -%>)
+  </td>
+  <td>
+    <%= distance_of_time_in_words_to_now sheet.updated_at %>
+  </td>
+  <td>
+    <%= link_to author_icon(:object => sheet.author, :size => 25), author_path(sheet.author) %>
+    <%= link_to h(truncate(sheet.author.name, :length => 12)), author_path(sheet.author) %>
+  </td>
+  <td>
+    <% if sheet.own? author %>
+      <%= link_to t('link.edit'), edit_sheet_path(sheet) %>
+      <%= link_to t('link.destroy'), sheet_path(sheet), :method => :delete %>
+    <% end %>
+  </td>
+</tr>
diff --git a/app/views/sheets/_standard.html.erb b/app/views/sheets/_standard.html.erb
new file mode 100644 (file)
index 0000000..663de28
--- /dev/null
@@ -0,0 +1,9 @@
+<%= render 'sheets/body', :sheet_panels => sheet_panels, :sheet => sheet, :author => author %>
+<div class="sheet-data">
+  <% sheet_panels.each do |sheet_panel| %>
+    <%= render 'sheet_panels/play_footer', :sheet_panel => sheet_panel, :author => author %>
+  <% end %>
+  <%= render 'sheet_panels/licensed_pictures', :licensed_pictures => SheetPanel.licensed_pictures(sheet_panels) %>
+</div>
+<div class="sheet-break">
+</div>
diff --git a/app/views/sheets/browse.html.erb b/app/views/sheets/browse.html.erb
new file mode 100644 (file)
index 0000000..bd6dea1
--- /dev/null
@@ -0,0 +1,44 @@
+<h1><%= t '.title' -%></h1>
+<p>
+  <b><%= t_m 'Sheet.id' -%>:</b>
+  <%= h @sheet.id %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.caption' -%>:</b>
+  <%= h @sheet.caption %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.width' -%>:</b>
+  <%= h(@sheet.width) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.height' -%>:</b>
+  <%= h(@sheet.height) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.visible' -%>:</b>
+  <%= @sheet.visible %>
+  <%= t_selected_item('sheet_visible_items', @sheet.visible) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.author_id' -%>:</b>
+  <%= @sheet.author_id %>
+  <%= link_to h(@sheet.author.name), browse_author_path(@sheet.author) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.created_at' -%>:</b>
+  <%= l @sheet.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.updated_at' -%>:</b>
+  <%= l @sheet.updated_at %>
+</p>
+
+<%= link_to t('link.back'), :action => :list %>
diff --git a/app/views/sheets/edit.html.erb b/app/views/sheets/edit.html.erb
new file mode 100644 (file)
index 0000000..1d67f75
--- /dev/null
@@ -0,0 +1,4 @@
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<%= render 'form' %>
diff --git a/app/views/sheets/edit.js.erb b/app/views/sheets/edit.js.erb
new file mode 100644 (file)
index 0000000..61e9f00
--- /dev/null
@@ -0,0 +1 @@
+$("#newsheet").html("<%= escape_javascript(render('form')) -%>");
diff --git a/app/views/sheets/index.html.erb b/app/views/sheets/index.html.erb
new file mode 100644 (file)
index 0000000..327a355
--- /dev/null
@@ -0,0 +1,9 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <% @sheets.each do |sheet| %>
+    <%= render 'list_item', :sheet => sheet, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('sheets.new.title'), new_sheet_path %>
diff --git a/app/views/sheets/list.html.erb b/app/views/sheets/list.html.erb
new file mode 100644 (file)
index 0000000..550c5be
--- /dev/null
@@ -0,0 +1,28 @@
+<h1><%= t '.title' -%></h1>
+
+<table>
+  <tr>
+    <th><%= t_m 'Sheet.id' -%></th>
+    <th><%= t_m 'Sheet.caption' -%></th>
+    <th><%= t_m 'Sheet.width' -%></th>
+    <th><%= t_m 'Sheet.height' -%></th>
+    <th><%= t_m 'Sheet.visible' -%></th>
+    <th><%= t_m 'Sheet.author_id' -%></th>
+    <th><%= t_m 'Sheet.created_at' -%></th>
+    <th><%= t_m 'Sheet.updated_at' -%></th>
+  </tr>
+
+<% @sheets.each do |sheet| %>
+  <tr>
+    <td><%= link_to sheet.id, browse_sheet_path(sheet) %></td>
+    <td><%= h(truncate(sheet.caption, :length => 12)) %></td>
+    <td><%= sheet.width %></td>
+    <td><%= sheet.height %></td>
+    <td><%= sheet.visible %></td>
+    <td><%= link_to sheet.author_id, browse_author_path(sheet.author) %></td>
+    <td><%= l sheet.created_at %></td>
+    <td><%= l sheet.updated_at %></td>
+  </tr>
+<% end %>
+</table>
+
diff --git a/app/views/sheets/new.html.erb b/app/views/sheets/new.html.erb
new file mode 100644 (file)
index 0000000..39ae7be
--- /dev/null
@@ -0,0 +1,5 @@
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
+
+<%= link_to t('link.back'), sheets_path %>
diff --git a/app/views/sheets/new.js.erb b/app/views/sheets/new.js.erb
new file mode 100644 (file)
index 0000000..61e9f00
--- /dev/null
@@ -0,0 +1 @@
+$("#newsheet").html("<%= escape_javascript(render('form')) -%>");
diff --git a/app/views/sheets/play.html.erb b/app/views/sheets/play.html.erb
new file mode 100644 (file)
index 0000000..094ce8e
--- /dev/null
@@ -0,0 +1,17 @@
+<% @page_caption = @sheet.caption %>
+<p id="notice"><%= notice %></p>
+<%= render 'sheet_panels/play_header', :sheet => @sheet, :author => @author %>
+
+<% if @sheet_panels.empty? -%>
+  <h2><%= t('sheet_panels.sheet.empty') %></h2>
+<% else %>
+  <%= render 'sheets/standard', :sheet_panels => @sheet_panels, :sheet => @sheet, :author => @author %>
+<% end %>
+<% if @sheet.own? @author -%>
+  <h3><%= t('sheet_panels.append.new_panels') -%></h3>
+  <table>
+    <% @new_panels.each do |panel| %>
+      <%= render 'sheet_panels/append_panel', :sheet => @sheet, :panel => panel, :author => @author %>
+    <% end %>
+  </table>
+<% end %>
diff --git a/app/views/sheets/show.html.erb b/app/views/sheets/show.html.erb
new file mode 100644 (file)
index 0000000..92c7477
--- /dev/null
@@ -0,0 +1,48 @@
+<% @page_caption = t('.title') + ':' + @sheet.caption %>
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b><%= t_m 'Sheet.caption' -%>:</b>
+  <%= link_to h(@sheet.caption), play_sheet_path(@sheet) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.width' -%>:</b>
+  <%= h(@sheet.width) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.height' -%>:</b>
+  <%= h(@sheet.height) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.visible' -%>:</b>
+  <%= t_selected_item('sheet_visible_items', @sheet.visible) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.author_id' -%>:</b>
+  <%= link_to h(@sheet.author.name), author_path(@sheet.author) %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.created_at' -%>:</b>
+  <%= l @sheet.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'Sheet.updated_at' -%>:</b>
+  <%= l @sheet.updated_at %>
+</p>
+
+<%= link_to t('link.edit'), edit_sheet_path(@sheet) %>
+<% if @sheet.own? @author -%>
+  <h3><%= t('sheet_panels.append.new_panels') -%></h3>
+  <table>
+    <% @new_panels.each do |panel| %>
+      <%= render 'sheet_panels/append_panel', :sheet => @sheet, :panel => panel, :author => @author %>
+    <% end %>
+  </table>
+<% end %>
diff --git a/app/views/stories/_append_panel.html.erb b/app/views/stories/_append_panel.html.erb
deleted file mode 100644 (file)
index 241bcf8..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<tr>
-  <td>
-    <%= link_to panel_icon(:object => panel, :size => 25), panel_path(panel) %>
-    <%= link_to author_icon(:object => panel.author, :size => 17), author_path(panel.author) %>
-  </td>
-  <td>
-    <%= link_to h(truncate(h(panel.caption), :length => 40)), :controller => 'stories', :action => :comic, :id => comic.id %>
-  </td>
-  <td>
-    <%= l panel.updated_at %>
-  </td>
-  <td>
-    <% @story = Story.new :comic_id => comic.id, :panel_id => panel.id -%>
-    <%= form_for(@story) do |f| %>
-      <%= f.hidden_field :comic_id %>
-      <%= f.hidden_field :t %>
-      <%= f.hidden_field :panel_id %>
-      <%= f.submit t('stories.comic.append') %>
-    <% end %>
-  </td>
-</tr>
diff --git a/app/views/stories/_comic_header.html.erb b/app/views/stories/_comic_header.html.erb
deleted file mode 100644 (file)
index d1eb9e7..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<h1>
-  <%= link_to comic_icon, comic_path(comic) %>
-  <%= link_to h(comic.title), :controller => 'stories', :action => :comic, :id => comic.id %>
-</h1>
-<% if comic.own? author -%>
-  <%= form_for(comic) do |f| %>
-    <div class="field">
-      <%= f.label :title %><br />
-      <%= f.text_field :title %>
-    </div>
-    <div class="field">
-      <%= f.label :visible %><br />
-      <%= f.collection_select :visible, t_select_items(MagicNumber['comic_visible_items']), :last, :first, :html => {:selected => @comic.visible} %>
-    </div>
-    <div class="actions">
-      <%= f.submit %>
-    </div>
-  <% end %>
-<% else %>
-  <p>
-    <b><%= t_m 'Comic.visible' -%>:</b>
-    <%= t_selected_item('comic_visible_items', @comic.visible) %>
-  </p>
-<% end %>
-
-<p>
-  <b><%= t_m 'Comic.author_id' -%>:</b>
-  <%= link_to h(@comic.author.name), author_path(@comic.author) %>
-</p>
-
-<p>
-  <b><%= t_m 'Comic.created_at' -%>:</b>
-  <%= l @comic.created_at %>
-</p>
-
-<p>
-  <b><%= t_m 'Comic.updated_at' -%>:</b>
-  <%= l @comic.updated_at %>
-</p>
-
diff --git a/app/views/stories/_footer.html.erb b/app/views/stories/_footer.html.erb
deleted file mode 100644 (file)
index 56e9367..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<table class="no-border" style="margin: 0px; padding: 0px; width=100%">
-  <tr>
-    <td>
-      <% if story.panel -%>
-        <%= link_to panel_icon(:object => story.panel, :size => 25), panel_path(story.panel) %>
-        <%= link_to author_icon(:object => story.panel.author, :size => 17), author_path(story.panel.author) %>
-        <%= distance_of_time_in_words_to_now story.panel.updated_at %>
-      <% end %>
-    </td>
-    <td>
-      <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
-      <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %>
-      <%= l story.updated_at %>
-    </td>
-    <td>
-      <% if story.own? author %>
-        <%= render 'order', :story => story %>
-      <% else %>
-        No.<%= story.t %>
-      <% end %>
-    </td>
-  </tr>
-</table>
index 8d705f5..4355267 100644 (file)
@@ -6,12 +6,24 @@
     <%= f.number_field :comic_id %>
   </div>
   <div class="field">
-    <%= f.label :t %><br />
-    <%= f.number_field :t %>
+    <%= f.label :title %><br />
+    <%= f.text_field :title %>
+  </div>
+  <div class="field">
+    <%= f.label :description %><br />
+    <%= f.text_area :description %>
+  </div>
+  <div class="field">
+    <%= f.label :visible %><br />
+    <%= f.collection_select :visible, t_select_items(MagicNumber['story_visible_items']), :last, :first, :html => {:selected => @story.visible} %>
+  </div>
+  <div class="field">
+    <%= f.label :author_id %><br />
+    <%= h @author.name %>
   </div>
   <div class="field">
-    <%= f.label :panel_id %><br />
-    <%= f.number_field :panel_id %>
+    <%= f.label :t %><br />
+    <%= f.number_field :t %>
   </div>
 
   <div class="actions">
index 1b18f0f..ffc557c 100644 (file)
@@ -3,7 +3,7 @@
       <%= link_to comic_icon(:object => story.comic, :size => 25), comic_path(story.comic) %>
     </td>
     <td>
-      <%= link_to h(story.comic.title), :controller => 'stories', :action => :comic, :id => story.comic.id %>
+      <%= link_to h(story.comic.title), comic_path(story.comic) %>
     </td>
     <td>
       <%= link_to author_icon(:object => story.comic.author, :size => 17), author_path(story.comic.author) %>
@@ -12,6 +12,9 @@
       <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
     </td>
     <td>
+      <%= 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>
@@ -20,9 +23,4 @@
     <td>
       <%= l story.updated_at %>
     </td>
-    <td>
-      <% if story.panel %>
-        <%= h story.panel.caption %>
-      <% end %>
-    </td>
   </tr>
index e0ceadf..71ae6ed 100644 (file)
@@ -1,15 +1,6 @@
 <%= form_for(story) do |f| %>
-  <table class="no-border">
-    <tr>
-      <td>
         No.
         <%= f.number_field :t, :size => 3 %>
-        <%= f.hidden_field :panel_id %>
         <%= f.hidden_field :comic_id %>
-      </td>
-      <td>
         <%= f.submit t 'stories.move' %>
-      </td>
-    </tr>
-  </table>
 <% end %>
diff --git a/app/views/stories/_play_footer.html.erb b/app/views/stories/_play_footer.html.erb
new file mode 100644 (file)
index 0000000..f68d13d
--- /dev/null
@@ -0,0 +1,24 @@
+<div>
+  <table class="no-border">
+    <tr>
+      <td>
+        <%= 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| %>
+            No.
+            <%= f.number_field :t, :size => 3 %>
+            <%= f.hidden_field :comic_id %>
+            <%= f.submit t 'stories.move' %>
+          <% end %>
+        </td>
+      <% end %>
+    </tr>
+  </table>
+</div>
index 24a7a6c..c9a07a2 100644 (file)
@@ -6,8 +6,18 @@
 </p>
 
 <p>
-  <b>panel_id:</b>
-  <%= @story.panel_id %>
+  <b>title</b>
+  <%= link_to h(@story.title), story_path(@story) %>
+</p>
+
+<p>
+  <b>description</b>
+  <%= h(@story.description) %>
+</p>
+
+<p>
+  <b>visible</b>
+  <%= @story.visible %>
 </p>
 
 <p>
diff --git a/app/views/stories/comic.html.erb b/app/views/stories/comic.html.erb
deleted file mode 100644 (file)
index 631f6f0..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<% @page_title = @comic.title %>
-<h1><%= t '.title' -%></h1>
-<p id="notice"><%= notice %></p>
-<%= render 'comic_header', :comic => @comic, :author => @author %>
-
-<% if @stories.empty? -%>
-  <h2><%= t('stories.comic.empty') %></h2>
-<% else %>
-  <% @stories.each do |story| %>
-    <% if story.panel -%>
-      <%= render 'panels/body', :panel => story.panel, :author => @author, :spot => nil %>
-    <% end %>
-    <%= render 'footer', :story => story, :author => @author %>
-  <% end %>
-  <%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %>
-
-  <% if @prev_offset -%>
-    <%= link_to h('<<prev'), comic_story_path(@comic, {:offset => @prev_offset, :count => @panel_count}) %>
-  <% end %>
-
-  <% if @next_offset -%>
-    <%= link_to h('next>>'), comic_story_path(@comic, {:offset => @next_offset, :count => @panel_count}) %>
-  <% end %>
-
-<% end %>
-<% if @comic.own? @author -%>
-  <h3><%= t('stories.comic.new_panels') -%></h3>
-  <table>
-    <% @new_panels.each do |panel| %>
-      <%= render 'append_panel', :comic => @comic, :panel => panel, :author => @author %>
-    <% end %>
-  </table>
-<% end %>
index cee9463..0ee86fd 100644 (file)
@@ -2,4 +2,4 @@
 <p id="notice"><%= notice %></p>
 
 <%= render 'form' %>
-<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
+<%= button_to 'Destroy', @story, confirm: 'Are you sure?', method: :delete %>
index 6fae81c..99d5442 100644 (file)
@@ -4,7 +4,7 @@
   <tr>
     <th>id</th>
     <th>comic_id</th>
-    <th>panel_id</th>
+    <th>title</th>
     <th>t</th>
     <th>author_id</th>
     <th>created_at</th>
@@ -16,7 +16,7 @@
   <tr>
     <td><%= link_to story.id, :action => :browse, :id => story.id %></td>
     <td><%= story.comic_id %></td>
-    <td><%= story.panel_id %></td>
+    <td><%= h(truncate(h(story.title), :length => 10)) %></td>
     <td><%= story.t %></td>
     <td><%= link_to story.author_id, :controller => '/authors', :action => :browse, :id => story.author_id %></td>
     <td><%= story.created_at %></td>
diff --git a/app/views/stories/play.html.erb b/app/views/stories/play.html.erb
new file mode 100644 (file)
index 0000000..529d191
--- /dev/null
@@ -0,0 +1,25 @@
+<% @page_caption = @story.title %>
+<p id="notice"><%= notice %></p>
+<%= render 'story_sheets/play_header', :story => @story, :author => @author %>
+
+<% if @sheet -%>
+  <%= paginate(@paginate) %>
+  <% @sheet_panels = SheetPanel.play_list(@sheet, @author) -%>
+  <%= render 'sheets/standard', :sheet_panels => @sheet_panels, :sheet => @sheet, :author => @author %>
+  <%= paginate(@paginate) %>
+
+  <%= render 'story_sheets/play_footer', :story => @story, :sheet => @sheet, :author => @author %>
+
+<% else %>
+  <h2><%= t('stories.play.empty') %></h2>
+<% end %>
+<%= render 'stories/play_footer', :story => @story, :sheet => @sheet, :author => @author %>
+
+<% if @story.own? @author -%>
+  <h3><%= t('story_sheets.append.new_sheets') -%></h3>
+  <table>
+    <% @new_sheets.each do |sheet| %>
+      <%= render 'story_sheets/append_sheet', :story => @story, :sheet => sheet, :author => @author %>
+    <% end %>
+  </table>
+<% end %>
index fa0c3a0..73b5cb3 100644 (file)
@@ -4,17 +4,22 @@
 <p>
   <b><%= t_m 'Story.comic_id' -%>:</b>
   <%= link_to comic_icon(:object => @story.comic), comic_path(@story.comic) %>
-  <%= link_to h(@story.comic.title), :controller => 'stories', :action => :comic, :id => @story.comic.id %>
+  <%= link_to h(@story.comic.title), comic_path(@story.comic) %>
 </p>
 
+<div>
+  <%= link_to t('stories.show.t', :t => @story.disp_t), story_path(@story) %>
+  <%= link_to_if @story, h(@story.title), play_story_path(@story) %>
+</div>
+
 <p>
-  <b><%= t_m 'Story.panel_id' -%>:</b>
-  <%= link_to panel_icon(:object => @story.panel), panel_path(@story.panel) %>
+  <b><%= t_m 'Story.description' -%>:</b>
+  <%= h(@story.description) %>
 </p>
 
 <p>
-  <b><%= t_m 'Story.t' -%>:</b>
-  <%= @story.t %>
+  <b><%= t_m 'Story.visible' -%>:</b>
+  <%= t_selected_item('story_visible_items', @story.visible) %>
 </p>
 
 <p>
 <% if @story.own? @author -%>
   <%= link_to t('link.edit'), edit_story_path(@story) %>
   <%= link_to t('link.destroy'), story_path(@story), :method => :delete %>
-<% end %>
 
-<hr>
-<%= render 'panels/standard', :panel => @story.panel, :author => @author %>
+  <h3><%= t('story_sheets.append.new_sheets') -%></h3>
+  <table>
+    <% @new_sheets.each do |sheet| %>
+      <%= render 'story_sheets/append_sheet', :story => @story, :sheet => sheet, :author => @author %>
+    <% end %>
+  </table>
+<% end %>
diff --git a/app/views/story_sheets/_append_sheet.html.erb b/app/views/story_sheets/_append_sheet.html.erb
new file mode 100644 (file)
index 0000000..b775392
--- /dev/null
@@ -0,0 +1,23 @@
+<tr>
+  <td>
+    <%= link_to sheet_icon(:object => sheet, :size => 25), sheet_path(sheet) %>
+    <%= link_to author_icon(:object => sheet.author, :size => 17), author_path(sheet.author) %>
+  </td>
+  <td>
+    <%= link_to h(truncate(h(sheet.caption), :length => 40)), sheet_path(sheet) %>
+  </td>
+  <td>
+    <%= l sheet.updated_at %>
+  </td>
+  <td>
+    <% @story_sheet = StorySheet.new :story_id => story.id, :sheet_id => sheet.id -%>
+    <% @story_sheet.supply_default -%>
+    <% @story_sheet.attributes = {:story_id => story.id, :sheet_id => sheet.id} -%>
+    <%= form_for(@story_sheet) do |f| %>
+      <%= f.hidden_field :story_id %>
+      <%= f.hidden_field :t %>
+      <%= f.hidden_field :sheet_id %>
+      <%= f.submit t('story_sheets.append.sheet') %>
+    <% end %>
+  </td>
+</tr>
diff --git a/app/views/story_sheets/_append_story.html.erb b/app/views/story_sheets/_append_story.html.erb
new file mode 100644 (file)
index 0000000..317f648
--- /dev/null
@@ -0,0 +1,27 @@
+<tr>
+  <td>
+    <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
+    <%= link_to h(truncate(story.title, :length => 40)), play_story_path(story) %>
+    (<%= story.story_sheets.size -%>)
+  </td>
+  <td>
+    <%= distance_of_time_in_words_to_now story.updated_at %>
+  </td>
+  <td>
+    <%= link_to author_icon(:object => story.author, :size => 25), story_path(story.author) %>
+    <%= link_to h(truncate(story.author.name, :length => 12)), author_path(story.author) %>
+  </td>
+  <td>
+    <% if story.own? author %>
+      <% @story_sheet = StorySheet.new :story_id => story.id, :sheet_id => sheet.id %>
+      <%= form_for(@story_sheet) do |f| %>
+        <%= f.hidden_field :story_id %>
+        <%= f.hidden_field :t %>
+        <%= f.hidden_field :sheet_id %>
+        <div class="actions">
+          <%= f.submit t('story_sheets.append.story') %>
+        </div>
+      <% end %>
+    <% end %>
+  </td>
+</tr>
diff --git a/app/views/story_sheets/_form.html.erb b/app/views/story_sheets/_form.html.erb
new file mode 100644 (file)
index 0000000..601a0f9
--- /dev/null
@@ -0,0 +1,20 @@
+<%= form_for(@story_sheet) do |f| %>
+  <%= render 'system/error_explanation', :obj => @story_sheet %>
+
+  <div class="field">
+    <%= f.label :story_id %><br />
+    <%= f.number_field :story_id %>
+  </div>
+  <div class="field">
+    <%= f.label :sheet_id %><br />
+    <%= f.number_field :sheet_id %>
+  </div>
+  <div class="field">
+    <%= f.label :t %><br />
+    <%= f.number_field :t %>
+  </div>
+
+  <div class="actions">
+    <%= f.submit %>
+  </div>
+<% end %>
diff --git a/app/views/story_sheets/_list_item.html.erb b/app/views/story_sheets/_list_item.html.erb
new file mode 100644 (file)
index 0000000..81597b1
--- /dev/null
@@ -0,0 +1,28 @@
+  <tr>
+    <td>
+      <%= link_to story_icon(:object => story_sheet.story, :size => 25), story_path(story_sheet.story) %>
+    </td>
+    <td>
+      <%= 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>
+      <%= link_to author_icon(:object => story_sheet.author, :size => 17), author_path(story_sheet.author) %>
+    </td>
+    <td>
+      No.<%= story_sheet.t %>
+    </td>
+    <td>
+      <%= l story_sheet.updated_at %>
+    </td>
+    <td>
+      <% if story_sheet.sheet %>
+        <%= h story_sheet.sheet.caption %>
+      <% end %>
+    </td>
+  </tr>
diff --git a/app/views/story_sheets/_order.html.erb b/app/views/story_sheets/_order.html.erb
new file mode 100644 (file)
index 0000000..ace4b13
--- /dev/null
@@ -0,0 +1,15 @@
+<%= form_for(sheet_panel) do |f| %>
+  <table class="no-border">
+    <tr>
+      <td>
+        No.
+        <%= f.number_field :t, :size => 3 %>
+        <%= f.hidden_field :panel_id %>
+        <%= f.hidden_field :sheet_id %>
+      </td>
+      <td>
+        <%= f.submit t 'sheet_panels.move' %>
+      </td>
+    </tr>
+  </table>
+<% end %>
diff --git a/app/views/story_sheets/_play_footer.html.erb b/app/views/story_sheets/_play_footer.html.erb
new file mode 100644 (file)
index 0000000..482cbc1
--- /dev/null
@@ -0,0 +1,9 @@
+<div>
+  <% if sheet -%>
+    <%= link_to sheet_icon(:object => sheet, :size => 25), sheet_path(sheet) %>
+    <%= link_to h(truncate(sheet.caption, :length => 40)), play_sheet_path(sheet) %>
+
+    <%= link_to author_icon(:object => sheet.author, :size => 25), author_path(sheet.author) %>
+    <%= link_to h(truncate(sheet.author.name, :length => 12)), author_path(sheet.author) %>
+  <% end %>
+</div>
diff --git a/app/views/story_sheets/_play_header.html.erb b/app/views/story_sheets/_play_header.html.erb
new file mode 100644 (file)
index 0000000..9276d65
--- /dev/null
@@ -0,0 +1,16 @@
+<div width="100%">
+<table class="no-border">
+  <tr>
+    <td width="50%">
+      <%= link_to t('stories.show.t', :t => story.disp_t), story_path(story) %>
+      <%= link_to_if story, h(story.title), play_story_path(story) %>
+    </td>
+    <td width="50%">
+      <%= link_to comic_icon(:object => story.comic, :size => 25), comic_path(story.comic) %>
+      <%= link_to h(truncate(story.comic.title, :length => 40)), comic_path(story.comic) %>
+    </td>
+  </td>
+  </tr>
+</table>
+</div>
+
diff --git a/app/views/story_sheets/browse.html.erb b/app/views/story_sheets/browse.html.erb
new file mode 100644 (file)
index 0000000..6772579
--- /dev/null
@@ -0,0 +1,28 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b>sheet_id:</b>
+  <%= @sheet_panel.sheet_id %>
+</p>
+
+<p>
+  <b>panel_id:</b>
+  <%= @sheet_panel.panel_id %>
+</p>
+
+<p>
+  <b>t:</b>
+  <%= @sheet_panel.t %>
+</p>
+
+<p>
+  <b>author_id:</b>
+  <%= @sheet_panel.author_id %>
+</p>
+
+<p>
+  <b>updated_at:</b>
+  <%= @sheet_panel.updated_at %>
+</p>
+
+<%= link_to 'Back', :action => :list %>
diff --git a/app/views/story_sheets/edit.html.erb b/app/views/story_sheets/edit.html.erb
new file mode 100644 (file)
index 0000000..7e45d59
--- /dev/null
@@ -0,0 +1,5 @@
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<%= render 'form' %>
+<%= button_to 'Destroy', @story_sheet, confirm: 'Are you sure?', method: :delete %>
diff --git a/app/views/story_sheets/edit.js.erb b/app/views/story_sheets/edit.js.erb
new file mode 100644 (file)
index 0000000..d7bfe9f
--- /dev/null
@@ -0,0 +1 @@
+$("#sheet_panel-update-<%= @sheet_panel.id -%>").html("<%= escape_javascript(render('editform')) -%>");
diff --git a/app/views/story_sheets/index.html.erb b/app/views/story_sheets/index.html.erb
new file mode 100644 (file)
index 0000000..23065cd
--- /dev/null
@@ -0,0 +1,8 @@
+<h1><%= t '.title' -%></h1>
+<table>
+  <% @story_sheets.each do |story_sheet| %>
+    <%= render 'list_item', :story_sheet => story_sheet, :author => @author %>
+  <% end %>
+</table>
+<%= paginate(@paginate) %>
+<%= link_to t('story_sheets.new.title'), new_story_sheet_path %>
diff --git a/app/views/story_sheets/list.html.erb b/app/views/story_sheets/list.html.erb
new file mode 100644 (file)
index 0000000..7790abc
--- /dev/null
@@ -0,0 +1,29 @@
+<h1>Listing SheetPanel</h1>
+
+<table>
+  <tr>
+    <th>id</th>
+    <th>sheet_id</th>
+    <th>panel_id</th>
+    <th>t</th>
+    <th>author_id</th>
+    <th>created_at</th>
+    <th>updated_at</th>
+    <th></th>
+  </tr>
+
+<%  @sheet_panels.each do |sheet_panel| %>
+  <tr>
+    <td><%= link_to sheet_panel.id, :action => :browse, :id => sheet_panel.id %></td>
+    <td><%= sheet_panel.sheet_id %></td>
+    <td><%= sheet_panel.panel_id %></td>
+    <td><%= sheet_panel.t %></td>
+    <td><%= link_to sheet_panel.author_id, :controller => '/authors', :action => :browse, :id => sheet_panel.author_id %></td>
+    <td><%= sheet_panel.created_at %></td>
+    <td><%= sheet_panel.updated_at %></td>
+    <td>
+    </td>
+  </tr>
+<% end %>
+</table>
+
diff --git a/app/views/story_sheets/new.html.erb b/app/views/story_sheets/new.html.erb
new file mode 100644 (file)
index 0000000..f33a2f8
--- /dev/null
@@ -0,0 +1,3 @@
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
diff --git a/app/views/story_sheets/show.html.erb b/app/views/story_sheets/show.html.erb
new file mode 100644 (file)
index 0000000..c21cf12
--- /dev/null
@@ -0,0 +1,39 @@
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<p>
+  <b><%= t_m 'StorySheet.story_id' -%>:</b>
+  <%= link_to story_icon(:object => @story_sheet.story), story_path(@story_sheet.story) %>
+  <%= link_to h(@story_sheet.story.title), play_story_path(@story_sheet.story) %>
+</p>
+
+<p>
+  <b><%= t_m 'StorySheet.sheet_id' -%>:</b>
+  <%= link_to sheet_icon(:object => @story_sheet.sheet), sheet_path(@story_sheet.sheet) %>
+</p>
+
+<p>
+  <b><%= t_m 'StorySheet.t' -%>:</b>
+  <%= @story_sheet.t %>
+</p>
+
+<p>
+  <b><%= t_m 'StorySheet.author_id' -%>:</b>
+  <%= link_to author_icon(:object => @story_sheet.author), author_path(@story_sheet.author) %>
+  <%= link_to h(@story_sheet.author.name), author_path(@story_sheet.author) %>
+</p>
+
+<p>
+  <b><%= t_m 'StorySheet.created_at' -%>:</b>
+  <%= l @story_sheet.created_at %>
+</p>
+
+<p>
+  <b><%= t_m 'StorySheet.updated_at' -%>:</b>
+  <%= l @story_sheet.updated_at %>
+</p>
+<% if @story_sheet.own? @author -%>
+  <%= link_to t('link.edit'), edit_story_sheet_path(@story_sheet) %>
+  <%= link_to t('link.destroy'), story_sheet_path(@story_sheet), :method => :delete %>
+<% end %>
+
index 2d9add6..214e407 100644 (file)
       <%= link_to t_m('ScrollPanel'), main_app.scroll_panels_path %>\r
     </td>\r
     <td width="200px" align="center" valign="middle">\r
+      <%= link_to t_m('Comic'), main_app.comics_path %>\r
+    </td>\r
+    <td width="200px" align="center" valign="middle">\r
+      <%= link_to t_m('Story'), main_app.stories_path %>\r
+    </td>\r
+  </tr>\r
+  <tr height="100px">\r
+    <td width="200px" align="center" valign="middle">\r
+      <%= link_to t_m('StorySheet'), main_app.story_sheets_path %>\r
+    </td>\r
+    <td width="200px" align="center" valign="middle">\r
+      <%= link_to t_m('Sheet'), main_app.sheets_path %>\r
+    </td>\r
+    <td width="200px" align="center" valign="middle">\r
+      <%= link_to t_m('SheetPanel'), main_app.sheet_panels_path %>\r
+    </td>\r
+    <td width="200px" align="center" valign="middle">\r
+    </td>\r
+  </tr>\r
+  <tr height="100px">\r
+    <td width="200px" align="center" valign="middle">\r
       <%= link_to t_m('Panel'), main_app.panels_path %>\r
     </td>\r
     <td width="200px" align="center" valign="middle">\r
       <%= link_to t_m('ResourcePicture'), main_app.resource_pictures_path %>\r
     </td>\r
+    <td width="200px" align="center" valign="middle">\r
+    </td>\r
+    <td width="200px" align="center" valign="middle">\r
+    </td>\r
   </tr>\r
   <tr height="100px">\r
     <td width="200px" align="center" valign="middle">\r
index ad5340d..3eb8d47 100644 (file)
@@ -18,8 +18,13 @@ ja:
       user: ユーザ
       admin: 管理者
       demand_user: 借手
-      scroll: コミック
-      scroll_panel: ストーリー
+      scroll: スクロール
+      scroll_panel: スクコマ
+      comic: コミック
+      story: ストーリー
+      story_sheet: スト紙
+      sheet: 用紙
+      sheet_panel: 紙コマ
       panel: コマ
       panel_picture: コマ絵
       speech_balloon: フキダシ
@@ -75,12 +80,53 @@ ja:
         created_at: 更新
         updated_at: 作成
       scroll_panel:
-        scroll_id: ã\82³ã\83\9fã\83\83ã\82¯
+        scroll_id: ã\82¹ã\82¯ã\83­ã\83¼ã\83«
         panel_id: コマ
         author_id: 編集者
         t: No.
         created_at: 作成
         updated_at: 更新
+      comic:
+        title: タイトル
+        description: あらすじ
+        visible: 公開
+        author_id: 作家
+        created_at: 更新
+        updated_at: 作成
+      story:
+        comic_id: コミック
+        title: タイトル
+        description: あらすじ
+        visible: 公開
+        author_id: 作家
+        t: No.
+        created_at: 更新
+        updated_at: 作成
+      story_sheet:
+        story_id: ストーリー
+        sheet_id: 用紙
+        author_id: 編集者
+        t: No.
+        created_at: 作成
+        updated_at: 更新
+      sheet:
+        caption: 要約
+        width: 幅
+        height: 高さ
+        visible: 公開
+        author_id: 編集者
+        created_at: 更新
+        updated_at: 作成
+      sheet_panel:
+        sheet_id: 用紙
+        panel_id: コマ
+        x: X
+        y: Y
+        z: 重なり
+        t: No.
+        author_id: 編集者
+        created_at: 作成
+        updated_at: 更新
       panel:
         width: 幅
         height: 高さ
@@ -318,6 +364,18 @@ ja:
       visible:
         private: 非公開
         public: 公開
+    comic:
+      visible:
+        private: 非公開
+        public: 公開
+    story:
+      visible:
+        private: 非公開
+        public: 公開
+    sheet:
+      visible:
+        private: 非公開
+        public: 公開
     panel:
       visible:
         private: 非公開
@@ -412,9 +470,19 @@ ja:
       artist: 絵師
       not_artist: 画像を公開するには絵師登録
     scrolls:
-      title: æ\9c\80è¿\91æ\9b´æ\96°ã\81\97ã\81\9fã\82³ã\83\9fã\83\83ã\82¯
+      title: æ\9c\80è¿\91æ\9b´æ\96°ã\81\97ã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«
     scroll_panels:
+      title: 最近更新したスクコマ
+    comics:
+      title: 最近更新したコミック
+    stories:
       title: 最近更新したストーリー
+    story_sheets:
+      title: 最近更新したスト紙
+    sheets:
+      title: 最近更新した用紙
+    sheet_panels:
+      title: 最近更新した紙コマ
     panels:
       title: 最近更新したコマ
     resource_pictures:
@@ -460,6 +528,55 @@ ja:
     return: シンプル版に戻る
   scrolls:
     index:
+      title: スクロール一覧
+      new: 新刊
+    show:
+      title: スクロール詳細
+    play:
+      title: スクロールを読む
+      empty: スクコマはありません
+    new:
+      title: 新刊作成
+    edit:
+      title: スクロール変更
+    create:
+      title: 新刊作成
+    update:
+      title: スクロール変更
+    destroy:
+      title: スクロール削除
+    list:
+      title: スクロール 生一覧
+    browse:
+      title: スクロール 生単票
+  scroll_panels:
+    index:
+      title: スクコマ一覧
+    show:
+      title: スクコマ詳細
+    new:
+      title: スクコマ追加
+    edit:
+      title: 並び替え
+    create:
+      title: スクコマ追加
+    update:
+      title: 並び替え
+    destroy:
+      title: スクコマ削除
+    list:
+      title: スクコマ 生一覧
+    browse:
+      title: スクコマ 生単票
+    move: 移動
+    append:
+      panel: このコマを追加する
+      scroll: このスクロールに追加する
+      new_panels: 最近作成したコマ
+      new_scrolls: 最近作成したスクロール
+      fresh_scrolls: 最近更新したスクロール
+  comics:
+    index:
       title: コミック一覧
       new: 新刊
     show:
@@ -478,39 +595,111 @@ ja:
       title: コミック 生一覧
     browse:
       title: コミック 生単票
-  scroll_panels:
+  stories:
     index:
       title: ストーリー一覧
+      new: 新ストーリー
     show:
       title: ストーリー詳細
+      t: 第%{t}話
+    play:
+      title: ストーリーを読む
+      empty: 用紙はありません
     new:
-      title: ストーリー追加
+      title: 新ストーリー作成
     edit:
-      title: 並び替え
+      title: ストーリー変更
     create:
-      title: ストーリー追加
+      title: 新ストーリー作成
     update:
-      title: 並び替え
+      title: ストーリー変更
     destroy:
       title: ストーリー削除
-    scroll:
-      title: コミックを読む
-      empty: ストーリーはありません
-      append: このコマを追加する
-      new_panels: 最近作成したコマ
     list:
       title: ストーリー 生一覧
     browse:
       title: ストーリー 生単票
     move: 移動
+  story_sheets:
+    index:
+      title: スト紙一覧
+    show:
+      title: スト紙詳細
+    new:
+      title: スト紙追加
+    edit:
+      title: 並び替え
+    create:
+      title: スト紙追加
+    update:
+      title: 並び替え
+    destroy:
+      title: スト紙削除
+    list:
+      title: スト紙 生一覧
+    browse:
+      title: スト紙 生単票
+    move: 移動
+    append:
+      sheet: この用紙を追加する
+      story: このストーリーに追加する
+      new_sheets: 最近作成した用紙
+      new_stories: 最近作成したストーリー
+      fresh_stories: 最近更新したストーリー
+  sheets:
+    index:
+      title: 用紙一覧
+      new: 新紙
+    show:
+      title: 用紙詳細
+    play:
+      title: 用紙を読む
+      empty: 紙コマはありません
+    new:
+      title: 用紙作成
+    edit:
+      title: 用紙変更
+    create:
+      title: 用紙作成
+    update:
+      title: 用紙変更
+    destroy:
+      title: 用紙削除
+    list:
+      title: 用紙 生一覧
+    browse:
+      title: 用紙 生単票
+  sheet_panels:
+    index:
+      title: 紙コマ一覧
+    show:
+      title: 紙コマ詳細
+    new:
+      title: 紙コマ追加
+    edit:
+      title: 並び替え
+    create:
+      title: 紙コマ追加
+    update:
+      title: 並び替え
+    destroy:
+      title: 紙コマ削除
+    list:
+      title: 紙コマ 生一覧
+    browse:
+      title: 紙コマ 生単票
+    move: 移動
+    append:
+      panel: このコマを追加する
+      sheet: この用紙に追加する
+      new_panels: 最近作成したコマ
+      new_sheets: 最近作成した用紙
+      fresh_sheets: 最近更新した用紙
   panels:
     index:
       title: コマ一覧
     show:
       title: コマ詳細
-      append: このコミックに追加する
-      new_scrolls: 最近作成したコミック
-      fresh_scrolls: 最近更新したコミック
       copy: コマをコピーしたい
       inspire: インスパイヤ
     new:
@@ -755,17 +944,32 @@ ja:
       title: 作家一覧
     show:
       title: 作家詳細
-      to_scrolls: 最近更新したコミック
-      to_scroll_panels: 最近更新したストーリー
+      to_scrolls: 最近更新したスクロール
+      to_scroll_panels: 最近更新したスクコマ
+      to_comics: 最近更新したコミック
+      to_stories: 最近更新したストーリー
+      to_story_sheets: 最近更新したスト紙
+      to_sheets: 最近更新した用紙
+      to_sheet_panels: 最近更新した紙コマ
       to_panels: 最近更新したコマ
       to_panel_pictures: 最近コマで使ったコマ絵
       to_speech_balloons: 最近更新したフキダシ
       to_ground_pictures: 最近コマで使った絵地
       to_ground_colors: 最近コマで使った色地
     scrolls:
-      title: æ\9c\80è¿\91æ\9b´æ\96°ã\81\97ã\81\9fã\82³ã\83\9fã\83\83ã\82¯
+      title: æ\9c\80è¿\91æ\9b´æ\96°ã\81\97ã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«
     scroll_panels:
+      title: 最近更新したスクコマ
+    comics:
+      title: 最近更新したコミック
+    stories:
       title: 最近更新したストーリー
+    story_sheets:
+      title: 最近更新したスト紙
+    sheets:
+      title: 最近更新した用紙
+    sheet_panels:
+      title: 最近更新した紙コマ
     panels:
       title: 最近更新したコマ
     panel_pictures:
@@ -992,7 +1196,10 @@ ja:
   tab:
     creator:
       home: 作る・見せる
-      scroll: コミック
+      comic: コミック
+      story: ストーリー
+      sheet: 用紙
+      scroll: スクロール
       panel: コマ
       original_picture: 原画
       resource_picture: 素材
index a061991..2e9f9c2 100644 (file)
     ['select_items.scroll.visible.private', 0], 
     ['select_items.scroll.visible.public', 1]
   ]
+  comic_visible_items: [
+    ['select_items.comic.visible.private', 0], 
+    ['select_items.comic.visible.public', 1]
+  ]
+  story_visible_items: [
+    ['select_items.story.visible.private', 0], 
+    ['select_items.story.visible.public', 1]
+  ]
+  sheet_visible_items: [
+    ['select_items.sheet.visible.private', 0], 
+    ['select_items.sheet.visible.public', 1]
+  ]
   panel_visible_items: [
     ['select_items.panel.visible.private', 0], 
     ['select_items.panel.visible.public', 1]
index 48f61d0..0730724 100644 (file)
@@ -29,6 +29,11 @@ Pettanr::Application.routes.draw do
       get :browse
       get :scrolls
       get :scroll_panels
+      get :comics
+      get :stories
+      get :story_sheets
+      get :sheets
+      get :sheet_panels
       get :panels
       get :panel_pictures
       get :speech_balloons
@@ -85,6 +90,24 @@ Pettanr::Application.routes.draw do
       get :list
     end
     member do
+      get :play
+      get :edit
+      put :update
+      delete :destroy
+      get :browse
+    end
+  end
+  resources :story_sheets do
+    new do
+      get :new
+    end
+    collection do
+      get :index
+      get :show
+      post :create
+      get :list
+    end
+    member do
       get :edit
       put :update
       delete :destroy
@@ -103,6 +126,7 @@ Pettanr::Application.routes.draw do
       get :list
     end
     member do
+      get :play
       get :edit
       put :update
       delete :destroy
index 29773ca..8908447 100644 (file)
@@ -510,6 +510,271 @@ 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
+      @sheet = FactoryGirl.create :sheet, :author_id => @other_user.author.id
+      Author.stub(:show).and_return(@other_author)
+      Sheet.stub(:himlist).and_return([@sheet, @sheet, @sheet])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :sheets, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :sheets, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :sheets, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :sheets, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_sheet_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :sheets, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.sheet_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :sheets, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_sheet_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :sheets, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :sheets, :id => @other_author.id
+      end
+      it '用紙モデルに一覧を問い合わせている' do
+        Sheet.should_receive(:himlist).exactly(1)
+        get :sheets, :id => @other_author.id
+      end
+      it '@sheetsにリストを取得している' do
+        get :sheets, :id => @other_author.id
+        assigns(:sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :sheets, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'sheetsテンプレートを描画する' do
+          get :sheets, :id => @other_author.id
+          response.should render_template("sheets")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :sheets, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '用紙モデルにjson一覧出力オプションを問い合わせている' do
+          Sheet.should_receive(:list_json_opt).exactly(1)
+          get :sheets, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :sheets, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは用紙っぽいものであって欲しい' do
+          get :sheets, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("caption").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 :sheets, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :sheets, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :sheets, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :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 :sheets, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :sheets, :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
+      @sheet = FactoryGirl.create :sheet, :author_id => @other_user.author.id
+      @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @other_user.author.id
+      Author.stub(:show).and_return(@other_author)
+      SheetPanel.stub(:himlist).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
+      sign_in @user
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :sheet_panels, :id => @other_author.id, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :sheet_panels, :id => @other_author.id
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :sheet_panels, :id => @other_author.id, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :sheet_panels, :id => @other_author.id
+        assigns(:page_size).should eq Author.default_sheet_panel_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :sheet_panels, :id => @other_author.id, :page_size => 1500
+        assigns(:page_size).should eq Author.sheet_panel_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :sheet_panels, :id => @other_author.id, :page_size => 0
+        assigns(:page_size).should eq Author.default_sheet_panel_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :sheet_panels, :id => @other_author.id
+        response.should be_success 
+      end
+      it '作家モデルに単体取得を問い合わせている' do
+        Author.should_receive(:show).exactly(1)
+        get :sheet_panels, :id => @other_author.id
+      end
+      it '紙コマモデルに他作家の紙コマ一覧を問い合わせている' do
+        SheetPanel.should_receive(:himlist).exactly(1)
+        get :sheet_panels, :id => @other_author.id
+      end
+      it '@sheet_panelsにリストを取得している' do
+        get :sheet_panels, :id => @other_author.id
+        assigns(:sheet_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :sheet_panels, :id => @other_author.id
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'sheet_panelsテンプレートを描画する' do
+          get :sheet_panels, :id => @other_author.id
+          response.should render_template("sheet_panels")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :sheet_panels, :id => @other_author.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルにjson一覧出力オプションを問い合わせている' do
+          SheetPanel.should_receive(:list_json_opt).exactly(1)
+          get :sheet_panels, :id => @other_author.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :sheet_panels, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
+          get :sheet_panels, :id => @other_author.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("sheet_id").should be_true
+          json.first.has_key?("t").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :sheet_panels, :id => @other_author.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :sheet_panels, :id => @other_author.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :sheet_panels, :id => @other_author.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :sheet_panels, :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 :sheet_panels, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :sheet_panels, :id => @other_author.id
+        response.should be_success 
+      end
+    end
+  end
+  
   describe '対象作家のコマ一覧表示に於いて' do
     before do
       @other_user = FactoryGirl.create( :user_yas)
diff --git a/spec/controllers/comics_controller_spec.rb b/spec/controllers/comics_controller_spec.rb
new file mode 100644 (file)
index 0000000..449cbcb
--- /dev/null
@@ -0,0 +1,1301 @@
+# -*- encoding: utf-8 -*-\r
+require 'spec_helper'\r
+#コミック\r
+describe ComicsController do\r
+  before do\r
+    @admin =FactoryGirl.create :admin\r
+    @sp = FactoryGirl.create :system_picture\r
+    @lg = FactoryGirl.create :license_group\r
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
+    @user = FactoryGirl.create :user_yas\r
+    @author = FactoryGirl.create :author, :user_id => @user.id\r
+  end\r
+  \r
+if MagicNumber['run_mode'] == 1\r
+  describe '一覧表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      Comic.stub(:list).and_return([@comic, @comic, @comic])\r
+      sign_in @user\r
+    end\r
+    context '事前チェックする' do\r
+      it '与えられたpageがセットされている' do\r
+        get :index, :page => 5\r
+        assigns(:page).should eq 5\r
+      end\r
+      it '省略されると@pageに1値が入る' do\r
+        get :index\r
+        assigns(:page).should eq 1\r
+      end\r
+      it '与えられたpage_sizeがセットされている' do\r
+        get :index, :page_size => 15\r
+        assigns(:page_size).should eq 15\r
+      end\r
+      it '省略されると@page_sizeにデフォルト値が入る' do\r
+        get :index\r
+        assigns(:page_size).should eq Comic.default_page_size\r
+      end\r
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do\r
+        get :index, :page_size => 1500\r
+        assigns(:page_size).should eq Comic.max_page_size\r
+      end\r
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do\r
+        get :index, :page_size => 0\r
+        assigns(:page_size).should eq Comic.default_page_size\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+      it 'コミックモデルに一覧を問い合わせている' do\r
+        Comic.should_receive(:list).exactly(1)\r
+        get :index\r
+      end\r
+      it '@comicsにリストを取得している' do\r
+        get :index\r
+        assigns(:comics).should have_at_least(3).items\r
+      end\r
+      context 'html形式' do\r
+        it '@paginateにページ制御を取得している' do\r
+          get :index\r
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true\r
+        end\r
+        it 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :index, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'コミックモデルにjson一覧出力オプションを問い合わせている' do\r
+          Comic.should_receive(:list_json_opt).exactly(1)\r
+          get :index, :format => :json\r
+        end\r
+        it 'データがリスト構造になっている' do\r
+          get :index, :format => :json\r
+          json = JSON.parse response.body\r
+          json.should have_at_least(3).items\r
+        end\r
+        it 'リストの先頭くらいはコミックっぽいものであって欲しい' do\r
+          get :index, :format => :json\r
+          json = JSON.parse response.body\r
+          json.first.has_key?("title").should be_true\r
+          json.first.has_key?("visible").should be_true\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :index\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :index\r
+          response.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :index, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :index, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :index\r
+          response.should be_success \r
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '単体表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id, :title => 'normal'\r
+      Comic.stub(:show).and_return(@comic)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      it 'コミックモデルに単体取得を問い合わせている' do\r
+        Comic.should_receive(:show).exactly(1)\r
+        get :show\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        get :show, :id => @comic.id\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'コミックモデルにjson単体出力オプションを問い合わせている' do\r
+          Comic.should_receive(:show_json_opt).exactly(1)\r
+          get :show, :id => @comic.id, :format => :json\r
+        end\r
+        it 'データがアレになっている' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          json = JSON.parse response.body\r
+          json["title"].should match(/normal/)\r
+          json["visible"].should_not be_nil\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :show, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :show, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          get :show, :id => @comic.id\r
+          response.should be_success\r
+        end\r
+      end\r
+    end\r
+=begin\r
+    context '対象コミックがないとき' do\r
+      context 'html形式' do\r
+        it '例外404 not_foundを返す' do\r
+          lambda{\r
+            get :show, :id => 0\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外404 not_foundを返す' do\r
+          lambda{ \r
+            get :show, :id => 0, :format => :json\r
+          }.should raise_error(ActiveRecord::RecordNotFound)\r
+        end\r
+      end\r
+    end\r
+    context '非公開コミックを見ようとしたとき' do\r
+      context 'html形式' do\r
+        it '例外403 forbiddenを返す' do\r
+          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+          hidden = FactoryGirl.create :hidden_comic, :author_id => @author.id\r
+          lambda{\r
+            get :show, :id => hidden\r
+          }.should raise_error(ActiveRecord::Forbidden)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '例外403 forbiddenを返す' do\r
+          Comic.any_instance.stub(:visible?).with(any_args()).and_return(false)\r
+          hidden = FactoryGirl.create :hidden_comic, :author_id => @author.id\r
+          lambda{\r
+            get :show, :id => hidden, :format => :json\r
+          }.should raise_error(ActiveRecord::Forbidden)\r
+        end\r
+      end\r
+    end\r
+=end\r
+  end\r
+  describe 'コミック数取得に於いて' do\r
+    before do\r
+      Comic.should_receive(:visible_count).and_return(3)\r
+#      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :count, :format => :json\r
+        response.should be_success \r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :count, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがHash構造になっていてコミック数が1である' do\r
+          get :count, :format => :json\r
+          json = JSON.parse response.body\r
+          json["count"].should == 3\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成フォーム表示に於いて' do\r
+    before do\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :new\r
+        response.should be_success \r
+      end\r
+      it '@comicに新規データを用意している' do\r
+        get :new\r
+        assigns(:comic).should be_a_new(Comic)\r
+      end\r
+      it 'コミックモデルにデフォルト値補充を依頼している' do\r
+        Comic.any_instance.should_receive(:supply_default).exactly(1)\r
+        get :new\r
+      end\r
+      context 'html形式' do\r
+        it 'newテンプレートを描画する' do\r
+          get :new\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'new.jsテンプレートを描画する' do\r
+          get :new, :format => :js\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :new, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'コミックモデルにjson単体出力オプションを問い合わせている' do\r
+          Comic.should_receive(:show_json_opt).exactly(1)\r
+          get :new, :format => :json\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :new\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :new\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :new\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :new\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :new, @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          get :new, @attr\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成に於いて' do\r
+    before do\r
+      sign_in @user\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'normal')\r
+    end\r
+    context '事前チェックしておく' do\r
+      it 'コミックモデルにデフォルト値補充を依頼している' do\r
+        Comic.any_instance.should_receive(:supply_default).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it 'コミックモデルにカラム値復元を依頼している' do\r
+        Comic.any_instance.should_receive(:attributes=).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it 'コミックモデルに上書き補充を依頼している' do\r
+        Comic.any_instance.should_receive(:overwrite).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+      it 'モデルに保存依頼する' do\r
+        Comic.any_instance.should_receive(:save).exactly(1)\r
+        post :create, :comic => @attr\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it "@comicに作成されたコミックを保持していて、それがDBにある" do\r
+        post :create, :comic => @attr\r
+        assigns(:comic).should be_a(Comic)\r
+        assigns(:comic).should be_persisted\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作成されたコミックの表示ページへ遷移する' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.should redirect_to(Comic.last)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it '作成されたコミックをjsonデータで返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+        it 'データがアレになっている' do\r
+          post :create, :comic => @attr, :format => :json\r
+          json = JSON.parse response.body\r
+          json["title"].should match(/normal/)\r
+          json["visible"].should_not be_nil\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          post :create, :comic => @attr\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+    context '検証、保存に失敗した' do\r
+      before do\r
+        Comic.any_instance.stub(:save).and_return(false)\r
+      end\r
+      it "未保存のコミックを保持している" do\r
+        post :create, :comic => @attr\r
+        assigns(:comic).should be_a_new(Comic)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 200\r
+        end\r
+        it '新規ページを描画する' do\r
+          post :create, :comic => @attr\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '編集フォーム表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      sign_in @user\r
+      Comic.stub(:edit).and_return(@comic)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :edit, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+      it 'コミックモデルに編集取得を問い合わせている' do\r
+        Comic.should_receive(:edit).exactly(1)\r
+        get :edit, :id => @comic.id\r
+      end\r
+      it '@comicにデータを用意している' do\r
+        get :edit, :id => @comic.id\r
+        assigns(:comic).should eq @comic\r
+      end\r
+      context 'html形式' do\r
+        it 'editテンプレートを描画する' do\r
+          get :edit, :id => @comic.id\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'edit.jsテンプレートを描画する' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :edit, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :edit, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :edit, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          get :edit, :id => @comic.id\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '更新に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'updated title', :visible => 0)\r
+      sign_in @user\r
+    end\r
+    context '事前チェックしておく' do\r
+      it 'コミックモデルに編集取得を問い合わせている' do\r
+        Comic.stub(:edit).with(any_args()).and_return @comic\r
+        Comic.should_receive(:edit).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'コミックモデルにカラム値復元を依頼している' do\r
+        Comic.any_instance.should_receive(:attributes=).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'コミックモデルに上書き補充を依頼している' do\r
+        Comic.any_instance.should_receive(:overwrite).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it 'モデルに更新を依頼する' do\r
+        Comic.any_instance.stub(:save).with(any_args).and_return true\r
+        Comic.any_instance.should_receive(:save).exactly(1)\r
+        put :update, :id => @comic.id, :comic => @attr\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '更新される' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        Comic.find(@comic.id).visible.should eq 0\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '更新されたコミックの表示ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should redirect_to(@comic)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.body.should match /./\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+    context '検証、保存に失敗したとき' do\r
+      before do\r
+        Comic.any_instance.stub(:save).and_return(false)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード200 Okを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 200\r
+        end\r
+        it '編集ページを描画する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          Comic.any_instance.stub(:save).and_return(false)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '削除に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      sign_in @user\r
+    end\r
+    context '事前チェックしておく' do\r
+      before do\r
+        Comic.stub(:edit).with(any_args()).and_return @comic\r
+        Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+      end\r
+      it 'コミックモデルに編集取得を問い合わせている' do\r
+        Comic.should_receive(:edit).exactly(1)\r
+        delete :destroy, :id => @comic.id\r
+      end\r
+      it 'モデルに削除を依頼する' do\r
+        Comic.any_instance.should_receive(:destroy_with_story).exactly(1)\r
+        delete :destroy, :id => @comic.id\r
+      end\r
+      it '@comicにアレを取得している' do\r
+        delete :destroy, :id => @comic.id\r
+        assigns(:comic).id.should eq(@comic.id)\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '削除される' do\r
+        lambda {\r
+          delete :destroy, :id => @comic.id\r
+        }.should change Comic, :count\r
+      end\r
+      context 'html形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'マイコミックの一覧ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.should redirect_to('/home/comics')\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード200 OKを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.body.should match /./\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限はないが管理者権限があるとき' do\r
+      before do\r
+        sign_out @user\r
+        sign_in @admin\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザだが作家登録していないとき' do\r
+      before do\r
+        @author.destroy\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it '作家登録ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to new_author_path\r
+        end\r
+      end\r
+    end\r
+    context '削除に失敗したとき' do\r
+      before do\r
+        Comic.any_instance.stub(:destroy_with_story).and_return(false)\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'そのコミックの詳細ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.should redirect_to(comic_path(@comic))\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード422 unprocessable_entity を返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.status.should eq 422\r
+        end\r
+        it '応答メッセージUnprocessable Entityを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unprocessable/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+else\r
+  describe '一覧表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      Comic.stub(:list).and_return([@comic, @comic, @comic])\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :index, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :index\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'indexテンプレートを描画する' do\r
+          get :index\r
+          response.should render_template("index")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :index, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '単体表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id, :title => 'normal'\r
+      Comic.stub(:show).and_return(@comic)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :show, :id => @comic.id\r
+        response.should be_success\r
+      end\r
+      context 'html形式' do\r
+        it 'showテンプレートを描画する' do\r
+          get :show, :id => @comic.id\r
+          response.should render_template("show")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :show, :id => @comic.id, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+  end\r
+  describe 'コミック数取得に於いて' do\r
+    before do\r
+      Comic.should_receive(:visible_count).and_return(3)\r
+      sign_out @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :count, :format => :json\r
+        response.should be_success \r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :count, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成フォーム表示に於いて' do\r
+    before do\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :new\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'newテンプレートを描画する' do\r
+          get :new\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'new.jsテンプレートを描画する' do\r
+          get :new, :format => :js\r
+          response.should render_template("new")\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'jsonデータを返す' do\r
+          get :new, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :new\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :new\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :new, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '新規作成に於いて' do\r
+    before do\r
+      sign_in @user\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'normal')\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '作成されたコミックの表示ページへ遷移する' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr\r
+          response.should redirect_to(Comic.last)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+#          Comic.any_instance.stub(:save).and_return(true)\r
+          post :create, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it '作成されたコミックをjsonデータで返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          post :create, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          post :create, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          post :create, :comic => @attr, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '編集フォーム表示に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author_id => @user.author.id\r
+      sign_in @user\r
+      Comic.stub(:edit).and_return(@comic)\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it 'ステータスコード200 OKを返す' do\r
+        get :edit, :id => @comic.id\r
+        response.should be_success \r
+      end\r
+      context 'html形式' do\r
+        it 'editテンプレートを描画する' do\r
+          get :edit, :id => @comic.id\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'edit.jsテンプレートを描画する' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.should render_template("edit")\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          get :edit, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'サインインページへ遷移する' do\r
+          get :edit, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'js形式' do\r
+        it 'ステータスコード401 Unauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.status.should eq 401\r
+        end\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          get :edit, :id => @comic.id, :format => :js\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '更新に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      @attr = FactoryGirl.attributes_for(:comic, :author_id => @author.id, :title => 'updated title', :visible => 0)\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        it 'ステータスコード302 Foundを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.status.should eq 302\r
+        end\r
+        it '更新されたコミックの表示ページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.should redirect_to(@comic)\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it 'ステータスコード200 OKを返す' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          Comic.any_instance.stub(:save).with(any_args()).and_return(true)\r
+          put :update, :id => @comic.id, :comic => @attr, :format => :json\r
+          response.body.should match /./\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      it 'ステータスコード302 Foundを返す' do\r
+        put :update, :id => @comic.id, :comic => @attr\r
+        response.status.should eq 302\r
+      end\r
+      context 'html形式' do\r
+        it 'サインインページへ遷移する' do\r
+          put :update, :id => @comic.id, :comic => @attr\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+  describe '削除に於いて' do\r
+    before do\r
+      @comic = FactoryGirl.create :comic, :author => @author\r
+      sign_in @user\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      context 'html形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード302 Foundを返す' do\r
+          delete :destroy, :id => @comic.id\r
+          response.status.should eq 302\r
+        end\r
+        it 'マイコミックの一覧ページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.should redirect_to('/home/comic')\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        before do\r
+          Comic.any_instance.stub(:destroy_with_story).with(any_args()).and_return(true)\r
+        end\r
+        it 'ステータスコード200 OKを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.should be_success \r
+        end\r
+        it 'ページ本体は特に返さない' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.body.should match /./\r
+        end\r
+      end\r
+    end\r
+    context 'ユーザ権限がないとき' do\r
+      before do\r
+        sign_out @user\r
+      end\r
+      it 'ステータスコード302 Foundを返す' do\r
+        delete :destroy, :id => @comic.id\r
+        response.status.should eq 302\r
+      end\r
+      context 'html形式' do\r
+        it 'サインインページへ遷移する' do\r
+          delete :destroy, :id => @comic.id\r
+          response.body.should redirect_to '/users/sign_in'\r
+        end\r
+      end\r
+      context 'json形式' do\r
+        it '応答メッセージにUnauthorizedを返す' do\r
+          delete :destroy, :id => @comic.id, :format => :json\r
+          response.message.should match(/Unauthorized/)\r
+        end\r
+      end\r
+    end\r
+  end\r
+\r
+end\r
+\r
+end\r
index ae93441..4b3426a 100644 (file)
@@ -21,7 +21,7 @@ describe HomeController do
   end
   
 if MagicNumber['run_mode'] == 1
-  describe 'è\87ªå\88\86ã\81®ã\82³ã\83\9fã\83\83ã\82¯一覧表示に於いて' do
+  describe 'è\87ªå\88\86ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«一覧表示に於いて' do
     before do
       @scroll = FactoryGirl.create :scroll, :author_id => @author.id
       sign_in @user
@@ -58,7 +58,7 @@ if MagicNumber['run_mode'] == 1
         get :scrolls
         response.should be_success 
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに一覧を問い合わせている' do
         Scroll.should_receive(:mylist).exactly(1)
         get :scrolls
       end
@@ -81,7 +81,7 @@ if MagicNumber['run_mode'] == 1
           get :scrolls, :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, :format => :json
         end
@@ -90,7 +90,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, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("title").should be_true
@@ -125,6 +125,320 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
+  describe '自分のスクコマ一覧表示に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @author.id
+      @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id
+      sign_in @user
+      ScrollPanel.stub(:mylist).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :scroll_panels, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :scroll_panels
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :scroll_panels, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :scroll_panels
+        assigns(:page_size).should eq Author.default_scroll_panel_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :scroll_panels, :page_size => 1500
+        assigns(:page_size).should eq Author.scroll_panel_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :scroll_panels, :page_size => 0
+        assigns(:page_size).should eq Author.default_scroll_panel_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :scroll_panels
+        response.should be_success 
+      end
+      it 'スクコマモデルに一覧を問い合わせている' do
+        ScrollPanel.should_receive(:mylist).exactly(1)
+        get :scroll_panels
+      end
+      it '@scroll_panelsにリストを取得している' do
+        get :scroll_panels
+        assigns(:scroll_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :scroll_panels
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'scroll_panelsテンプレートを描画する' do
+          get :scroll_panels
+          response.should render_template("scroll_panels")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :scroll_panels, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スクコマモデルにjson一覧出力オプションを問い合わせている' do
+          ScrollPanel.should_receive(:list_json_opt).exactly(1)
+          get :scroll_panels, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :scroll_panels, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
+          get :scroll_panels, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("scroll_id").should be_true
+          json.first.has_key?("panel_id").should be_true
+        end
+      end
+    end
+    context '作家権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :scroll_panels
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :scroll_panels
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :scroll_panels, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :scroll_panels, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分の用紙一覧表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @author.id
+      sign_in @user
+      Sheet.stub(:mylist).and_return([@sheet, @sheet, @sheet])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :sheets, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :sheets
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :sheets, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :sheets
+        assigns(:page_size).should eq Author.default_sheet_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :sheets, :page_size => 1500
+        assigns(:page_size).should eq Author.sheet_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :sheets, :page_size => 0
+        assigns(:page_size).should eq Author.default_sheet_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :sheets
+        response.should be_success 
+      end
+      it '用紙モデルに一覧を問い合わせている' do
+        Sheet.should_receive(:mylist).exactly(1)
+        get :sheets
+      end
+      it '@sheetsにリストを取得している' do
+        get :sheets
+        assigns(:sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :sheets
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'sheetsテンプレートを描画する' do
+          get :sheets
+          response.should render_template("sheets")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :sheets, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '用紙モデルにjson一覧出力オプションを問い合わせている' do
+          Sheet.should_receive(:list_json_opt).exactly(1)
+          get :sheets, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :sheets, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは用紙っぽいものであって欲しい' do
+          get :sheets, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("caption").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 :sheets
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :sheets
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :sheets, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :sheets, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '自分の紙コマ一覧表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      sign_in @user
+      SheetPanel.stub(:mylist).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :sheet_panels, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :sheet_panels
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :sheet_panels, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :sheet_panels
+        assigns(:page_size).should eq Author.default_sheet_panel_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :sheet_panels, :page_size => 1500
+        assigns(:page_size).should eq Author.sheet_panel_max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :sheet_panels, :page_size => 0
+        assigns(:page_size).should eq Author.default_sheet_panel_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :sheet_panels
+        response.should be_success 
+      end
+      it '紙コマモデルに一覧を問い合わせている' do
+        SheetPanel.should_receive(:mylist).exactly(1)
+        get :sheet_panels
+      end
+      it '@sheet_panelsにリストを取得している' do
+        get :sheet_panels
+        assigns(:sheet_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :sheet_panels
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'sheet_panelsテンプレートを描画する' do
+          get :sheet_panels
+          response.should render_template("sheet_panels")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :sheet_panels, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルにjson一覧出力オプションを問い合わせている' do
+          SheetPanel.should_receive(:list_json_opt).exactly(1)
+          get :sheet_panels, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :sheet_panels, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
+          get :sheet_panels, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_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 :sheet_panels
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :sheet_panels
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :sheet_panels, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :sheet_panels, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
   describe '自分のコマ一覧表示に於いて' do
     before do
       @panel = FactoryGirl.create :panel, :author_id => @author.id
@@ -788,7 +1102,7 @@ if MagicNumber['run_mode'] == 1
   end
   
 else
-  describe 'è\87ªå\88\86ã\81®ã\82³ã\83\9fã\83\83ã\82¯一覧表示に於いて' do
+  describe 'è\87ªå\88\86ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«一覧表示に於いて' do
     before do
       @scroll = FactoryGirl.create :scroll, :author_id => @author.id
       sign_in @user
index 2a4db41..5c1495e 100644 (file)
@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 require 'spec_helper'
-#ã\82¹ã\83\88ã\83¼ã\83ªã\83¼
+#ã\82¹ã\82¯ã\82³ã\83\9e
 describe ScrollPanelsController do
   before do
     @admin = FactoryGirl.create :admin
@@ -51,7 +51,7 @@ if MagicNumber['run_mode'] == 1
         get :index
         response.should be_success 
       end
-      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルに一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\82³ã\83\9eモデルに一覧を問い合わせている' do
         ScrollPanel.should_receive(:list).exactly(1)
         get :index
       end
@@ -74,7 +74,7 @@ if MagicNumber['run_mode'] == 1
           get :index, :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 :index, :format => :json
         end
@@ -83,7 +83,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 :index, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("panel_id").should be_true
@@ -148,7 +148,7 @@ if MagicNumber['run_mode'] == 1
       ScrollPanel.stub(:show).with(@scroll_panel.id.to_s, [nil, @admin]).and_return(@scroll_panel)
     end
     context 'つつがなく終わるとき' do
-      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルに単体取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\82³ã\83\9eモデルに単体取得を問い合わせている' do
         ScrollPanel.should_receive(:show).with(@scroll_panel.id.to_s, [@user, nil]).exactly(1)
         get :show, :id => @scroll_panel.id
       end
@@ -175,7 +175,7 @@ if MagicNumber['run_mode'] == 1
           get :show, :id => @scroll_panel.id, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81«ã\82¹ã\83\88ã\83¼ã\83ªã\83¼json出力を問い合わせている' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81«ã\82¹ã\82¯ã\82³ã\83\9ejson出力を問い合わせている' do
           ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
           get :show, :id => @scroll_panel.id, :format => :json
         end
@@ -234,139 +234,6 @@ if MagicNumber['run_mode'] == 1
     end
   end
   
-  describe '閲覧に於いて' do
-    before do
-      @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
-      Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
-      Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
-      ScrollPanel.stub(:count).and_return(10)
-      ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
-      sign_in @user
-    end
-    context 'パラメータチェックする' do
-      it '与えられたoffsetがセットされている' do
-        get :scroll, :id => @scroll.id, :offset => 5
-        assigns(:offset).should eq 5
-      end
-      it '省略されると@offsetに0値が入る' do
-        get :scroll, :id => @scroll.id
-        assigns(:offset).should eq 0
-      end
-      it '与えられたcountがセットされている' do
-        get :scroll, :id => @scroll.id, :count => 4
-        assigns(:panel_count).should eq 4
-      end
-      it '省略されると@panel_countにデフォルト値が入る' do
-        get :scroll, :id => @scroll.id
-        assigns(:panel_count).should eq ScrollPanel.default_panel_size
-      end
-      it '最大を超えると@panel_countにデフォルト最大値が入る' do
-        get :scroll, :id => @scroll.id, :count => 1500
-        assigns(:panel_count).should eq ScrollPanel.max_panel_size
-      end
-      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
-        get :scroll, :id => @scroll.id, :count => -1
-        assigns(:panel_count).should eq ScrollPanel.default_panel_size
-      end
-    end
-    context '事前チェックする' do
-      it 'コミックモデルに単体取得を問い合わせている' do
-        Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
-        get :scroll, :id => @scroll.id
-      end
-      it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
-        ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
-        get :scroll, :id => @scroll.id
-      end
-    end
-    context 'つつがなく終わるとき' do
-      it '@scroll_panelsにリストを取得している' do
-        get :scroll, :id => @scroll.id
-        assigns(:scroll_panels).should have_at_least(3).items
-      end
-      context 'html形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :scroll, :id => @scroll.id
-          response.should be_success 
-        end
-        it 'scrollテンプレートを描画する' do
-          get :scroll, :id => @scroll.id
-          response.should render_template("scroll")
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード200 OKを返す' do
-          get :scroll, :id => @scroll.id, :format => :json
-          response.should be_success 
-        end
-        it 'jsonデータを返す' do
-          get :scroll, :id => @scroll.id, :format => :json
-          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
-        end
-        it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
-          ScrollPanel.should_receive(:list_as_json_text).exactly(1)
-          get :scroll, :id => @scroll.id, :format => :json
-        end
-        it 'データがリスト構造になっている' do
-          get :scroll, :id => @scroll.id, :format => :json
-          json = JSON.parse response.body
-          json.should have_at_least(3).items
-        end
-        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
-          get :scroll, :id => @scroll.id, :format => :json
-          json = JSON.parse response.body
-          json.first.has_key?("panel_id").should be_true
-          json.first.has_key?("scroll_id").should be_true
-          json.first.has_key?("author_id").should be_true
-        end
-      end
-    end
-    context 'ユーザ権限がないとき' do
-      before do
-        sign_out @user
-      end
-      context 'html形式' do
-        it 'ステータスコード302 Foundを返す' do
-          get :scroll, :id => @scroll.id
-          response.status.should eq 302
-        end
-        it 'サインインページへ遷移する' do
-          get :scroll, :id => @scroll.id
-          response.should redirect_to '/users/sign_in'
-        end
-      end
-      context 'json形式' do
-        it 'ステータスコード401 Unauthorizedを返す' do
-          get :scroll, :id => @scroll.id, :format => :json
-          response.status.should eq 401
-        end
-        it '応答メッセージにUnauthorizedを返す' do
-          get :scroll, :id => @scroll.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 :scroll, :id => @scroll.id
-        response.should be_success 
-      end
-    end
-    context 'ユーザだが作家登録していないとき' do
-      before do
-        @author.destroy
-      end
-      it 'ステータスコード200 OKを返す' do
-        get :scroll, :id => @scroll.id
-        response.should be_success 
-      end
-    end
-  end
-
   describe '新規作成フォーム表示に於いて' do
     before do
       sign_in @user
@@ -409,7 +276,7 @@ if MagicNumber['run_mode'] == 1
           get :new, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼のjson出力を問い合わせている' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81®ã\82¹ã\82¯ã\82³ã\83\9eのjson出力を問い合わせている' do
           ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
           get :new, :format => :json
         end
@@ -500,7 +367,8 @@ if MagicNumber['run_mode'] == 1
         ScrollPanel.any_instance.should_receive(:overwrite).exactly(1)
         post :create, :scroll_panel => @attr
       end
-      it 'コミックモデルに編集取得を依頼している' do
+      it 'スクロールモデルに編集取得を依頼している' do
+        Scroll.stub(:edit).and_return(@scroll)
         Scroll.should_receive(:edit).with(@scroll.id, @author).exactly(1)
         post :create, :scroll_panel => @attr
       end
@@ -523,10 +391,10 @@ if MagicNumber['run_mode'] == 1
           post :create, :scroll_panel => @attr
           response.status.should eq 302
         end
-        it 'ã\82³ã\83\9fã\83\83ã\82¯ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼表示へ遷移する' do
+        it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«ã\81®ã\82¹ã\82¯ã\82³ã\83\9e表示へ遷移する' do
 #          ScrollPanel.any_instance.stub(:store).and_return(true)
           post :create, :scroll_panel => @attr
-          response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
+          response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
         end
       end
       context 'json形式' do
@@ -539,7 +407,7 @@ if MagicNumber['run_mode'] == 1
           post :create, :scroll_panel => @attr, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼ã\83¢ã\83\87ã\83«ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼のjson出力を問い合わせている' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9eã\83¢ã\83\87ã\83«ã\81®ã\82¹ã\82¯ã\82³ã\83\9eのjson出力を問い合わせている' do
           ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).exactly(1)
           post :create, :scroll_panel => @attr, :format => :json
         end
@@ -644,7 +512,7 @@ if MagicNumber['run_mode'] == 1
       ScrollPanel.stub(:show).and_return(@scroll_panel)
     end
     context 'つつがなく終わるとき' do
-      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\82³ã\83\9eモデルに編集取得を問い合わせている' do
         ScrollPanel.should_receive(:edit).exactly(1)
         get :edit, :id => @scroll_panel.id
       end
@@ -756,7 +624,7 @@ if MagicNumber['run_mode'] == 1
         ScrollPanel.any_instance.should_receive(:store).exactly(1)
         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
       end
-      it "@scroll_panelã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\83\88ã\83¼ã\83ªã\83¼を保持していて、それがDBにある" do
+      it "@scroll_panelã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\82³ã\83\9eを保持していて、それがDBにある" do
         put :update, :id => @scroll_panel.id, :scroll_panel => @attr
         assigns(:scroll_panel).should be_a(ScrollPanel)
         assigns(:scroll_panel).should be_persisted
@@ -767,10 +635,10 @@ if MagicNumber['run_mode'] == 1
           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
           response.status.should eq 302
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼表示へ遷移する' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9e表示へ遷移する' do
 #          ScrollPanel.any_instance.stub(:store).and_return(true)
           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
-          response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
+          response.should redirect_to(play_scroll_path(@attr[:scroll_id]))
         end
       end
       context 'json形式' do
@@ -879,7 +747,7 @@ if MagicNumber['run_mode'] == 1
         ScrollPanel.stub(:edit).with(any_args()).and_return @scroll_panel
         ScrollPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
       end
-      it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\82³ã\83\9eモデルに編集取得を問い合わせている' do
         ScrollPanel.should_receive(:edit).exactly(1)
         delete :destroy, :id => @scroll_panel.id
       end
@@ -903,7 +771,7 @@ if MagicNumber['run_mode'] == 1
         end
         it '閲覧ページへ遷移する' do
           delete :destroy, :id => @scroll_panel.id
-          response.should redirect_to(:controller => 'scroll_panels', :action => :scroll, :id => @scroll_panel.scroll_id)
+          response.should redirect_to(play_scroll_path(@scroll_panel.scroll_id) )
         end
       end
       context 'json形式' do
@@ -978,7 +846,7 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @scroll_panel.id
           response.status.should eq 302
         end
-        it 'ã\81\9dã\81®ã\82³ã\83\9fã\83\83ã\82¯の詳細ページへ遷移する' do
+        it 'ã\81\9dã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«の詳細ページへ遷移する' do
           delete :destroy, :id => @scroll_panel.id
           response.should redirect_to(scroll_panel_path(@scroll_panel))
         end
@@ -995,9 +863,9 @@ if MagicNumber['run_mode'] == 1
       end
     end
 =begin
-    context '対象ã\82¹ã\83\88ã\83¼ã\83ªã\83¼がないとき' do
+    context '対象ã\82¹ã\82¯ã\82³ã\83\9eがないとき' do
     end
-    context 'ä»\96人ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼だったとき' do
+    context 'ä»\96人ã\81®ã\82¹ã\82¯ã\82³ã\83\9eだったとき' do
     end
 =end
   end
@@ -1244,7 +1112,7 @@ else
           post :create, :scroll_panel => @attr
           response.status.should eq 302
         end
-        it 'ã\82³ã\83\9fã\83\83ã\82¯ã\81®ã\82¹ã\83\88ã\83¼ã\83ªã\83¼表示へ遷移する' do
+        it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«ã\81®ã\82¹ã\82¯ã\82³ã\83\9e表示へ遷移する' do
 #          ScrollPanel.any_instance.stub(:store).and_return(true)
           post :create, :scroll_panel => @attr
           response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
@@ -1357,7 +1225,7 @@ else
           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
           response.status.should eq 302
         end
-        it 'ã\82¹ã\83\88ã\83¼ã\83ªã\83¼表示へ遷移する' do
+        it 'ã\82¹ã\82¯ã\82³ã\83\9e表示へ遷移する' do
 #          ScrollPanel.any_instance.stub(:store).and_return(true)
           put :update, :id => @scroll_panel.id, :scroll_panel => @attr
           response.should redirect_to(:action => :scroll, :id => @attr[:scroll_id])
index 8ebf574..041f309 100644 (file)
@@ -1,6 +1,6 @@
 # -*- encoding: utf-8 -*-
 require 'spec_helper'
-#ã\82³ã\83\9fã\83\83ã\82¯
+#ã\82¹ã\82¯ã\83­ã\83¼ã\83«
 describe ScrollsController do
   before do
     @admin =FactoryGirl.create :admin
@@ -49,7 +49,7 @@ if MagicNumber['run_mode'] == 1
         get :index
         response.should be_success 
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに一覧を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに一覧を問い合わせている' do
         Scroll.should_receive(:list).exactly(1)
         get :index
       end
@@ -72,7 +72,7 @@ if MagicNumber['run_mode'] == 1
           get :index, :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 :index, :format => :json
         end
@@ -81,7 +81,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 :index, :format => :json
           json = JSON.parse response.body
           json.first.has_key?("title").should be_true
@@ -148,7 +148,7 @@ if MagicNumber['run_mode'] == 1
         get :show, :id => @scroll.id
         response.should be_success
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに単体取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに単体取得を問い合わせている' do
         Scroll.should_receive(:show).exactly(1)
         get :show
       end
@@ -167,7 +167,7 @@ if MagicNumber['run_mode'] == 1
           get :show, :id => @scroll.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(:show_json_opt).exactly(1)
           get :show, :id => @scroll.id, :format => :json
         end
@@ -226,7 +226,7 @@ if MagicNumber['run_mode'] == 1
       end
     end
 =begin
-    context '対象ã\82³ã\83\9fã\83\83ã\82¯がないとき' do
+    context '対象ã\82¹ã\82¯ã\83­ã\83¼ã\83«がないとき' do
       context 'html形式' do
         it '例外404 not_foundを返す' do
           lambda{
@@ -242,7 +242,7 @@ if MagicNumber['run_mode'] == 1
         end
       end
     end
-    context 'é\9d\9eå\85¬é\96\8bã\82³ã\83\9fã\83\83ã\82¯を見ようとしたとき' do
+    context 'é\9d\9eå\85¬é\96\8bã\82¹ã\82¯ã\83­ã\83¼ã\83«を見ようとしたとき' do
       context 'html形式' do
         it '例外403 forbiddenを返す' do
           Scroll.any_instance.stub(:visible?).with(any_args()).and_return(false)
@@ -264,7 +264,143 @@ if MagicNumber['run_mode'] == 1
     end
 =end
   end
-  describe 'コミック数取得に於いて' do
+  
+  describe '閲覧に於いて' do
+    before do
+      @scroll = FactoryGirl.create :scroll, :author_id => @user.author.id
+      @panel = FactoryGirl.create :panel, :author_id => @author.id
+      @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
+      Scroll.stub(:show).with(@scroll.id.to_s, [@user, nil]).and_return(@scroll)
+      Scroll.stub(:show).with(@scroll.id.to_s, [nil, @admin]).and_return(@scroll)
+      ScrollPanel.stub(:count).and_return(10)
+      ScrollPanel.stub(:play_list).with(any_args).and_return([@scroll_panel, @scroll_panel, @scroll_panel])
+      sign_in @user
+    end
+    context 'パラメータチェックする' do
+      it '与えられたoffsetがセットされている' do
+        get :play, :id => @scroll.id, :offset => 5
+        assigns(:offset).should eq 5
+      end
+      it '省略されると@offsetに0値が入る' do
+        get :play, :id => @scroll.id
+        assigns(:offset).should eq 0
+      end
+      it '与えられたcountがセットされている' do
+        get :play, :id => @scroll.id, :count => 4
+        assigns(:panel_count).should eq 4
+      end
+      it '省略されると@panel_countにデフォルト値が入る' do
+        get :play, :id => @scroll.id
+        assigns(:panel_count).should eq ScrollPanel.default_panel_size
+      end
+      it '最大を超えると@panel_countにデフォルト最大値が入る' do
+        get :play, :id => @scroll.id, :count => 1500
+        assigns(:panel_count).should eq ScrollPanel.max_panel_size
+      end
+      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
+        get :play, :id => @scroll.id, :count => -1
+        assigns(:panel_count).should eq ScrollPanel.default_panel_size
+      end
+    end
+    context '事前チェックする' do
+      it 'スクロールモデルに単体取得を問い合わせている' do
+        Scroll.should_receive(:show).with(@scroll.id.to_s, [@user, nil]).exactly(1)
+        get :play, :id => @scroll.id
+      end
+      it 'スクコマモデルにプレイリスト取得を問い合わせている' do
+        ScrollPanel.should_receive(:play_list).with(@scroll, @author, 0, 30).exactly(1)
+        get :play, :id => @scroll.id
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '@scroll_panelsにリストを取得している' do
+        get :play, :id => @scroll.id
+        assigns(:scroll_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :play, :id => @scroll.id
+          response.should be_success 
+        end
+        it 'scrollテンプレートを描画する' do
+          get :play, :id => @scroll.id
+          response.should render_template("scroll")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スクコマモデルにスクコマリストのjson出力を問い合わせている' do
+          ScrollPanel.should_receive(:list_as_json_text).exactly(1)
+          get :play, :id => @scroll.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :play, :id => @scroll.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスクコマっぽいものであって欲しい' do
+          get :play, :id => @scroll.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("scroll_id").should be_true
+          json.first.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :play, :id => @scroll.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :play, :id => @scroll.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :play, :id => @scroll.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :play, :id => @scroll.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 :play, :id => @scroll.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :play, :id => @scroll.id
+        response.should be_success 
+      end
+    end
+  end
+
+  describe 'スクロール数取得に於いて' do
     before do
       Scroll.should_receive(:visible_count).and_return(3)
 #      sign_in @user
@@ -279,7 +415,7 @@ if MagicNumber['run_mode'] == 1
           get :count, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
-        it 'ã\83\87ã\83¼ã\82¿ã\81\8cHashæ§\8bé\80 ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\81¦ã\82³ã\83\9fã\83\83ã\82¯数が1である' do
+        it 'ã\83\87ã\83¼ã\82¿ã\81\8cHashæ§\8bé\80 ã\81«ã\81ªã\81£ã\81¦ã\81\84ã\81¦ã\82¹ã\82¯ã\83­ã\83¼ã\83«数が1である' do
           get :count, :format => :json
           json = JSON.parse response.body
           json["count"].should == 3
@@ -301,7 +437,7 @@ if MagicNumber['run_mode'] == 1
         get :new
         assigns(:scroll).should be_a_new(Scroll)
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにデフォルト値補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにデフォルト値補充を依頼している' do
         Scroll.any_instance.should_receive(:supply_default).exactly(1)
         get :new
       end
@@ -322,7 +458,7 @@ if MagicNumber['run_mode'] == 1
           get :new, :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(:show_json_opt).exactly(1)
           get :new, :format => :json
         end
@@ -402,15 +538,15 @@ if MagicNumber['run_mode'] == 1
       @attr = FactoryGirl.attributes_for(:scroll, :author_id => @author.id, :title => 'normal')
     end
     context '事前チェックしておく' do
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにデフォルト値補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにデフォルト値補充を依頼している' do
         Scroll.any_instance.should_receive(:supply_default).exactly(1)
         post :create, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにカラム値復元を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにカラム値復元を依頼している' do
         Scroll.any_instance.should_receive(:attributes=).exactly(1)
         post :create, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに上書き補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに上書き補充を依頼している' do
         Scroll.any_instance.should_receive(:overwrite).exactly(1)
         post :create, :scroll => @attr
       end
@@ -420,7 +556,7 @@ if MagicNumber['run_mode'] == 1
       end
     end
     context 'つつがなく終わるとき' do
-      it "@scrollã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯を保持していて、それがDBにある" do
+      it "@scrollã\81«ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«を保持していて、それがDBにある" do
         post :create, :scroll => @attr
         assigns(:scroll).should be_a(Scroll)
         assigns(:scroll).should be_persisted
@@ -431,7 +567,7 @@ if MagicNumber['run_mode'] == 1
           post :create, :scroll => @attr
           response.status.should eq 302
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
 #          Scroll.any_instance.stub(:save).and_return(true)
           post :create, :scroll => @attr
           response.should redirect_to(Scroll.last)
@@ -443,7 +579,7 @@ if MagicNumber['run_mode'] == 1
           post :create, :scroll => @attr, :format => :json
           response.should be_success 
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯をjsonデータで返す' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«をjsonデータで返す' do
           post :create, :scroll => @attr, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
@@ -515,7 +651,7 @@ if MagicNumber['run_mode'] == 1
       before do
         Scroll.any_instance.stub(:save).and_return(false)
       end
-      it "æ\9cªä¿\9då­\98ã\81®ã\82³ã\83\9fã\83\83ã\82¯を保持している" do
+      it "æ\9cªä¿\9då­\98ã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«を保持している" do
         post :create, :scroll => @attr
         assigns(:scroll).should be_a_new(Scroll)
       end
@@ -553,7 +689,7 @@ if MagicNumber['run_mode'] == 1
         get :edit, :id => @scroll.id
         response.should be_success 
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに編集取得を問い合わせている' do
         Scroll.should_receive(:edit).exactly(1)
         get :edit, :id => @scroll.id
       end
@@ -639,16 +775,16 @@ if MagicNumber['run_mode'] == 1
       sign_in @user
     end
     context '事前チェックしておく' do
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに編集取得を問い合わせている' do
         Scroll.stub(:edit).with(any_args()).and_return @scroll
         Scroll.should_receive(:edit).exactly(1)
         put :update, :id => @scroll.id, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルにカラム値復元を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルにカラム値復元を依頼している' do
         Scroll.any_instance.should_receive(:attributes=).exactly(1)
         put :update, :id => @scroll.id, :scroll => @attr
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに上書き補充を依頼している' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに上書き補充を依頼している' do
         Scroll.any_instance.should_receive(:overwrite).exactly(1)
         put :update, :id => @scroll.id, :scroll => @attr
       end
@@ -673,7 +809,7 @@ if MagicNumber['run_mode'] == 1
           put :update, :id => @scroll.id, :scroll => @attr
           response.status.should eq 302
         end
-        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
           put :update, :id => @scroll.id, :scroll => @attr
           response.should redirect_to(@scroll)
         end
@@ -781,7 +917,7 @@ if MagicNumber['run_mode'] == 1
         Scroll.stub(:edit).with(any_args()).and_return @scroll
         Scroll.any_instance.stub(:destroy_with_scroll_panel).with(any_args()).and_return(true)
       end
-      it 'ã\82³ã\83\9fã\83\83ã\82¯モデルに編集取得を問い合わせている' do
+      it 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«モデルに編集取得を問い合わせている' do
         Scroll.should_receive(:edit).exactly(1)
         delete :destroy, :id => @scroll.id
       end
@@ -808,7 +944,7 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @scroll.id
           response.status.should eq 302
         end
-        it 'ã\83\9eã\82¤ã\82³ã\83\9fã\83\83ã\82¯の一覧ページへ遷移する' do
+        it 'ã\83\9eã\82¤ã\82¹ã\82¯ã\83­ã\83¼ã\83«の一覧ページへ遷移する' do
           delete :destroy, :id => @scroll.id
           response.should redirect_to('/home/scrolls')
         end
@@ -888,7 +1024,7 @@ if MagicNumber['run_mode'] == 1
           delete :destroy, :id => @scroll.id
           response.status.should eq 302
         end
-        it 'ã\81\9dã\81®ã\82³ã\83\9fã\83\83ã\82¯の詳細ページへ遷移する' do
+        it 'ã\81\9dã\81®ã\82¹ã\82¯ã\83­ã\83¼ã\83«の詳細ページへ遷移する' do
           delete :destroy, :id => @scroll.id
           response.should redirect_to(scroll_path(@scroll))
         end
@@ -1000,7 +1136,7 @@ else
       end
     end
   end
-  describe 'ã\82³ã\83\9fã\83\83ã\82¯数取得に於いて' do
+  describe 'ã\82¹ã\82¯ã\83­ã\83¼ã\83«数取得に於いて' do
     before do
       Scroll.should_receive(:visible_count).and_return(3)
       sign_out @user
@@ -1096,7 +1232,7 @@ else
           post :create, :scroll => @attr
           response.status.should eq 302
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
 #          Scroll.any_instance.stub(:save).and_return(true)
           post :create, :scroll => @attr
           response.should redirect_to(Scroll.last)
@@ -1108,7 +1244,7 @@ else
           post :create, :scroll => @attr, :format => :json
           response.should be_success 
         end
-        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯をjsonデータで返す' do
+        it 'ä½\9cæ\88\90ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«をjsonデータで返す' do
           post :create, :scroll => @attr, :format => :json
           lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
         end
@@ -1205,7 +1341,7 @@ else
           put :update, :id => @scroll.id, :scroll => @attr
           response.status.should eq 302
         end
-        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82³ã\83\9fã\83\83ã\82¯の表示ページへ遷移する' do
+        it 'æ\9b´æ\96°ã\81\95ã\82\8cã\81\9fã\82¹ã\82¯ã\83­ã\83¼ã\83«の表示ページへ遷移する' do
           put :update, :id => @scroll.id, :scroll => @attr
           response.should redirect_to(@scroll)
         end
@@ -1254,7 +1390,7 @@ else
           delete :destroy, :id => @scroll.id
           response.status.should eq 302
         end
-        it 'ã\83\9eã\82¤ã\82³ã\83\9fã\83\83ã\82¯の一覧ページへ遷移する' do
+        it 'ã\83\9eã\82¤ã\82¹ã\82¯ã\83­ã\83¼ã\83«の一覧ページへ遷移する' do
           delete :destroy, :id => @scroll.id
           response.should redirect_to('/home/scroll')
         end
index 918da85..5040adf 100644 (file)
+# -*- encoding: utf-8 -*-
 require 'spec_helper'
-
+#紙コマ
 describe SheetPanelsController do
+  before do
+    @admin = FactoryGirl.create :admin
+    @sp = FactoryGirl.create :system_picture
+    @lg = FactoryGirl.create :license_group
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @user = FactoryGirl.create :user_yas
+    @author = FactoryGirl.create :author, :user_id => @user.id
+    @sheet = FactoryGirl.create :sheet, :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
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      SheetPanel.stub(:list).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :index, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :index
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :index, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :index
+        assigns(:page_size).should eq SheetPanel.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 1500
+        assigns(:page_size).should eq SheetPanel.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 0
+        assigns(:page_size).should eq SheetPanel.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it '紙コマモデルに一覧を問い合わせている' do
+        SheetPanel.should_receive(:list).exactly(1)
+        get :index
+      end
+      it '@sheet_panelsにリストを取得している' do
+        get :index
+        assigns(:sheet_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルにjson一覧出力オプションを問い合わせている' do
+          SheetPanel.should_receive(:list_json_opt).exactly(1)
+          get :index, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("sheet_id").should be_true
+          json.first.has_key?("t").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :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 :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      SheetPanel.stub(:show).with(@sheet_panel.id.to_s, [@user, nil]).and_return(@sheet_panel)
+      SheetPanel.stub(:show).with(@sheet_panel.id.to_s, [nil, @admin]).and_return(@sheet_panel)
+    end
+    context 'つつがなく終わるとき' do
+      it '紙コマモデルに単体取得を問い合わせている' do
+        SheetPanel.should_receive(:show).with(@sheet_panel.id.to_s, [@user, nil]).exactly(1)
+        get :show, :id => @sheet_panel.id
+      end
+      it '@sheet_panelにアレを取得している' do
+        get :show, :id => @sheet_panel.id
+        assigns(:sheet_panel).should eq @sheet_panel
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sheet_panel.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルに紙コマjson出力を問い合わせている' do
+          SheetPanel.any_instance.should_receive(:sheet_panel_as_json).exactly(1)
+          get :show, :id => @sheet_panel.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          json = JSON.parse response.body
+          json.has_key?("panel_id").should be_true
+          json.has_key?("sheet_id").should be_true
+          json.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @sheet_panel.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 :show, :id => @sheet_panel.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it '@sheet_panelに新規データを用意している' do
+        get :new
+        assigns(:sheet_panel).should be_a_new(SheetPanel)
+      end
+      it 'モデルにデフォルト値補充を依頼している' do
+        SheetPanel.any_instance.should_receive(:supply_default).exactly(1)
+        get :new
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルの紙コマのjson出力を問い合わせている' do
+          SheetPanel.any_instance.should_receive(:sheet_panel_as_json).exactly(1)
+          get :new, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :new, :format => :json
+          json = JSON.parse response.body
+          json.has_key?("panel_id").should be_true
+          json.has_key?("sheet_id").should be_true
+          json.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :new
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+  
+  describe '新規作成に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'デフォルト値補充を依頼する' do
+        SheetPanel.any_instance.should_receive(:supply_default).exactly(1)
+        post :create, :sheet_panel => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        SheetPanel.any_instance.stub(:store).and_return(true)
+        post :create, :sheet_panel => @attr
+        assigns(:sheet_panel).sheet_id.should eq @sheet.id
+        assigns(:sheet_panel).panel_id.should eq @panel.id
+      end
+      it '上書き補充を依頼する' do
+        SheetPanel.any_instance.should_receive(:overwrite).exactly(1)
+        post :create, :sheet_panel => @attr
+      end
+      it '用紙モデルに編集取得を依頼している' do
+        Sheet.stub(:edit).and_return(@sheet)
+        Sheet.should_receive(:edit).with(@sheet.id, @author).exactly(1)
+        post :create, :sheet_panel => @attr
+      end
+      it 'コマモデルに単体取得を依頼している' do
+        Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
+        post :create, :sheet_panel => @attr
+      end
+      it 'モデルに保存依頼する' do
+        SheetPanel.any_instance.should_receive(:store).exactly(1)
+        post :create, :sheet_panel => @attr
+      end
+      it "@sheet_panelに作成された紙コマを保持していて、それがDBにある" do
+        post :create, :sheet_panel => @attr
+        assigns(:sheet_panel).should be_a(SheetPanel)
+        assigns(:sheet_panel).should be_persisted
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          SheetPanel.any_instance.stub(:store).and_return(true)
+          post :create, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it '用紙の紙コマ表示へ遷移する' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          post :create, :sheet_panel => @attr
+          response.should redirect_to(play_sheet_path(@attr[:sheet_id]))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          post :create, :sheet_panel => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成された紙コマをjsonデータで返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルの紙コマのjson出力を問い合わせている' do
+          SheetPanel.any_instance.should_receive(:sheet_panel_as_json).exactly(1)
+          post :create, :sheet_panel => @attr, :format => :json
+        end
+        it 'データがアレになっている' do
+          post :create, :sheet_panel => @attr, :format => :json
+          json = JSON.parse response.body
+          json["t"].should eq 0
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :sheet_panel => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :sheet_panel => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          post :create, :sheet_panel => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        SheetPanel.any_instance.stub(:store).and_return(false)
+      end
+      it "未保存の紙コマを保持している" do
+        post :create, :sheet_panel => @attr
+        assigns(:sheet_panel).should be_a_new(SheetPanel)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          post :create, :sheet_panel => @attr
+          response.status.should eq 200
+        end
+        it '新規ページを描画する' do
+          post :create, :sheet_panel => @attr
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id
+      sign_in @user
+      SheetPanel.stub(:show).and_return(@sheet_panel)
+    end
+    context 'つつがなく終わるとき' do
+      it '紙コマモデルに編集取得を問い合わせている' do
+        SheetPanel.should_receive(:edit).exactly(1)
+        get :edit, :id => @sheet_panel.id
+      end
+      it '@sheet_panelにデータを用意している' do
+        get :edit, :id => @sheet_panel.id
+        assigns(:sheet_panel).should eq @sheet_panel
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @sheet_panel.id
+          response.should be_success 
+        end
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @sheet_panel.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.should be_success 
+        end
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :edit, :id => @sheet_panel.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+
+  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)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'モデルに編集取得依頼する' do
+        SheetPanel.stub(:edit).with(any_args).and_return(@sheet_panel)
+        SheetPanel.should_receive(:edit).exactly(1)
+        put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        SheetPanel.any_instance.stub(:store).and_return(true)
+        SheetPanel.any_instance.should_receive(:attributes=).exactly(1)
+        put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+      end
+      it '上書き補充を依頼する' do
+        SheetPanel.any_instance.should_receive(:overwrite).exactly(1)
+        put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+      end
+      it 'モデルに保存依頼する' do
+        SheetPanel.any_instance.should_receive(:store).exactly(1)
+        put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+      end
+      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
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          SheetPanel.any_instance.stub(:store).and_return(true)
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it '紙コマ表示へ遷移する' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.should redirect_to(play_sheet_path(@attr[:sheet_id]))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        SheetPanel.any_instance.stub(:store).and_return(false)
+      end
+      it "指定の紙コマを保持している" do
+        put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+        assigns(:sheet_panel).should eq @sheet_panel
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id
+      sign_in @user
+      SheetPanel.stub(:edit).and_return(@sheet_panel)
+    end
+    context '事前チェックしておく' do
+      before do
+        SheetPanel.stub(:edit).with(any_args()).and_return @sheet_panel
+        SheetPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      it '紙コマモデルに編集取得を問い合わせている' do
+        SheetPanel.should_receive(:edit).exactly(1)
+        delete :destroy, :id => @sheet_panel.id
+      end
+      it 'モデルに削除を依頼する' do
+        SheetPanel.any_instance.should_receive(:destroy_and_shorten).exactly(1)
+        delete :destroy, :id => @sheet_panel.id
+      end
+      it '@sheet_panelにアレを取得している' do
+        delete :destroy, :id => @sheet_panel.id
+        assigns(:sheet_panel).id.should eq(@sheet_panel.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        SheetPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it '閲覧ページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.should redirect_to(play_sheet_path(@sheet_panel.sheet_id))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.should be_success
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        SheetPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'その用紙の詳細ページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.should redirect_to(sheet_panel_path(@sheet_panel))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+=begin
+    context '対象紙コマがないとき' do
+    end
+    context '他人の紙コマだったとき' do
+    end
+=end
+  end
+  
+else
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      SheetPanel.stub(:list).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      SheetPanel.stub(:show).with(@sheet_panel.id.to_s, [nil, nil]).and_return(@sheet_panel)
+      SheetPanel.stub(:show).with(@sheet_panel.id.to_s, [@user, nil]).and_return(@sheet_panel)
+      SheetPanel.stub(:show).with(@sheet_panel.id.to_s, [nil, @admin]).and_return(@sheet_panel)
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sheet_panel.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sheet_panel.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @sheet_panel.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '閲覧に於いて' do
+    before do
+      @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      SheetPanel.stub(:count).and_return(10)
+      SheetPanel.stub(:play_list).with(any_args).and_return([@sheet_panel, @sheet_panel, @sheet_panel])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id
+          response.should be_success 
+        end
+        it 'sheetテンプレートを描画する' do
+          get :sheet, :id => @sheet.id
+          response.should render_template("sheet")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id
+          response.should be_success 
+        end
+        it 'sheetテンプレートを描画する' do
+          get :sheet, :id => @sheet.id
+          response.should render_template("sheet")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
 
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '新規作成に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          SheetPanel.any_instance.stub(:store).and_return(true)
+          post :create, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it '用紙の紙コマ表示へ遷移する' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          post :create, :sheet_panel => @attr
+          response.should redirect_to(:action => :sheet, :id => @attr[:sheet_id])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          post :create, :sheet_panel => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成されたコマをjsonデータで返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :sheet_panel => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :sheet_panel => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id
+      sign_in @user
+      SheetPanel.stub(:show).and_return(@sheet_panel)
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @sheet_panel.id
+          response.should be_success 
+        end
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @sheet_panel.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.should be_success 
+        end
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @sheet_panel.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  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)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          SheetPanel.any_instance.stub(:store).and_return(true)
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it '紙コマ表示へ遷移する' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.should redirect_to(:action => :sheet, :id => @attr[:sheet_id])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          SheetPanel.any_instance.stub(:store).and_return(true)
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @sheet_panel.id, :sheet_panel => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id
+      sign_in @user
+      SheetPanel.stub(:edit).and_return(@sheet_panel)
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        SheetPanel.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it '閲覧ページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.should redirect_to(:controller => 'sheet_panels', :action => :sheet, :id => @sheet_panel.sheet_id)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.should be_success
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet_panel.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @sheet_panel.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @sheet_panel.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+end
 end
index 8855b14..6f4d0ea 100644 (file)
+# -*- encoding: utf-8 -*-
 require 'spec_helper'
-
+#用紙
 describe SheetsController do
+  before do
+    @admin =FactoryGirl.create :admin
+    @sp = FactoryGirl.create :system_picture
+    @lg = FactoryGirl.create :license_group
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @user = FactoryGirl.create :user_yas
+    @author = FactoryGirl.create :author, :user_id => @user.id
+  end
+  
+if MagicNumber['run_mode'] == 1
+  describe '一覧表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+      Sheet.stub(:list).and_return([@sheet, @sheet, @sheet])
+      sign_in @user
+    end
+    context '事前チェックする' do
+      it '与えられたpageがセットされている' do
+        get :index, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :index
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :index, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :index
+        assigns(:page_size).should eq Sheet.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 1500
+        assigns(:page_size).should eq Sheet.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 0
+        assigns(:page_size).should eq Sheet.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it '用紙モデルに一覧を問い合わせている' do
+        Sheet.should_receive(:list).exactly(1)
+        get :index
+      end
+      it '@sheetsにリストを取得している' do
+        get :index
+        assigns(:sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '用紙モデルにjson一覧出力オプションを問い合わせている' do
+          Sheet.should_receive(:list_json_opt).exactly(1)
+          get :index, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは用紙っぽいものであって欲しい' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("caption").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 :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :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 :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :index
+          response.should be_success 
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
+      Sheet.stub(:show).and_return(@sheet)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @sheet.id
+        response.should be_success
+      end
+      it '用紙モデルに単体取得を問い合わせている' do
+        Sheet.should_receive(:show).exactly(1)
+        get :show
+      end
+      it '@sheetにアレを取得している' do
+        get :show, :id => @sheet.id
+        assigns(:sheet).id.should eq(@sheet.id)
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sheet.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '用紙モデルにjson単体出力オプションを問い合わせている' do
+          Sheet.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @sheet.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @sheet.id, :format => :json
+          json = JSON.parse response.body
+          json["caption"].should match(/normal/)
+          json["visible"].should_not be_nil
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @sheet.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @sheet.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 :show, :id => @sheet.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @sheet.id
+          response.should be_success
+        end
+      end
+    end
+=begin
+    context '対象用紙がないとき' do
+      context 'html形式' do
+        it '例外404 not_foundを返す' do
+          lambda{
+            get :show, :id => 0
+          }.should raise_error(ActiveRecord::RecordNotFound)
+        end
+      end
+      context 'json形式' do
+        it '例外404 not_foundを返す' do
+          lambda{ 
+            get :show, :id => 0, :format => :json
+          }.should raise_error(ActiveRecord::RecordNotFound)
+        end
+      end
+    end
+    context '非公開用紙を見ようとしたとき' do
+      context 'html形式' do
+        it '例外403 forbiddenを返す' do
+          Sheet.any_instance.stub(:visible?).with(any_args()).and_return(false)
+          hidden = FactoryGirl.create :hidden_sheet, :author_id => @author.id
+          lambda{
+            get :show, :id => hidden
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+      context 'json形式' do
+        it '例外403 forbiddenを返す' do
+          Sheet.any_instance.stub(:visible?).with(any_args()).and_return(false)
+          hidden = FactoryGirl.create :hidden_sheet, :author_id => @author.id
+          lambda{
+            get :show, :id => hidden, :format => :json
+          }.should raise_error(ActiveRecord::Forbidden)
+        end
+      end
+    end
+=end
+  end
+  
+  describe '閲覧に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.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
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      SheetPanel.stub(:count).and_return(10)
+      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)
+        get :play, :id => @sheet.id
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '@sheet_panelsにリストを取得している' do
+        get :play, :id => @sheet.id
+        assigns(:sheet_panels).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :play, :id => @sheet.id
+          response.should be_success 
+        end
+        it 'sheetテンプレートを描画する' do
+          get :play, :id => @sheet.id
+          response.should render_template("sheet")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :play, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :play, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '紙コマモデルに紙コマリストのjson出力を問い合わせている' do
+          SheetPanel.should_receive(:list_as_json_text).exactly(1)
+          get :play, :id => @sheet.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :play, :id => @sheet.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいは紙コマっぽいものであって欲しい' do
+          get :play, :id => @sheet.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("sheet_id").should be_true
+          json.first.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :play, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :play, :id => @sheet.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :play, :id => @sheet.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :play, :id => @sheet.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 :play, :id => @sheet.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :play, :id => @sheet.id
+        response.should be_success 
+      end
+    end
+  end
+
+  describe '用紙数取得に於いて' do
+    before do
+      Sheet.should_receive(:visible_count).and_return(3)
+#      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :count, :format => :json
+        response.should be_success 
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :count, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'データがHash構造になっていて用紙数が1である' do
+          get :count, :format => :json
+          json = JSON.parse response.body
+          json["count"].should == 3
+        end
+      end
+    end
+  end
+
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :new
+        response.should be_success 
+      end
+      it '@sheetに新規データを用意している' do
+        get :new
+        assigns(:sheet).should be_a_new(Sheet)
+      end
+      it '用紙モデルにデフォルト値補充を依頼している' do
+        Sheet.any_instance.should_receive(:supply_default).exactly(1)
+        get :new
+      end
+      context 'html形式' do
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it '用紙モデルにjson単体出力オプションを問い合わせている' do
+          Sheet.should_receive(:show_json_opt).exactly(1)
+          get :new, :format => :json
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new, @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :new, @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+
+  describe '新規作成に於いて' do
+    before do
+      sign_in @user
+      @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
+    end
+    context '事前チェックしておく' do
+      it '用紙モデルにデフォルト値補充を依頼している' do
+        Sheet.any_instance.should_receive(:supply_default).exactly(1)
+        post :create, :sheet => @attr
+      end
+      it '用紙モデルにカラム値復元を依頼している' do
+        Sheet.any_instance.should_receive(:attributes=).exactly(1)
+        post :create, :sheet => @attr
+      end
+      it '用紙モデルに上書き補充を依頼している' do
+        Sheet.any_instance.should_receive(:overwrite).exactly(1)
+        post :create, :sheet => @attr
+      end
+      it 'モデルに保存依頼する' do
+        Sheet.any_instance.should_receive(:save).exactly(1)
+        post :create, :sheet => @attr
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it "@sheetに作成された用紙を保持していて、それがDBにある" do
+        post :create, :sheet => @attr
+        assigns(:sheet).should be_a(Sheet)
+        assigns(:sheet).should be_persisted
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Sheet.any_instance.stub(:save).and_return(true)
+          post :create, :sheet => @attr
+          response.status.should eq 302
+        end
+        it '作成された用紙の表示ページへ遷移する' do
+#          Sheet.any_instance.stub(:save).and_return(true)
+          post :create, :sheet => @attr
+          response.should redirect_to(Sheet.last)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Sheet.any_instance.stub(:save).and_return(true)
+          post :create, :sheet => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成された用紙をjsonデータで返す' do
+          post :create, :sheet => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'データがアレになっている' do
+          post :create, :sheet => @attr, :format => :json
+          json = JSON.parse response.body
+          json["caption"].should match(/normal/)
+          json["visible"].should_not be_nil
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :sheet => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          post :create, :sheet => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        Sheet.any_instance.stub(:save).and_return(false)
+      end
+      it "未保存の用紙を保持している" do
+        post :create, :sheet => @attr
+        assigns(:sheet).should be_a_new(Sheet)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          post :create, :sheet => @attr
+          response.status.should eq 200
+        end
+        it '新規ページを描画する' do
+          post :create, :sheet => @attr
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          post :create, :sheet => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          post :create, :sheet => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+      sign_in @user
+      Sheet.stub(:edit).and_return(@sheet)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :edit, :id => @sheet.id
+        response.should be_success 
+      end
+      it '用紙モデルに編集取得を問い合わせている' do
+        Sheet.should_receive(:edit).exactly(1)
+        get :edit, :id => @sheet.id
+      end
+      it '@sheetにデータを用意している' do
+        get :edit, :id => @sheet.id
+        assigns(:sheet).should eq @sheet
+      end
+      context 'html形式' do
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @sheet.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @sheet.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @sheet.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @sheet.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :edit, :id => @sheet.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author => @author
+      @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'updated caption', :visible => 0)
+      sign_in @user
+    end
+    context '事前チェックしておく' do
+      it '用紙モデルに編集取得を問い合わせている' do
+        Sheet.stub(:edit).with(any_args()).and_return @sheet
+        Sheet.should_receive(:edit).exactly(1)
+        put :update, :id => @sheet.id, :sheet => @attr
+      end
+      it '用紙モデルにカラム値復元を依頼している' do
+        Sheet.any_instance.should_receive(:attributes=).exactly(1)
+        put :update, :id => @sheet.id, :sheet => @attr
+      end
+      it '用紙モデルに上書き補充を依頼している' do
+        Sheet.any_instance.should_receive(:overwrite).exactly(1)
+        put :update, :id => @sheet.id, :sheet => @attr
+      end
+      it 'モデルに更新を依頼する' do
+        Sheet.any_instance.stub(:save).with(any_args).and_return true
+        Sheet.any_instance.should_receive(:save).exactly(1)
+        put :update, :id => @sheet.id, :sheet => @attr
+      end
+      it '@sheetにアレを取得している' do
+        put :update, :id => @sheet.id, :sheet => @attr
+        assigns(:sheet).id.should eq(@sheet.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '更新される' do
+        put :update, :id => @sheet.id, :sheet => @attr
+        Sheet.find(@sheet.id).visible.should eq 0
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.status.should eq 302
+        end
+        it '更新された用紙の表示ページへ遷移する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.should redirect_to(@sheet)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗したとき' do
+      before do
+        Sheet.any_instance.stub(:save).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 Okを返す' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          Sheet.any_instance.stub(:save).and_return(false)
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author => @author
+      sign_in @user
+    end
+    context '事前チェックしておく' do
+      before do
+        Sheet.stub(:edit).with(any_args()).and_return @sheet
+        Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
+      end
+      it '用紙モデルに編集取得を問い合わせている' do
+        Sheet.should_receive(:edit).exactly(1)
+        delete :destroy, :id => @sheet.id
+      end
+      it 'モデルに削除を依頼する' do
+        Sheet.any_instance.should_receive(:destroy_with_sheet_panel).exactly(1)
+        delete :destroy, :id => @sheet.id
+      end
+      it '@sheetにアレを取得している' do
+        delete :destroy, :id => @sheet.id
+        assigns(:sheet).id.should eq(@sheet.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '削除される' do
+        lambda {
+          delete :destroy, :id => @sheet.id
+        }.should change Sheet, :count
+      end
+      context 'html形式' do
+        before do
+          Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
+        end
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'マイ用紙の一覧ページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.should redirect_to('/home/sheets')
+        end
+      end
+      context 'json形式' do
+        before do
+          Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
+        end
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        Sheet.any_instance.stub(:destroy_with_sheet_panel).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'その用紙の詳細ページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.should redirect_to(sheet_path(@sheet))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+else
+  describe '一覧表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+      Sheet.stub(:list).and_return([@sheet, @sheet, @sheet])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id, :caption => 'normal'
+      Sheet.stub(:show).and_return(@sheet)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @sheet.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sheet.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :show, :id => @sheet.id
+        response.should be_success
+      end
+      context 'html形式' do
+        it 'showテンプレートを描画する' do
+          get :show, :id => @sheet.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :show, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  describe '用紙数取得に於いて' do
+    before do
+      Sheet.should_receive(:visible_count).and_return(3)
+      sign_out @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :count, :format => :json
+        response.should be_success 
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :count, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :new
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '新規作成に於いて' do
+    before do
+      sign_in @user
+      @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'normal')
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Sheet.any_instance.stub(:save).and_return(true)
+          post :create, :sheet => @attr
+          response.status.should eq 302
+        end
+        it '作成された用紙の表示ページへ遷移する' do
+#          Sheet.any_instance.stub(:save).and_return(true)
+          post :create, :sheet => @attr
+          response.should redirect_to(Sheet.last)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Sheet.any_instance.stub(:save).and_return(true)
+          post :create, :sheet => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成された用紙をjsonデータで返す' do
+          post :create, :sheet => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :sheet => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+      sign_in @user
+      Sheet.stub(:edit).and_return(@sheet)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :edit, :id => @sheet.id
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @sheet.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @sheet.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @sheet.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @sheet.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author => @author
+      @attr = FactoryGirl.attributes_for(:sheet, :author_id => @author.id, :caption => 'updated caption', :visible => 0)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.status.should eq 302
+        end
+        it '更新された用紙の表示ページへ遷移する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.should redirect_to(@sheet)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          Sheet.any_instance.stub(:save).with(any_args()).and_return(true)
+          put :update, :id => @sheet.id, :sheet => @attr, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード302 Foundを返す' do
+        put :update, :id => @sheet.id, :sheet => @attr
+        response.status.should eq 302
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          put :update, :id => @sheet.id, :sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @sheet = FactoryGirl.create :sheet, :author => @author
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        before do
+          Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
+        end
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @sheet.id
+          response.status.should eq 302
+        end
+        it 'マイ用紙の一覧ページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.should redirect_to('/home/sheet')
+        end
+      end
+      context 'json形式' do
+        before do
+          Sheet.any_instance.stub(:destroy_with_sheet_panel).with(any_args()).and_return(true)
+        end
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'ページ本体は特に返さない' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.body.should match /./
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード302 Foundを返す' do
+        delete :destroy, :id => @sheet.id
+        response.status.should eq 302
+      end
+      context 'html形式' do
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @sheet.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+end
 
 end
diff --git a/spec/controllers/stories_controller_spec.rb b/spec/controllers/stories_controller_spec.rb
new file mode 100644 (file)
index 0000000..7e7a4d4
--- /dev/null
@@ -0,0 +1,1456 @@
+# -*- encoding: utf-8 -*-
+require 'spec_helper'
+#ストーリー
+describe StoriesController do
+  before do
+    @admin = FactoryGirl.create :admin
+    @sp = FactoryGirl.create :system_picture
+    @lg = FactoryGirl.create :license_group
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @user = FactoryGirl.create :user_yas
+    @author = FactoryGirl.create :author, :user_id => @user.id
+    @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.stub(:list).and_return([@story, @story, @story])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :index, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :index
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :index, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :index
+        assigns(:page_size).should eq Story.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 1500
+        assigns(:page_size).should eq Story.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 0
+        assigns(:page_size).should eq Story.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it 'ストーリーモデルに一覧を問い合わせている' do
+        Story.should_receive(:list).exactly(1)
+        get :index
+      end
+      it '@storiesにリストを取得している' do
+        get :index
+        assigns(:stories).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :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 :index, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("comic_id").should be_true
+          json.first.has_key?("t").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :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 :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      Comic.stub(:show).with(@comic.id.to_s, [@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
+        Story.should_receive(:show).with(@story.id.to_s, [@user, nil]).exactly(1)
+        get :show, :id => @story.id
+      end
+      it '@storyにアレを取得している' do
+        get :show, :id => @story.id
+        assigns(:story).should eq @story
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @story.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @story.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルにストーリーjson出力を問い合わせている' do
+          Story.any_instance.should_receive(:story_as_json).exactly(1)
+          get :show, :id => @story.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @story.id, :format => :json
+          json = JSON.parse response.body
+          json.has_key?("panel_id").should be_true
+          json.has_key?("comic_id").should be_true
+          json.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @story.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @story.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '閲覧に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      Comic.stub(:show).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(:count).and_return(10)
+      Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
+      sign_in @user
+    end
+    context 'パラメータチェックする' do
+      it '与えられたoffsetがセットされている' do
+        get :comic, :id => @comic.id, :offset => 5
+        assigns(:offset).should eq 5
+      end
+      it '省略されると@offsetに0値が入る' do
+        get :comic, :id => @comic.id
+        assigns(:offset).should eq 0
+      end
+      it '与えられたcountがセットされている' do
+        get :comic, :id => @comic.id, :count => 4
+        assigns(:panel_count).should eq 4
+      end
+      it '省略されると@panel_countにデフォルト値が入る' do
+        get :comic, :id => @comic.id
+        assigns(:panel_count).should eq Story.default_panel_size
+      end
+      it '最大を超えると@panel_countにデフォルト最大値が入る' do
+        get :comic, :id => @comic.id, :count => 1500
+        assigns(:panel_count).should eq Story.max_panel_size
+      end
+      it '不正な値が入ると@panel_countにデフォルト最大値が入る' do
+        get :comic, :id => @comic.id, :count => -1
+        assigns(:panel_count).should eq Story.default_panel_size
+      end
+    end
+    context '事前チェックする' do
+      it 'コミックモデルに単体取得を問い合わせている' do
+        Comic.should_receive(:show).with(@comic.id.to_s, [@user, nil]).exactly(1)
+        get :comic, :id => @comic.id
+      end
+      it 'ストーリーモデルにプレイリスト取得を問い合わせている' do
+        Story.should_receive(:play_list).with(@comic, @author, 0, 30).exactly(1)
+        get :comic, :id => @comic.id
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it '@storiesにリストを取得している' do
+        get :comic, :id => @comic.id
+        assigns(:stories).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :comic, :id => @comic.id
+          response.should be_success 
+        end
+        it 'comicテンプレートを描画する' do
+          get :comic, :id => @comic.id
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルにストーリーリストのjson出力を問い合わせている' do
+          Story.should_receive(:list_as_json_text).exactly(1)
+          get :comic, :id => @comic.id, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :comic, :id => @comic.id, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do
+          get :comic, :id => @comic.id, :format => :json
+          json = JSON.parse response.body
+          json.first.has_key?("panel_id").should be_true
+          json.first.has_key?("comic_id").should be_true
+          json.first.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :comic, :id => @comic.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :comic, :id => @comic.id
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comic, :id => @comic.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :comic, :id => @comic.id
+        response.should be_success 
+      end
+    end
+  end
+
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it '@storyに新規データを用意している' do
+        get :new
+        assigns(:story).should be_a_new(Story)
+      end
+      it 'モデルにデフォルト値補充を依頼している' do
+        Story.any_instance.should_receive(:supply_default).exactly(1)
+        get :new
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
+          Story.any_instance.should_receive(:story_as_json).exactly(1)
+          get :new, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :new, :format => :json
+          json = JSON.parse response.body
+          json.has_key?("panel_id").should be_true
+          json.has_key?("comic_id").should be_true
+          json.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :new
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+  
+  describe '新規作成に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'デフォルト値補充を依頼する' do
+        Story.any_instance.should_receive(:supply_default).exactly(1)
+        post :create, :story => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        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)
+        post :create, :story => @attr
+      end
+      it 'コミックモデルに編集取得を依頼している' do
+        Comic.should_receive(:edit).with(@comic.id, @author).exactly(1)
+        post :create, :story => @attr
+      end
+      it 'コマモデルに単体取得を依頼している' do
+        Panel.should_receive(:show).with(@panel.id, @author).exactly(1)
+        post :create, :story => @attr
+      end
+      it 'モデルに保存依頼する' do
+        Story.any_instance.should_receive(:store).exactly(1)
+        post :create, :story => @attr
+      end
+      it "@storyに作成されたコマを保持していて、それが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)
+          post :create, :story => @attr
+          response.status.should eq 302
+        end
+        it 'コミックのストーリー表示へ遷移する' do
+#          Story.any_instance.stub(:store).and_return(true)
+          post :create, :story => @attr
+          response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Story.any_instance.stub(:store).and_return(true)
+          post :create, :story => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成されたコマをjsonデータで返す' do
+          post :create, :story => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'ストーリーモデルのストーリーのjson出力を問い合わせている' do
+          Story.any_instance.should_receive(:story_as_json).exactly(1)
+          post :create, :story => @attr, :format => :json
+        end
+        it 'データがアレになっている' do
+          post :create, :story => @attr, :format => :json
+          json = JSON.parse response.body
+          json["t"].should eq 0
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :story => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :story => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :story => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :story => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          post :create, :story => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        Story.any_instance.stub(:store).and_return(false)
+      end
+      it "未保存のコマを保持している" do
+        post :create, :story => @attr
+        assigns(:story).should be_a_new(Story)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          post :create, :story => @attr
+          response.status.should eq 200
+        end
+        it '新規ページを描画する' do
+          post :create, :story => @attr
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          post :create, :story => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          post :create, :story => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :author_id => @author.id
+      sign_in @user
+      Story.stub(:show).and_return(@story)
+    end
+    context 'つつがなく終わるとき' do
+      it 'ストーリーモデルに編集取得を問い合わせている' do
+        Story.should_receive(:edit).exactly(1)
+        get :edit, :id => @story.id
+      end
+      it '@storyにデータを用意している' do
+        get :edit, :id => @story.id
+        assigns(:story).should eq @story
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story.id
+          response.should be_success 
+        end
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @story.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story.id, :format => :js
+          response.should be_success 
+        end
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @story.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @story.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @story.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :edit, :id => @story.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :author_id => @user.author.id
+      @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'モデルに編集取得依頼する' do
+        Story.stub(:edit).with(any_args).and_return(@story)
+        Story.should_receive(:edit).exactly(1)
+        put :update, :id => @story.id, :story => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        Story.any_instance.stub(:store).and_return(true)
+        Story.any_instance.should_receive(:attributes=).exactly(1)
+        put :update, :id => @story.id, :story => @attr
+      end
+      it '上書き補充を依頼する' do
+        Story.any_instance.should_receive(:overwrite).exactly(1)
+        put :update, :id => @story.id, :story => @attr
+      end
+      it 'モデルに保存依頼する' do
+        Story.any_instance.should_receive(:store).exactly(1)
+        put :update, :id => @story.id, :story => @attr
+      end
+      it "@storyに作成されたストーリーを保持していて、それがDBにある" do
+        put :update, :id => @story.id, :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)
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 302
+        end
+        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])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Story.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @story.id, :story => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @story.id, :story => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          put :update, :id => @story.id, :story => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        Story.any_instance.stub(:store).and_return(false)
+      end
+      it "指定のコマを保持している" do
+        put :update, :id => @story.id, :story => @attr
+        assigns(:story).should eq @story
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @story.id, :story => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :author_id => @author.id
+      sign_in @user
+      Story.stub(:edit).and_return(@story)
+    end
+    context '事前チェックしておく' do
+      before do
+        Story.stub(:edit).with(any_args()).and_return @story
+        Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      it 'ストーリーモデルに編集取得を問い合わせている' do
+        Story.should_receive(:edit).exactly(1)
+        delete :destroy, :id => @story.id
+      end
+      it 'モデルに削除を依頼する' do
+        Story.any_instance.should_receive(:destroy_and_shorten).exactly(1)
+        delete :destroy, :id => @story.id
+      end
+      it '@storyにアレを取得している' do
+        delete :destroy, :id => @story.id
+        assigns(:story).id.should eq(@story.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it '閲覧ページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.should be_success
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'そのコミックの詳細ページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.should redirect_to(story_path(@story))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+=begin
+    context '対象ストーリーがないとき' do
+    end
+    context '他人のストーリーだったとき' do
+    end
+=end
+  end
+  
+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.stub(:list).and_return([@story, @story, @story])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      Comic.stub(:show).with(@comic.id.to_s, [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)
+      Story.stub(:show).with(@story.id.to_s, [nil, nil]).and_return(@story)
+      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
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @story.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @story.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @story.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @story.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '閲覧に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
+      Comic.stub(:show).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)
+      Story.stub(:count).and_return(10)
+      Story.stub(:play_list).with(any_args).and_return([@story, @story, @story])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :comic, :id => @comic.id
+          response.should be_success 
+        end
+        it 'comicテンプレートを描画する' do
+          get :comic, :id => @comic.id
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :comic, :id => @comic.id
+          response.should be_success 
+        end
+        it 'comicテンプレートを描画する' do
+          get :comic, :id => @comic.id
+          response.should render_template("comic")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :comic, :id => @comic.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '新規作成に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Story.any_instance.stub(:store).and_return(true)
+          post :create, :story => @attr
+          response.status.should eq 302
+        end
+        it 'コミックのストーリー表示へ遷移する' do
+#          Story.any_instance.stub(:store).and_return(true)
+          post :create, :story => @attr
+          response.should redirect_to(:action => :comic, :id => @attr[:comic_id])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Story.any_instance.stub(:store).and_return(true)
+          post :create, :story => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成されたコマをjsonデータで返す' do
+          post :create, :story => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :story => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :story => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :story => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :author_id => @author.id
+      sign_in @user
+      Story.stub(:show).and_return(@story)
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story.id
+          response.should be_success 
+        end
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @story.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story.id, :format => :js
+          response.should be_success 
+        end
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @story.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @story.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @story.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :author_id => @user.author.id
+      @attr = FactoryGirl.attributes_for(:story, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          Story.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 302
+        end
+        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])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          Story.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story.id, :story => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @story.id, :story => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @story.id, :story => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @story = FactoryGirl.create :story, :author_id => @author.id
+      sign_in @user
+      Story.stub(:edit).and_return(@story)
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        Story.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it '閲覧ページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.should redirect_to(:controller => 'stories', :action => :comic, :id => @story.comic_id)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.should be_success
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @story.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @story.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+end
+end
index 1ee00c8..9751c55 100644 (file)
+# -*- encoding: utf-8 -*-
 require 'spec_helper'
-
+#スト紙
 describe StorySheetsController do
+  before do
+    @admin = FactoryGirl.create :admin
+    @sp = FactoryGirl.create :system_picture
+    @lg = FactoryGirl.create :license_group
+    @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
+    @user = FactoryGirl.create :user_yas
+    @author = FactoryGirl.create :author, :user_id => @user.id
+    @comic = FactoryGirl.create :comic, :author_id => @user.author.id
+    @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id
+    @sheet = FactoryGirl.create :sheet, :author_id => @user.author.id
+  end
+  
+if MagicNumber['run_mode'] == 1
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
+      StorySheet.stub(:list).and_return([@story_sheet, @story_sheet, @story_sheet])
+    end
+    context 'パラメータpageについて' do
+      it '@pageに値が入る' do
+        get :index, :page => 5
+        assigns(:page).should eq 5
+      end
+      it '省略されると@pageに1値が入る' do
+        get :index
+        assigns(:page).should eq 1
+      end
+      it '与えられたpage_sizeがセットされている' do
+        get :index, :page_size => 15
+        assigns(:page_size).should eq 15
+      end
+      it '省略されると@page_sizeにデフォルト値が入る' do
+        get :index
+        assigns(:page_size).should eq StorySheet.default_page_size
+      end
+      it '最大を超えると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 1500
+        assigns(:page_size).should eq StorySheet.max_page_size
+      end
+      it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do
+        get :index, :page_size => 0
+        assigns(:page_size).should eq StorySheet.default_page_size
+      end
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      it 'スト紙モデルに一覧を問い合わせている' do
+        StorySheet.should_receive(:list).exactly(1)
+        get :index
+      end
+      it '@story_sheetsにリストを取得している' do
+        get :index
+        assigns(:story_sheets).should have_at_least(3).items
+      end
+      context 'html形式' do
+        it '@paginateにページ制御を取得している' do
+          get :index
+          assigns(:paginate).is_a?(Kaminari::PaginatableArray).should be_true
+        end
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :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 :index, :format => :json
+        end
+        it 'データがリスト構造になっている' do
+          get :index, :format => :json
+          json = JSON.parse response.body
+          json.should have_at_least(3).items
+        end
+        it 'リストの先頭くらいはスト紙っぽいものであって欲しい' do
+          get :index, :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
+          json.first.has_key?("t").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :index
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :index
+          response.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :index, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :index, :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 :index
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      StorySheet.stub(:show).with(@story_sheet.id.to_s, [@user, nil]).and_return(@story_sheet)
+      StorySheet.stub(:show).with(@story_sheet.id.to_s, [nil, @admin]).and_return(@story_sheet)
+    end
+    context 'つつがなく終わるとき' do
+      it 'スト紙モデルに単体取得を問い合わせている' do
+        StorySheet.should_receive(:show).with(@story_sheet.id.to_s, [@user, nil]).exactly(1)
+        get :show, :id => @story_sheet.id
+      end
+      it '@story_sheetにアレを取得している' do
+        get :show, :id => @story_sheet.id
+        assigns(:story_sheet).should eq @story_sheet
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @story_sheet.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スト紙モデルにjson単体出力オプションを問い合わせている' do
+          StorySheet.should_receive(:show_json_opt).exactly(1)
+          get :show, :id => @story_sheet.id, :format => :json
+        end
+        it 'データがアレになっている' do
+          get :show, :id => @story_sheet.id, :format => :json
+          json = JSON.parse response.body
+          json.has_key?("story_id").should be_true
+          json.has_key?("sheet_id").should be_true
+          json.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :show, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :show, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :show, :id => @story_sheet.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 :show, :id => @story_sheet.id
+        response.should be_success 
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id
+        response.should be_success 
+      end
+    end
+  end
+  
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it '@story_sheetに新規データを用意している' do
+        get :new
+        assigns(:story_sheet).should be_a_new(StorySheet)
+      end
+      it 'モデルにデフォルト値補充を依頼している' do
+        StorySheet.any_instance.should_receive(:supply_default).exactly(1)
+        get :new
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スト紙モデルにjson単体出力オプションを問い合わせている' do
+          StorySheet.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?("story_id").should be_true
+          json.has_key?("sheet_id").should be_true
+          json.has_key?("author_id").should be_true
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :new
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+  
+  describe '新規作成に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:story_sheet, :t => nil, :story_id => @story.id, :sheet_id => @sheet.id, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'デフォルト値補充を依頼する' do
+        StorySheet.any_instance.should_receive(:supply_default).exactly(1)
+        post :create, :story_sheet => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        StorySheet.any_instance.stub(:store).and_return(true)
+        post :create, :story_sheet => @attr
+        assigns(:story_sheet).story_id.should eq @story.id
+        assigns(:story_sheet).sheet_id.should eq @sheet.id
+      end
+      it '上書き補充を依頼する' do
+        StorySheet.any_instance.should_receive(:overwrite).exactly(1)
+        post :create, :story_sheet => @attr
+      end
+      it 'ストーリーモデルに編集取得を依頼している' do
+        Story.stub(:edit).and_return(@story)
+        Story.should_receive(:edit).with(@story.id, @author).exactly(1)
+        post :create, :story_sheet => @attr
+      end
+      it '用紙モデルに単体取得を依頼している' do
+        Sheet.should_receive(:show).with(@sheet.id, @author).exactly(1)
+        post :create, :story_sheet => @attr
+      end
+      it 'モデルに保存依頼する' do
+        StorySheet.any_instance.should_receive(:store).exactly(1)
+        post :create, :story_sheet => @attr
+      end
+      it "@story_sheetに作成されたストーリーを保持していて、それがDBにある" do
+        post :create, :story_sheet => @attr
+        assigns(:story_sheet).should be_a(StorySheet)
+        assigns(:story_sheet).should be_persisted
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          StorySheet.any_instance.stub(:store).and_return(true)
+          post :create, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'ストーリーのスト紙表示へ遷移する' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          post :create, :story_sheet => @attr
+          response.should redirect_to(play_story_path(@attr[:story_id]))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          post :create, :story_sheet => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成されたストーリーをjsonデータで返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+        it 'スト紙モデルにjson単体出力オプションを問い合わせている' do
+          StorySheet.should_receive(:show_json_opt).exactly(1)
+          post :create, :story_sheet => @attr, :format => :json
+        end
+        it 'データがアレになっている' do
+          post :create, :story_sheet => @attr, :format => :json
+          json = JSON.parse response.body
+          json["t"].should eq 0
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :story_sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :story_sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          post :create, :story_sheet => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        StorySheet.any_instance.stub(:store).and_return(false)
+      end
+      it "未保存のストーリーを保持している" do
+        post :create, :story_sheet => @attr
+        assigns(:story_sheet).should be_a_new(StorySheet)
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          post :create, :story_sheet => @attr
+          response.status.should eq 200
+        end
+        it '新規ページを描画する' do
+          post :create, :story_sheet => @attr
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
+      sign_in @user
+      StorySheet.stub(:show).and_return(@story_sheet)
+    end
+    context 'つつがなく終わるとき' do
+      it 'スト紙モデルに編集取得を問い合わせている' do
+        StorySheet.should_receive(:edit).exactly(1)
+        get :edit, :id => @story_sheet.id
+      end
+      it '@story_sheetにデータを用意している' do
+        get :edit, :id => @story_sheet.id
+        assigns(:story_sheet).should eq @story_sheet
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story_sheet.id
+          response.should be_success 
+        end
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @story_sheet.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.should be_success 
+        end
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          get :edit, :id => @story_sheet.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @user.author.id
+      @attr = FactoryGirl.attributes_for(:story_sheet, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      it 'モデルに編集取得依頼する' do
+        StorySheet.stub(:edit).with(any_args).and_return(@story_sheet)
+        StorySheet.should_receive(:edit).exactly(1)
+        put :update, :id => @story_sheet.id, :story_sheet => @attr
+      end
+      it 'POSTデータから、カラム値を復元している' do
+        StorySheet.any_instance.stub(:store).and_return(true)
+        StorySheet.any_instance.should_receive(:attributes=).exactly(1)
+        put :update, :id => @story_sheet.id, :story_sheet => @attr
+      end
+      it '上書き補充を依頼する' do
+        StorySheet.any_instance.should_receive(:overwrite).exactly(1)
+        put :update, :id => @story_sheet.id, :story_sheet => @attr
+      end
+      it 'モデルに保存依頼する' do
+        StorySheet.any_instance.should_receive(:store).exactly(1)
+        put :update, :id => @story_sheet.id, :story_sheet => @attr
+      end
+      it "@story_sheetに作成されたスト紙を保持していて、それがDBにある" do
+        put :update, :id => @story_sheet.id, :story_sheet => @attr
+        assigns(:story_sheet).should be_a(StorySheet)
+        assigns(:story_sheet).should be_persisted
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          StorySheet.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'スト紙表示へ遷移する' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.should redirect_to(play_story_path(@attr[:story_id]))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '検証、保存に失敗した' do
+      before do
+        StorySheet.any_instance.stub(:store).and_return(false)
+      end
+      it "指定のスト紙を保持している" do
+        put :update, :id => @story_sheet.id, :story_sheet => @attr
+        assigns(:story_sheet).should eq @story_sheet
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 200
+        end
+        it '編集ページを描画する' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.should render_template("edit")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
+      sign_in @user
+      StorySheet.stub(:edit).and_return(@story_sheet)
+    end
+    context '事前チェックしておく' do
+      before do
+        StorySheet.stub(:edit).with(any_args()).and_return @story_sheet
+        StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      it 'スト紙モデルに編集取得を問い合わせている' do
+        StorySheet.should_receive(:edit).exactly(1)
+        delete :destroy, :id => @story_sheet.id
+      end
+      it 'モデルに削除を依頼する' do
+        StorySheet.any_instance.should_receive(:destroy_and_shorten).exactly(1)
+        delete :destroy, :id => @story_sheet.id
+      end
+      it '@story_sheetにアレを取得している' do
+        delete :destroy, :id => @story_sheet.id
+        assigns(:story_sheet).id.should eq(@story_sheet.id)
+      end
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it '閲覧ページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.should redirect_to(play_story_path(@story_sheet.story_id))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.should be_success
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+    context 'ユーザ権限はないが管理者権限があるとき' do
+      before do
+        sign_out @user
+        sign_in @admin
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+    end
+    context 'ユーザだが作家登録していないとき' do
+      before do
+        @author.destroy
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it '作家登録ページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.body.should redirect_to new_author_path
+        end
+      end
+    end
+    context '削除に失敗したとき' do
+      before do
+        StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(false)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'その用紙の詳細ページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.should redirect_to(story_sheet_path(@story_sheet))
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード422 unprocessable_entity を返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.status.should eq 422
+        end
+        it '応答メッセージUnprocessable Entityを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.message.should match(/Unprocessable/)
+        end
+      end
+    end
+=begin
+    context '対象スト紙がないとき' do
+    end
+    context '他人のスト紙だったとき' do
+    end
+=end
+  end
+  
+else
+  describe '一覧表示に於いて' do
+    before do
+      sign_in @user
+      @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id
+      StorySheet.stub(:list).and_return([@story_sheet, @story_sheet, @story_sheet])
+    end
+    context 'つつがなく終わるとき' do
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      it 'ステータスコード200 OKを返す' do
+        get :index
+        response.should be_success 
+      end
+      context 'html形式' do
+        it 'indexテンプレートを描画する' do
+          get :index
+          response.should render_template("index")
+        end
+      end
+      context 'json形式' do
+        it 'jsonデータを返す' do
+          get :index, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '単体表示に於いて' do
+    before do
+      sign_in @user
+      @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      StorySheet.stub(:show).with(@story_sheet.id.to_s, [nil, nil]).and_return(@story_sheet)
+      StorySheet.stub(:show).with(@story_sheet.id.to_s, [@user, nil]).and_return(@story_sheet)
+      StorySheet.stub(:show).with(@story_sheet.id.to_s, [nil, @admin]).and_return(@story_sheet)
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @story_sheet.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id
+          response.should be_success
+        end
+        it 'showテンプレートを描画する' do
+          get :show, :id => @story_sheet.id
+          response.should render_template("show")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          response.should be_success
+        end
+        it 'jsonデータを返す' do
+          get :show, :id => @story_sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
+  
+  describe '閲覧に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :t => 0, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [@user, nil]).and_return(@sheet)
+      Sheet.stub(:show).with(@sheet.id.to_s, [nil, @admin]).and_return(@sheet)
+      StorySheet.stub(:count).and_return(10)
+      StorySheet.stub(:play_list).with(any_args).and_return([@story_sheet, @story_sheet, @story_sheet])
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id
+          response.should be_success 
+        end
+        it 'sheetテンプレートを描画する' do
+          get :sheet, :id => @sheet.id
+          response.should render_template("sheet")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id
+          response.should be_success 
+        end
+        it 'sheetテンプレートを描画する' do
+          get :sheet, :id => @sheet.id
+          response.should render_template("sheet")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :sheet, :id => @sheet.id, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+  end
 
+  describe '新規作成フォーム表示に於いて' do
+    before do
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new
+          response.should be_success 
+        end
+        it 'newテンプレートを描画する' do
+          get :new
+          response.should render_template("new")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :js
+          response.should be_success 
+        end
+        it 'new.jsテンプレートを描画する' do
+          get :new, :format => :js
+          response.should render_template("new")
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :new, :format => :json
+          response.should be_success 
+        end
+        it 'jsonデータを返す' do
+          get :new, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :new
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :new
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :new, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :new, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+  describe '新規作成に於いて' do
+    before do
+      @attr = FactoryGirl.attributes_for(:story_sheet, :t => nil, :sheet_id => @sheet.id, :story_id => @story.id, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          StorySheet.any_instance.stub(:store).and_return(true)
+          post :create, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it '用紙のスト紙表示へ遷移する' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          post :create, :story_sheet => @attr
+          response.should redirect_to(:action => :sheet, :id => @attr[:sheet_id])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          post :create, :story_sheet => @attr, :format => :json
+          response.should be_success 
+        end
+        it '作成されたストーリーをjsonデータで返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError)
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          post :create, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          post :create, :story_sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          post :create, :story_sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '編集フォーム表示に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
+      sign_in @user
+      StorySheet.stub(:show).and_return(@story_sheet)
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story_sheet.id
+          response.should be_success 
+        end
+        it 'editテンプレートを描画する' do
+          get :edit, :id => @story_sheet.id
+          response.should render_template("edit")
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード200 OKを返す' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.should be_success 
+        end
+        it 'edit.jsテンプレートを描画する' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.should render_template("edit")
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          get :edit, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          get :edit, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'js形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          get :edit, :id => @story_sheet.id, :format => :js
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '更新に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @user.author.id
+      @attr = FactoryGirl.attributes_for(:story_sheet, :author_id => @author.id)
+      sign_in @user
+    end
+    context 'つつがなく終わるとき' do
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          StorySheet.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'スト紙表示へ遷移する' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.should redirect_to(:action => :sheet, :id => @attr[:sheet_id])
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+#          StorySheet.any_instance.stub(:store).and_return(true)
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.should be_success 
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          put :update, :id => @story_sheet.id, :story_sheet => @attr, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+
+  describe '削除に於いて' do
+    before do
+      @story_sheet = FactoryGirl.create :story_sheet, :author_id => @author.id
+      sign_in @user
+      StorySheet.stub(:edit).and_return(@story_sheet)
+    end
+    context 'つつがなく終わるとき' do
+      before do
+        StorySheet.any_instance.stub(:destroy_and_shorten).with(any_args()).and_return(true)
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it '閲覧ページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.should redirect_to(:controller => 'story_sheets', :action => :sheet, :id => @story_sheet.sheet_id)
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード200 OKを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.should be_success
+        end
+      end
+    end
+    context 'ユーザ権限がないとき' do
+      before do
+        sign_out @user
+      end
+      context 'html形式' do
+        it 'ステータスコード302 Foundを返す' do
+          delete :destroy, :id => @story_sheet.id
+          response.status.should eq 302
+        end
+        it 'サインインページへ遷移する' do
+          delete :destroy, :id => @story_sheet.id
+          response.body.should redirect_to '/users/sign_in'
+        end
+      end
+      context 'json形式' do
+        it 'ステータスコード401 Unauthorizedを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.status.should eq 401
+        end
+        it '応答メッセージにUnauthorizedを返す' do
+          delete :destroy, :id => @story_sheet.id, :format => :json
+          response.message.should match(/Unauthorized/)
+        end
+      end
+    end
+  end
+  
+end
 end