From d5da26a6f028740c2f68d30d88e2947db37e0efc Mon Sep 17 00:00:00 2001 From: yasushiito Date: Sun, 5 May 2013 18:53:50 +0900 Subject: [PATCH] t#31291:add stories index --- app/controllers/authors_controller.rb | 15 ++- app/views/authors/show.html.erb | 4 + app/views/authors/stories.html.erb | 8 ++ app/views/stories/_list_item.html.erb | 32 ++--- app/views/stories/index.html.erb | 8 +- config/locales/pettanr.ja.yml | 3 + config/routes.rb | 1 + spec/controllers/authors_controller_spec.rb | 195 +++++++++++++++++++++++++++- 8 files changed, 240 insertions(+), 26 deletions(-) create mode 100644 app/views/authors/stories.html.erb diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index 531f46d9..5b5da90f 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -4,7 +4,7 @@ class AuthorsController < ApplicationController before_filter :authenticate_user, :only => [:new, :create, :edit, :update] before_filter :authenticate_author, :only => [:edit, :update] else - before_filter :authenticate_reader, :only => [:index, :show, :comics, :panels] + before_filter :authenticate_reader, :only => [:index, :show, :comics, :stories, :panels] before_filter :authenticate_user, :only => [:new, :create, :edit, :update] before_filter :authenticate_author, :only => [:edit, :update] end @@ -43,6 +43,19 @@ class AuthorsController < ApplicationController end end + def stories + @au = Author.show(params[:id], [@user, @admin]) + + @page = Author.page params[:page] + @page_size = Author.comic_page_size params[:page_size] + @stories = Story.mylist(@au, @page, @page_size) + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @stories.to_json(Story.list_json_opt) } + end + end + def panels @au = Author.show(params[:id], [@user, @admin]) diff --git a/app/views/authors/show.html.erb b/app/views/authors/show.html.erb index 97f54d22..1d787165 100644 --- a/app/views/authors/show.html.erb +++ b/app/views/authors/show.html.erb @@ -22,6 +22,10 @@

+ <%= link_to t('authors.show.to_stories'), stories_author_path(@au) %> +

+ +

<%= link_to t('authors.show.to_panels'), panels_author_path(@au) %>

diff --git a/app/views/authors/stories.html.erb b/app/views/authors/stories.html.erb new file mode 100644 index 00000000..47e0cac3 --- /dev/null +++ b/app/views/authors/stories.html.erb @@ -0,0 +1,8 @@ +

<%= t '.title' -%>

+ + + <% @stories.each do |story| %> + <%= render 'stories/list_item', :story => story, :author => @author %> + <% end %> +
+<%= link_to t('stories.new.title'), new_story_path %> diff --git a/app/views/stories/_list_item.html.erb b/app/views/stories/_list_item.html.erb index 0d3eacf9..1b18f0fc 100644 --- a/app/views/stories/_list_item.html.erb +++ b/app/views/stories/_list_item.html.erb @@ -1,26 +1,28 @@ - + + + + + -
-
- <%= 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 %> -
+ <%= 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 %> + <%= 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) %> - <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %> -
-
- No.<%= story.t %> - <%= l story.updated_at %> -
+ <%= link_to story_icon(:object => story, :size => 25), story_path(story) %> +
+ <%= link_to author_icon(:object => story.author, :size => 17), author_path(story.author) %> + + No.<%= story.t %> + + <%= l story.updated_at %> <% if story.panel %> - <%= render 'panels/standard', :panel => story.panel, :author => @author %> + <%= h story.panel.caption %> <% end %>
diff --git a/app/views/stories/index.html.erb b/app/views/stories/index.html.erb index 1ab65ec0..2e02f67f 100644 --- a/app/views/stories/index.html.erb +++ b/app/views/stories/index.html.erb @@ -1,5 +1,7 @@

<%= t '.title' -%>

