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;
}
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
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])
@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
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
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
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 }
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
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)
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)
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)
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
@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
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
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
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
@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
@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)
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)
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)
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
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
#コミック
class Comic < ActiveRecord::Base
- has_many :stories
+ has_many :stories, :order => 't'
belongs_to :author
validates :title, :presence => true, :length => {:maximum => 100}
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
def supply_default
self.sheet_id = nil
self.panel_id = nil
+ self.x = 15
+ self.y = 15
+ self.z = 1
self.t = nil
end
self.visible > 0
end
+ def disp_t
+ self.t + 1
+ end
+
def self.default_page_size
25
end
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
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
['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
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 => {},
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
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
</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>
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
<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>
<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 %>
--- /dev/null
+<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 %>
<%= 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>
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
</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
<% 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
<% 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>
<% 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 %>
<%= 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 %>
<%= 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>
<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>
<%= 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 %>
<%= 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) %>
<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| %>
<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 %>
+++ /dev/null
-<% @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 %>
<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>
<%= 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>
<%= 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 -%>
<% 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 %>
<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 %>
--- /dev/null
+<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>
--- /dev/null
+<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>
--- /dev/null
+<%= 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 %>
--- /dev/null
+ <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>
--- /dev/null
+<%= 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 %>
--- /dev/null
+<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>
--- /dev/null
+<% 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>
--- /dev/null
+<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 %>
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<%= render 'form' %>
--- /dev/null
+$("#sheet_panel-update-<%= @sheet_panel.id -%>").html("<%= escape_javascript(render('editform')) -%>");
--- /dev/null
+<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 %>
--- /dev/null
+<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>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
--- /dev/null
+<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 %>
--- /dev/null
+<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>
--- /dev/null
+<%= 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 %>
--- /dev/null
+<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>
--- /dev/null
+<%= 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>
--- /dev/null
+<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 %>
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<%= render 'form' %>
--- /dev/null
+$("#newsheet").html("<%= escape_javascript(render('form')) -%>");
--- /dev/null
+<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 %>
--- /dev/null
+<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>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
+
+<%= link_to t('link.back'), sheets_path %>
--- /dev/null
+$("#newsheet").html("<%= escape_javascript(render('form')) -%>");
--- /dev/null
+<% @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 %>
--- /dev/null
+<% @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 %>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
-
+++ /dev/null
-<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>
<%= 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">
<%= 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) %>
<%= 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>
<td>
<%= l story.updated_at %>
</td>
- <td>
- <% if story.panel %>
- <%= h story.panel.caption %>
- <% end %>
- </td>
</tr>
<%= 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 %>
--- /dev/null
+<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>
</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>
+++ /dev/null
-<% @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 %>
<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 %>
<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>
<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>
--- /dev/null
+<% @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 %>
<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 %>
--- /dev/null
+<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>
--- /dev/null
+<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>
--- /dev/null
+<%= 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 %>
--- /dev/null
+ <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>
--- /dev/null
+<%= 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 %>
--- /dev/null
+<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>
--- /dev/null
+<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>
+
--- /dev/null
+<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 %>
--- /dev/null
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<%= render 'form' %>
+<%= button_to 'Destroy', @story_sheet, confirm: 'Are you sure?', method: :delete %>
--- /dev/null
+$("#sheet_panel-update-<%= @sheet_panel.id -%>").html("<%= escape_javascript(render('editform')) -%>");
--- /dev/null
+<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 %>
--- /dev/null
+<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>
+
--- /dev/null
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
--- /dev/null
+<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 %>
+
<%= 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
user: ユーザ
admin: 管理者
demand_user: 借手
- scroll: コミック
- scroll_panel: ストーリー
+ scroll: スクロール
+ scroll_panel: スクコマ
+ comic: コミック
+ story: ストーリー
+ story_sheet: スト紙
+ sheet: 用紙
+ sheet_panel: 紙コマ
panel: コマ
panel_picture: コマ絵
speech_balloon: フキダシ
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: 高さ
visible:
private: 非公開
public: 公開
+ comic:
+ visible:
+ private: 非公開
+ public: 公開
+ story:
+ visible:
+ private: 非公開
+ public: 公開
+ sheet:
+ visible:
+ private: 非公開
+ public: 公開
panel:
visible:
private: 非公開
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:
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:
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:
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:
tab:
creator:
home: 作る・見せる
- scroll: コミック
+ comic: コミック
+ story: ストーリー
+ sheet: 用紙
+ scroll: スクロール
panel: コマ
original_picture: 原画
resource_picture: 素材
['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]
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
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
get :list
end
member do
+ get :play
get :edit
put :update
delete :destroy
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)
--- /dev/null
+# -*- 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
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
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
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
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
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
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
# -*- 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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])
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])
# -*- 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
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
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
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
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
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
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{
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)
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
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
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
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
@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
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
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)
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
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
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
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
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
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
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
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
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
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)
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
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
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
+# -*- 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
+# -*- 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
--- /dev/null
+# -*- 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
+# -*- 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