class HomeController < ApplicationController
layout 'test' if MagicNumber['test_layout']
before_filter :authenticate_user!, :only => [
- :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3,
- :comic, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
+ :index, :show, :profile, :configure, :create_token, :delete_token,
+ :comic, :story, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
]
before_filter :authenticate_author, :only => [
- :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3,
- :comic, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
+ :index, :show, :profile, :configure, :create_token, :delete_token,
+ :comic, :story, :panel, :picture, :panel_picture, :panel_color, :ground_picture, :ground_color
]
before_filter :authenticate_artist, :only => [:picture]
end
end
- def step2
- end
-
- def save_step2
- respond_to do |format|
- if @author.step2(params[:author][:name])
- a = if params[:step3].to_i == 1
- :step3
- else
- :index
- end
- format.html { redirect_to({:action => a}, {:notice => 'your name was successfully updated.'}) }
- else
- format.html { render action: "step2" }
- end
- end
- end
-
- def step3
- end
-
- def save_step3
- if @author.artist?
- redirect_to :action => :index
- else
- @artist = Artist.new params[:artist]
- respond_to do |format|
- if @artist.save
- format.html { redirect_to({:action => :index}, {:notice => 'artist was successfully registered.'}) }
- else
- format.html { render action: "step3" }
- end
- end
- end
- end
-
def comic
@page = Author.page params[:page]
@page_size = Author.comic_page_size params[:page_size]
end
end
+ def story
+ @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 # index.html.erb
+ format.json { render text: Story.list_as_json_text(@stories) }
+ end
+ end
+
def panel
@page = Author.page params[:page]
@page_size = Author.panel_page_size params[:page_size]
t(MagicNumber[name][index][0])
end
+ def icon_tag name, opt = {}
+ title = opt[:object] ? (name.to_s + ' ID:' + opt[:object].id.to_s) : name
+ size = opt[:size] ? opt[:size].to_i : 35
+ tag :img, :src => asset_path(name.to_s.downcase + '.gif'), :width => size, :height => size, :alt => name.to_s + ' Icon', :title => title
+ end
+
+ def author_icon opt = {}
+ icon_tag :Author, opt
+ end
+
+ def artist_icon opt = {}
+ icon_tag :Artist, opt
+ end
+
+ def comic_icon opt = {}
+ icon_tag :Comic, opt
+ end
+
+ def story_icon opt = {}
+ icon_tag :Story, opt
+ end
+
+ def panel_icon opt = {}
+ icon_tag :Panel, opt
+ end
+
end
validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
def supply_default
+ self.comic_id = nil
+ self.panel_id = nil
self.t = nil
end
opt = {}
opt.merge!(self.list_opt)
opt.merge!({:limit => page_size, :offset => (page -1) * page_size}) if page_size > 0
- opt.merge!({:order => 'updated_at desc'})
+ opt.merge!({:conditions => ['comics.visible > 0'], :order => 'stories.updated_at desc'})
Story.find(:all, opt)
end
<%= render 'system/error_explanation', :obj => @comic %>
<div class="field">
- <%= f.label :author_id %><br />
- <%= h @author.name %>
- </div>
- <div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<%= f.label :visible %><br />
<%= f.collection_select :visible, t_select_items(MagicNumber['comic_visible_items']), :last, :first, :html => {:selected => @comic.visible} %>
</div>
-
+ <div class="field">
+ <%= f.label :author_id %><br />
+ <%= h @author.name %>
+ </div>
<div class="actions">
<%= f.submit %>
</div>
<tr>
<td>
- <%= link_to t('link.marker'), comic_path(comic) %>
+ <%= 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 %>
+ (<%= comic.stories.size -%>)
</td>
<td>
- <%= link_to h(truncate(comic.author.name, :length => 12)), author_path(comic.author) %>
+ <%= distance_of_time_in_words_to_now comic.updated_at %>
</td>
<td>
- <%= distance_of_time_in_words_to_now comic.updated_at %>
+ <%= link_to author_icon(:object => comic.author, :size => 25), comic_path(comic.author) %>
+ <%= link_to h(truncate(comic.author.name, :length => 12)), author_path(comic.author) %>
</td>
<td>
<% if comic.own? author %>
<%= link_to t('link.edit'), edit_comic_path(comic) %>
- <%= link_to t('link.destroy'), comic_path(comic), :method => :dellete %>
+ <%= link_to t('link.destroy'), comic_path(comic), :method => :delete %>
<% end %>
</td>
</tr>
<h1><%= t('.title') %></h1>
<%= render 'form' %>
-<%= link_to t('link.back'), comics_path %>
<h1><%= t '.title' -%></h1>
<table>
- <tr>
- <th><%= t_m 'Comic.title' -%></th>
- <th><%= t_m 'Comic.author_id' -%></th>
- <th><%= t_m 'Comic.updated_at' -%></th>
- <th> </th>
- </tr>
<% @comics.each do |comic| %>
<%= render 'list_item', :comic => comic, :author => @author %>
<% end %>
</table>
-<%= link_to t('.new'), new_comic_path %>
+<%= link_to t('comics.new.title'), new_comic_path %>
</p>
<%= link_to t('link.edit'), edit_comic_path(@comic) %>
-
-<%= link_to t('link.back'), comics_path %>
<h1><%= t '.title' -%></h1>
<table>
- <tr>
- <th><%= t_m 'Comic.title' -%></th>
- <th><%= t_m 'Comic.author_id' -%></th>
- <th><%= t_m 'Comic.updated_at' -%></th>
- <th>edit</th>
- </tr>
<% @comics.each do |comic| %>
<%= render 'comics/list_item', :comic => comic, :author => @author %>
<% end %>
</table>
-<%= link_to t('.new'), new_comic_path %>
+<%= link_to t('comics.new.title'), new_comic_path %>
-<h1>Listing My panels</h1>
+<h1><%= t '.title' -%></h1>
<% @panels.each do |panel| %>
<div>
<%= render 'panels/standard', :panel => panel, :author => @author %>
</div>
<% end %>
+<%= link_to t('panels.new.title'), new_panel_path %>
+++ /dev/null
-<h1>ようこそ、ぺったんRへ</h1>
-<div>
-<%= h(@user.email) -%>さんはぺったんRで作家としてデビューしました。
-今すぐにでも作品を作れますが、より良い活動をするために作家名を登録してください。
-</div>
-<%= form_for(:author, :url => {:controller => '/home', :action => :save_step2}) do |f| %>
- <% if @author.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@author.errors.count, "error") %> prohibited this original_license from being saved:</h2>
-
- <ul>
- <% @author.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </div>
- <p>あなたの素材を投稿してみませんか?</p>
- 絵師としての情報を登録すれば、あなたのキャラクターを漫画に登場させるなど、幅広い創作活動ができます。
- <div class="field">
- <%= check_box_tag 'step3', 1, false %> 引き続き、絵師登録を行う
- </div>
-
- <div class="actions">
- <%= f.submit '次のステップへ' %>
- </div>
-<% end %>
+++ /dev/null
-<h1>ようこそ、ぺったんRへ</h1>
-<%= h(@author.name) -%>さん
-<div>
- <%= form_for(:artist, :url => {:controller => '/home', :action => :save_step3}) do |f| %>
- <% if @artist.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:</h2>
-
- <ul>
- <% @artist.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <p>作家名とは別に絵師としてのペンネームを設定できます。</p>
- <%= f.label :name %><br />
- <%= f.text_field :name %><br />
-
- <%= f.hidden_field :author_id, :value => @artist.author_id %>
- </div>
- <div class="actions">
- <%= f.submit '完了' %>
- </div>
- <% end %>
-</div>
--- /dev/null
+<h1><%= t '.title' -%></h1>
+
+<table>
+ <% @stories.each do |story| %>
+ <%= render 'stories/list_item', :story => story, :author => @author %>
+ <% end %>
+</table>
+<%= link_to t('stories.new.title'), new_story_path %>
<table class="no-border">
<tr>
<td>
- <%= link_to '■', panel_path(panel) %>
- </td>
- <td>
- <%= link_to h(panel.author.name), author_path(panel.author) %>
- </td>
- <td>
- <%= panel.width %>x<%= panel.height %>
- </td>
- <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) %>
<%= l panel.updated_at %>
</td>
<td>
<% if panel.own? author %>
- <%= link_to 'edit', edit_panel_path(panel) %>
- <%= link_to 'destroy', panel_path(panel), :method => :delete %>
+ <%= link_to t('link.edit'), edit_panel_path(panel) %>
<% end %>
</td>
</tr>
<%= form_tag( {:controller => 'panels',:action => "create"}) do %>
<%= render 'system/error_explanation', :obj => @panel %>
- <label for="json">json data</label> <%= text_field_tag "json" %>
- <%= submit_tag 'upload' -%>
+ <div>
+ <label for="json">json data</label>
+ </div>
+ <%= text_field_tag "json" %>
+ <div>
+ <%= submit_tag t('panels.create_from_json') -%>
+ </div>
<% end -%>
-<h1>コマの編集</h1>
+<h1><%= t '.title' -%></h1>
<%= render 'standard', :panel => @panel, :author => @author %>
<%= render 'form' %>
+<%= link_to t('link.destroy'), panel_path(@panel), :method => :delete %>
<% @panels.each do |panel| %>
<%= render 'standard', :panel => panel, :author => @author %>
<% end %>
-<%= link_to 'open form', new_panel_path, :remote => true %>
- <div id="newpanel">
- ...
- </div>
+<%= link_to t('panels.new.title'), new_panel_path %>
-<h1>コマの新規作成</h1>
+<h1><%= t '.title' -%></h1>
<%= render 'form' %>
-<h1>コマの表示</h1>
+<h1><%= t '.title' -%></h1>
<p id="notice"><%= notice %></p>
<%= render 'standard', :panel => @panel, :author => @author %>
-<%= link_to 'Back', panels_path %>
+<%= link_to t('link.edit'), edit_panel_path(@panel) %>
+<%= link_to t('link.destroy'), panel_path(@panel), :method => :delete %>
--- /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
-<%= form_for(@story) do |f| %>
- <%= render 'system/error_explanation', :obj => @story %>
-
- <div class="field">
- <%= f.hidden_field :comic_id %>
- </div>
- <div class="field">
- <%= f.number_field :t %>
- </div>
- <div class="field">
- <%= f.hidden_field :panel_id %>
- </div>
-
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
-<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
--- /dev/null
+<table class="no-border" style="margin: 0px; padding: 0px; width=100%">
+ <tr>
+ <td>
+ <%= 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 %>
+ </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>
<%= render 'system/error_explanation', :obj => @story %>
<div class="field">
+ <%= f.label :comic_id %><br />
<%= f.number_field :comic_id %>
</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>
+++ /dev/null
-<table class="no-border">
- <tr>
- <td>
- No.<%= link_to story.t, story_path(story) %>:
- </td>
- <td>
- <%= link_to h(story.panel.author.name), author_path(story.panel.author) %>
- </td>
- <td>
- <%= story.updated_at %>
- </td>
- <td>
- <% if story.own? @author -%>
- <%= link_to 'edit', edit_story_path(story), :remote => true %>
- <span id="story-update-<%= @story.id -%>">
- ...
- </span>
- <% end -%>
- </td>
- </tr>
-</table>
<table class="no-border">
<tr>
<td>
- <%= link_to(tag(:img, picture.opt_img_tag), picture_path(picture.id)) -%>
+ <%= link_to(tag(:img, picture.tmb_opt_img_tag), picture_path(picture.id)) -%>
</td>
<td>
<%= render picture.credit_template, :picture => picture %>
--- /dev/null
+<table class="no-border" style="margin: 0px; padding: 0px; width=100%">
+ <tr>
+ <td>
+ <div>
+ <%= link_to comic_icon(:object => story.comic, :size => 25), comic_path(story.comic) %>
+ <%= link_to h(story.comic.title), :controller => 'stories', :action => :comic, :id => story.comic.id %>
+ </div>
+ <%= link_to author_icon(:object => story.comic.author, :size => 17), author_path(story.comic.author) %>
+ </td>
+ <td>
+ <div>
+ <%= link_to story_icon(:object => story, :size => 25), story_path(story) %>
+ <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %>
+ </div>
+ <div>
+ No.<%= story.t %>
+ <%= l story.updated_at %>
+ </div>
+ </td>
+ <td>
+ <% if story.panel %>
+ <%= render 'panels/standard', :panel => story.panel, :author => @author %>
+ <% end %>
+ </td>
+ </tr>
+</table>
-<%= form_for(@story) do |f| %>
- <% if @story.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@story.errors.count, "error") %> prohibited this comic from being saved:</h2>
-
- <ul>
- <% @story.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.hidden_field :comic_id %>
- </div>
- <div class="field">
- <%= f.number_field :t %>
- </div>
- <div class="field">
- <%= f.hidden_field :panel_id %>
- </div>
-
- <div class="actions">
- <%= f.submit %>
- </div>
+<%= 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 %>
-<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
-<h1><%= h @comic.title %> <%= link_to 'p', comic_path(@comic) %> <%= link_to 'edit', edit_comic_path(@comic) %></h1>
+<h1><%= t '.title' -%></h1>
+<%= render 'comic_header', :comic => @comic, :author => @author %>
-<% @stories.each do |story| %>
- <% @story = story %>
- <%= render 'header', :story => story, :author => @author %>
- <%= render 'panels/body', :panel => story.panel, :author => @author %>
- <%= render 'panels/footer', :panel => story.panel, :author => @author %>
+<% if @stories.empty? -%>
+ <h2><%= t('stories.comic.empty') %></h2>
+<% else %>
+ <% @stories.each do |story| %>
+ <%= render 'panels/body', :panel => story.panel, :author => @author %>
+ <%= render 'footer', :story => story, :author => @author %>
+ <% end %>
+ <%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %>
<% end %>
-<%= render 'licensed_pictures', :licensed_pictures => Story.licensed_pictures(@stories) %>
<% if @comic.own? @author -%>
- <%= link_to 'add panel', new_story_path, :remote => true %>
- <div id="story-create">
- t
+ <h3><%= t('stories.new.title') %></h3>
+ <% @story = Story.new ; @story.comic_id = @comic.id ; @story.t = Story.new_t @comic.id -%>
+ <%= form_for(@story) do |f| %>
+
+ <div class="field">
+ <%= f.hidden_field :comic_id %>
+ </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 %>
<% end %>
-<%= link_to 'Back', comics_path %>
-<%= render 'editform' %>
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
+<%= button_to 'Destroy', @story.panel, confirm: 'Are you sure?', method: :delete %>
<h1><%= t '.title' -%></h1>
<% @stories.each do |story| %>
- <%= render 'panels/standard', :panel => story.panel, :author => @author %>
+ <%= render 'list_item', :story => story, :author => @author %>
<% end %>
+<%= link_to t('stories.new.title'), new_story_path %>
-<%= render 'newform' %>
+<h1><%= t('.title') %></h1>
+
+<%= render 'form' %>
- <%= render 'panels/standard', :panel => @story.panel, :author => @author %>
- <% if @story.author.id == @author.id -%>
- <span>
- t:<%= @story.t %>
- </span>
-<%= button_to 'Destroy', @story, confirm: 'Are you sure?', method: :delete %>
- <%= render 'editform' %>
- <%= link_to 'open js', edit_story_path(@story), :remote => true %>
- <div id="story-update-<%= @story.id -%>">
- t
- </div>
- <% end -%>
-<% if @story.comic.own? @author -%>
- <%= link_to 'add panel', new_story_path, :remote => true %>
- <div id="story-create">
- t
- </div>
+<h1><%= t('.title') %></h1>
+<p id="notice"><%= notice %></p>
+
+<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 %>
+</p>
+
+<p>
+ <b><%= t_m 'Story.panel_id' -%>:</b>
+ <%= link_to panel_icon(:object => @story.panel), panel_path(@story.panel) %>
+</p>
+
+<p>
+ <b><%= t_m 'Story.t' -%>:</b>
+ <%= @story.t %>
+</p>
+
+<p>
+ <b><%= t_m 'Story.author_id' -%>:</b>
+ <%= link_to author_icon(:object => @story.author), author_path(@story.author) %>
+ <%= link_to h(@story.author.name), author_path(@story.author) %>
+</p>
+
+<p>
+ <b><%= t_m 'Story.created_at' -%>:</b>
+ <%= l @story.created_at %>
+</p>
+
+<p>
+ <b><%= t_m 'Story.updated_at' -%>:</b>
+ <%= l @story.updated_at %>
+</p>
+<% if @story.own? @author -%>
+ <%= link_to t('link.edit'), edit_story_path(@story) %>
<% end %>
+
+<hr>
+<%= render 'panels/standard', :panel => @story.panel, :author => @author %>
updated_picture: 最近更新した画像
comic:
title: 最近更新したコミック
+ story:
+ title: 最近更新したストーリー
panel:
title: 最近更新したコマ
picture:
title: ストーリー追加
edit:
title: 並び替え
+ comic:
+ title: コミックを読む
+ empty: ストーリーはありません
list:
title: ストーリー 生一覧
browse:
title: ストーリー 生単票
+ move: 移動
panels:
index:
title: コマ一覧
title: コマ詳細
new:
title: コマ作成
+ edit:
+ title: コマ編集
list:
title: コマ 生一覧
browse:
title: コマ 生単票
+ create_from_json: jsonデータからコマ作成する
panel_pictures:
index:
title: コマ絵一覧
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
+ 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 '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
end
describe '単体表示に於いて' do
end
end
- describe '一覧取得に於いて' do
+ describe 'プレイリスト取得に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
describe 'json一覧出力オプションに於いて' do
end
+ describe '一覧取得に於いて' do
+ before do
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
+ @panel = FactoryGirl.create :panel, :author_id => @author.id
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
+ @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
+ end
+ context 'page補正について' do
+ it '文字列から数値に変換される' do
+ Story.page('8').should eq 8
+ end
+ it 'nilの場合は1になる' do
+ Story.page().should eq 1
+ end
+ it '0以下の場合は1になる' do
+ Story.page('0').should eq 1
+ end
+ end
+ context 'page_size補正について' do
+ it '文字列から数値に変換される' do
+ Story.page_size('7').should eq 7
+ end
+ it 'nilの場合はStory.default_page_sizeになる' do
+ Story.page_size().should eq Story.default_page_size
+ end
+ it '0以下の場合はStory.default_page_sizeになる' do
+ Story.page_size('0').should eq Story.default_page_size
+ end
+ it 'Story.max_page_sizeを超えた場合はStory.max_page_sizeになる' do
+ Story.page_size('1000').should eq Story.max_page_size
+ end
+ end
+ it 'リストを返す' do
+ c = Story.list
+ c.should eq [@story]
+ end
+ it '時系列で並んでいる' do
+ #公開コミックのStoryは(他人のStoryであっても)含んでいる
+ v = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 0, :updated_at => Time.now + 100
+ c = Story.list
+ c.should eq [ v, @story]
+ end
+ it '非公開のストーリーは(自分のストーリーであっても)含まない' do
+ h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hidden_comic.id, :panel_id => @panel.id, :t => 0
+ c = Story.list
+ c.should eq [ @story]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+ @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
+ @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
+ @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+ end
+ it '通常は2件を返す' do
+ l = Story.list 1, 2
+ l.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ l = Story.list 1, 2
+ l.should eq [@story5, @story4]
+ end
+ it 'page=2なら中間2件を返す' do
+ l = Story.list 2, 2
+ l.should eq [@story3, @story2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ l = Story.list 3, 2
+ l.should eq [@story]
+ end
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
+ @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
+ @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
+ @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+ Story.stub(:default_page_size).and_return(2)
+ end
+ it '件数0は全件(5件)を返す' do
+ r = Story.list 5, 0
+ r.should have(5).items
+ end
+ end
+ end
describe '自分のストーリー一覧取得に於いて' do
before do
@comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
@story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
@story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
@story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
+ Story.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
- c = Story.mylist @author, 1, 2
- c.should have(2).items
+ l = Story.mylist @author, 1, 2
+ l.should have(2).items
end
it 'page=1なら末尾2件を返す' do
#時系列で並んでいる
- c = Story.mylist(@author, 1, 2)
- c.should eq [@story5, @story4]
+ l = Story.mylist @author, 1, 2
+ l.should eq [@story5, @story4]
end
it 'page=2なら中間2件を返す' do
- c = Story.mylist(@author, 2, 2)
- c.should eq [@story3, @story2]
+ l = Story.mylist @author, 2, 2
+ l.should eq [@story3, @story2]
end
it 'page=3なら先頭1件を返す' do
- c = Story.mylist(@author, 3, 2)
- c.should eq [@story]
+ l = Story.mylist @author, 3, 2
+ l.should eq [@story]
end
end
- context 'DBに5件あって1ページの件数を0件に変えたとして' do
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
@story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
@story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
@story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
@story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
- Author.stub(:default_story_size).and_return(2)
+ Author.stub(:default_story_page_size).and_return(2)
end
- it '通常は全件(5件)を返す' do
+ it '件数0は全件(5件)を返す' do
r = Story.mylist @author, 5, 0
r.should have(5).items
end