-<% @stories.each do |story| %> - <%= render 'list_item', :story => story, :author => @author %> -<% end %> + + <% @stories.each do |story| %> + <%= render 'list_item', :story => story, :author => @author %> + <% end %> +
<%= link_to t('stories.new.title'), new_story_path %> diff --git a/config/locales/pettanr.ja.yml b/config/locales/pettanr.ja.yml index e5006a65..6d4ed08a 100644 --- a/config/locales/pettanr.ja.yml +++ b/config/locales/pettanr.ja.yml @@ -671,9 +671,12 @@ ja: show: title: 作家詳細 to_comics: 最近更新したコミック + to_stories: 最近更新したストーリー to_panels: 最近更新したコマ comics: title: 最近更新したコミック + stories: + title: 最近更新したストーリー panels: title: 最近更新したコマ new: diff --git a/config/routes.rb b/config/routes.rb index 3c48f086..30ba8d56 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,7 @@ Pettanr::Application.routes.draw do delete :destroy get :browse get :comics + get :stories get :panels end end diff --git a/spec/controllers/authors_controller_spec.rb b/spec/controllers/authors_controller_spec.rb index 2ef27019..214998b2 100644 --- a/spec/controllers/authors_controller_spec.rb +++ b/spec/controllers/authors_controller_spec.rb @@ -291,9 +291,9 @@ if MagicNumber['run_mode'] == 1 assigns(:comics).should have_at_least(3).items end context 'html形式' do - it 'comicテンプレートを描画する' do + it 'comicsテンプレートを描画する' do get :comics, :id => @other_author.id - response.should render_template("comic") + response.should render_template("comics") end end context 'json形式' do @@ -364,6 +364,135 @@ if MagicNumber['run_mode'] == 1 end end + describe '対象作家のストーリー一覧表示に於いて' do + before do + @other_user = FactoryGirl.create( :user_yas) + @other_author = FactoryGirl.create :author, :user_id => @other_user.id + @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id + @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id + @panel = FactoryGirl.create :panel, :author_id => @other_user.author.id + @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_user.author.id + Story.stub(:mylist).and_return([@story, @story, @story]) + sign_in @user + end + context 'パラメータpageについて' do + it '@pageに値が入る' do + get :stories, :id => @other_author.id, :page => 5 + assigns(:page).should eq 5 + end + it '省略されると@pageに1値が入る' do + get :stories, :id => @other_author.id + assigns(:page).should eq 1 + end + it '与えられたpage_sizeがセットされている' do + get :stories, :id => @other_author.id, :page_size => 15 + assigns(:page_size).should eq 15 + end + it '省略されると@page_sizeにデフォルト値が入る' do + get :stories, :id => @other_author.id + assigns(:page_size).should eq Author.default_story_page_size + end + it '最大を超えると@page_sizeにデフォルト最大値が入る' do + get :stories, :id => @other_author.id, :page_size => 1500 + assigns(:page_size).should eq Author.story_max_page_size + end + it '不正な値が入ると@page_sizeにデフォルト最大値が入る' do + get :stories, :id => @other_author.id, :page_size => 0 + assigns(:page_size).should eq Author.default_story_page_size + end + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :stories, :id => @other_author.id + response.should be_success + end + it '作家モデルに単体取得を問い合わせている' do + Author.should_receive(:show).exactly(1) + get :stories, :id => @other_author.id + end + it 'ストーリーモデルに一覧を問い合わせている' do + Story.should_receive(:mylist).exactly(1) + get :stories, :id => @other_author.id + end + it '@storiesにリストを取得している' do + get :stories, :id => @other_author.id + assigns(:stories).should have_at_least(3).items + end + context 'html形式' do + it 'storiesテンプレートを描画する' do + get :stories, :id => @other_author.id + response.should render_template("stories") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :stories, :id => @other_author.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + it 'ストーリーモデルにjson一覧出力オプションを問い合わせている' do + Story.should_receive(:list_json_opt).exactly(1) + get :stories, :id => @other_author.id, :format => :json + end + it 'データがリスト構造になっている' do + get :stories, :id => @other_author.id, :format => :json + json = JSON.parse response.body + json.should have_at_least(3).items + end + it 'リストの先頭くらいはストーリーっぽいものであって欲しい' do + get :stories, :id => @other_author.id, :format => :json + json = JSON.parse response.body + json.first.has_key?("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 :stories, :id => @other_author.id + response.status.should eq 302 + end + it 'サインインページへ遷移する' do + get :stories, :id => @other_author.id + response.should redirect_to '/users/sign_in' + end + end + context 'json形式' do + it 'ステータスコード401 Unauthorizedを返す' do + get :stories, :id => @other_author.id, :format => :json + response.status.should eq 401 + end + it '応答メッセージにUnauthorizedを返す' do + get :stories, :id => @other_author.id, :format => :json + response.message.should match(/Unauthorized/) + end + end + end + context 'ユーザ権限はないが管理者権限があるとき' do + before do + sign_out @user + sign_in @admin + end + it 'ステータスコード200 OKを返す' do + get :stories, :id => @other_author.id + response.should be_success + end + end + context 'ユーザだが作家登録していないとき' do + before do + @author.destroy + end + it 'ステータスコード200 OKを返す' do + get :stories, :id => @other_author.id + response.should be_success + end + end + end + describe '対象作家のコマ一覧表示に於いて' do before do @other_user = FactoryGirl.create( :user_yas) @@ -417,7 +546,7 @@ if MagicNumber['run_mode'] == 1 assigns(:panels).should have_at_least(3).items end context 'html形式' do - it 'comicテンプレートを描画する' do + it 'panelsテンプレートを描画する' do get :panels, :id => @other_author.id response.should render_template("panels") end @@ -1115,9 +1244,9 @@ else response.should be_success end context 'html形式' do - it 'comicテンプレートを描画する' do + it 'comicsテンプレートを描画する' do get :comics, :id => @other_author.id - response.should render_template("comic") + response.should render_template("comics") end end context 'json形式' do @@ -1129,6 +1258,58 @@ else end end + describe '対象作家のストーリー一覧表示に於いて' do + before do + @other_user = FactoryGirl.create( :user_yas) + @other_author = FactoryGirl.create :author, :user_id => @other_user.id + @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id + @comic = FactoryGirl.create :comic, :author_id => @other_user.author.id + @panel = FactoryGirl.create :panel, :author_id => @other_author.id + @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @other_author.id + Story.stub(:mylist).and_return([@story, @story, @story]) + sign_in @user + end + context 'つつがなく終わるとき' do + it 'ステータスコード200 OKを返す' do + get :stories, :id => @other_author.id + response.should be_success + end + context 'html形式' do + it 'storiesテンプレートを描画する' do + get :stories, :id => @other_author.id + response.should render_template("stories") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :stories, :id => @other_author.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + context 'ユーザ権限がないとき' do + before do + sign_out @user + end + it 'ステータスコード200 OKを返す' do + get :stories, :id => @other_author.id + response.should be_success + end + context 'html形式' do + it 'storiesテンプレートを描画する' do + get :stories, :id => @other_author.id + response.should render_template("stories") + end + end + context 'json形式' do + it 'jsonデータを返す' do + get :stories, :id => @other_author.id, :format => :json + lambda{JSON.parse(response.body)}.should_not raise_error(JSON::ParserError) + end + end + end + end + describe '対象作家のコマ一覧表示に於いて' do before do @other_user = FactoryGirl.create( :user_yas) @@ -1144,7 +1325,7 @@ else response.should be_success end context 'html形式' do - it 'comicテンプレートを描画する' do + it 'panelsテンプレートを描画する' do get :panels, :id => @other_author.id response.should render_template("panels") end @@ -1165,7 +1346,7 @@ else response.should be_success end context 'html形式' do - it 'comicテンプレートを描画する' do + it 'panelsテンプレートを描画する' do get :panels, :id => @other_author.id response.should render_template("panels") end -- 2.11.0