From 5a6553eab0ee9b9123965463124b2b344e54609d Mon Sep 17 00:00:00 2001 From: yasushiito Date: Thu, 8 Nov 2012 18:34:43 +0900 Subject: [PATCH] t#30021:add repeat on gp --- app/models/ground_picture.rb | 6 ++ app/views/ground_pictures/index.html.erb | 4 ++ app/views/panels/_body.html.erb | 4 +- config/magic_number.yml | 1 + db/migrate/20121107091403_add_repeat_on_gp.rb | 13 ++++ spec/models/ground_picture_spec.rb | 93 +++++++++++++++++++++------ 6 files changed, 100 insertions(+), 21 deletions(-) create mode 100644 db/migrate/20121107091403_add_repeat_on_gp.rb diff --git a/app/models/ground_picture.rb b/app/models/ground_picture.rb index ebb59596..14b5859a 100644 --- a/app/models/ground_picture.rb +++ b/app/models/ground_picture.rb @@ -3,10 +3,16 @@ class GroundPicture < ActiveRecord::Base belongs_to :picture validates :panel_id, :numericality => {:allow_blank => true} + validates :repeat, :numericality => true, :inclusion => { :in => 0..3 } + validates :x, :numericality => true + validates :y, :numericality => true validates :picture_id, :numericality => true, :existence => true validates :z, :presence => true, :numericality => {:greater_than => 0} def supply_default + self.repeat = 0 + self.x = 0 + self.y = 0 end def overwrite diff --git a/app/views/ground_pictures/index.html.erb b/app/views/ground_pictures/index.html.erb index 32f741c6..18e665c6 100644 --- a/app/views/ground_pictures/index.html.erb +++ b/app/views/ground_pictures/index.html.erb @@ -5,6 +5,8 @@ id panel_id picture_id + repeat + position x,y z @@ -13,6 +15,8 @@ <%= gp.id %> <%= link_to gp.panel_id, panel_path(gp.panel_id) %> <%= link_to gp.picture_id, color_path(gp.picture_id) %> + <%= gp.repeat %><%= MagicNumber['ground_picture_repeat_items'][gp.repeat] %> + <%= gp.x %>, <%= gp.y %> <%= gp.z %> <% end -%> diff --git a/app/views/panels/_body.html.erb b/app/views/panels/_body.html.erb index ce1d04b1..a3ff9702 100644 --- a/app/views/panels/_body.html.erb +++ b/app/views/panels/_body.html.erb @@ -22,8 +22,8 @@ <% when 'GroundPicture' %> -
- +
+
<% end %> <% end %> diff --git a/config/magic_number.yml b/config/magic_number.yml index e8e218dc..9a6320eb 100644 --- a/config/magic_number.yml +++ b/config/magic_number.yml @@ -4,3 +4,4 @@ thumbnail_height: 64 comic_visible_items: [['private', 0], ['public', 1]] + ground_picture_repeat_items: ['repeat', 'repeat-x', 'repeat-y', 'no-repeat'] diff --git a/db/migrate/20121107091403_add_repeat_on_gp.rb b/db/migrate/20121107091403_add_repeat_on_gp.rb new file mode 100644 index 00000000..cdf03763 --- /dev/null +++ b/db/migrate/20121107091403_add_repeat_on_gp.rb @@ -0,0 +1,13 @@ +class AddRepeatOnGp < ActiveRecord::Migration + def up + add_column :ground_pictures, :repeat, :integer, :null => false, :default => 0 + add_column :ground_pictures, :x, :integer, :null => false, :default => 0 + add_column :ground_pictures, :y, :integer, :null => false, :default => 0 + end + + def down + remove_column :ground_pictures, :repeat + remove_column :ground_pictures, :x + remove_column :ground_pictures, :y + end +end diff --git a/spec/models/ground_picture_spec.rb b/spec/models/ground_picture_spec.rb index e2e449f3..5c8c2839 100644 --- a/spec/models/ground_picture_spec.rb +++ b/spec/models/ground_picture_spec.rb @@ -27,10 +27,16 @@ describe GroundPicture do context 'オーソドックスなデータのとき' do it '下限データが通る' do + @gp.repeat = 0 + @gp.x = -99999 + @gp.y = -99999 @gp.z = 1 @gp.should be_valid end it '上限データが通る' do + @gp.repeat = 3 + @gp.x = 99999 + @gp.y = 99999 @gp.z = 99999 @gp.should be_valid end @@ -58,6 +64,44 @@ describe GroundPicture do @gp.should_not be_valid end end + context 'repeatを検証するとき' do + it 'nullなら失敗する' do + @gp.repeat = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.repeat = 'a' + @gp.should_not be_valid + end + it '-1なら失敗する' do + @gp.repeat = -1 + @gp.should_not be_valid + end + it '4なら失敗する' do + @gp.repeat = 4 + @gp.should_not be_valid + end + end + context 'xを検証するとき' do + it 'nullなら失敗する' do + @gp.x = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.x = 'a' + @gp.should_not be_valid + end + end + context 'yを検証するとき' do + it 'nullなら失敗する' do + @gp.y = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.y = 'a' + @gp.should_not be_valid + end + end context 'zを検証するとき' do it 'nullなら失敗する' do @gp.z = nil @@ -79,9 +123,20 @@ describe GroundPicture do end describe 'デフォルト値補充に於いて' do - it 'defined' do - @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + end + it 'xに0を補充している' do + @gp.supply_default + @gp.x.should eq 0 + end + it 'yに0を補充している' do + @gp.supply_default + @gp.y.should eq 0 + end + it '繰り返しに0を補充している' do @gp.supply_default + @gp.repeat.should eq 0 end end @@ -121,13 +176,13 @@ describe GroundPicture do GroundPicture.page_size('1000').should eq GroundPicture.max_page_size end end - context 'つつがなく終わるとき' do - it '一覧取得オプションを利用している' do - GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) - GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) r = GroundPicture.list - end - end + end + end it 'リストを返す' do pl = GroundPicture.list pl.should eq [@gp] @@ -217,10 +272,10 @@ describe GroundPicture do end describe 'json一覧出力オプションに於いて' do before do - @op = FactoryGirl.create :original_picture, :artist_id => @artist.id - @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id - @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id - @sbt = FactoryGirl.create :speech_balloon_template + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + @sbt = FactoryGirl.create :speech_balloon_template @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id @@ -265,13 +320,13 @@ describe GroundPicture do before do @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id end - context 'つつがなく終わるとき' do - it '一覧取得オプションを利用している' do - GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) - GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) r = GroundPicture.mylist @author - end - end + end + end it 'リストを返す' do pl = GroundPicture.mylist @author pl.should eq [@gp] @@ -324,7 +379,7 @@ describe GroundPicture do @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 - Author.stub(:default_ground_picture_page_size).and_return(2) + Author.stub(:default_ground_picture_page_size).and_return(2) end it '通常は全件(5件)を返す' do r = GroundPicture.mylist @author, 5, 0 -- 2.11.0