OSDN Git Service

t#30021:add repeat on gp
authoryasushiito <yas@pen-chan.jp>
Thu, 8 Nov 2012 09:34:43 +0000 (18:34 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 8 Nov 2012 09:34:43 +0000 (18:34 +0900)
app/models/ground_picture.rb
app/views/ground_pictures/index.html.erb
app/views/panels/_body.html.erb
config/magic_number.yml
db/migrate/20121107091403_add_repeat_on_gp.rb [new file with mode: 0644]
spec/models/ground_picture_spec.rb

index ebb5959..14b5859 100644 (file)
@@ -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
index 32f741c..18e665c 100644 (file)
@@ -5,6 +5,8 @@
     <th>id</th>
     <th>panel_id</th>
     <th>picture_id</th>
+    <th>repeat</th>
+    <th>position x,y</th>
     <th>z</th>
   </tr>
 
@@ -13,6 +15,8 @@
     <td><%= gp.id %></td>
     <td><%= link_to gp.panel_id, panel_path(gp.panel_id) %></td>
     <td><%= link_to gp.picture_id, color_path(gp.picture_id) %></td>
+    <td><%= gp.repeat %><%= MagicNumber['ground_picture_repeat_items'][gp.repeat] %></td>
+    <td><%= gp.x %>, <%= gp.y %></td>
     <td><%= gp.z %></td>
   </tr>
 <% end -%>
index ce1d04b..a3ff970 100644 (file)
@@ -22,8 +22,8 @@
       
       </div>
     <% when 'GroundPicture' %>
-      <div id="ground-picture<%= elm.id -%>" class="pettanr-comic-ground-picture" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-image: url(<%= full_url elm.picture.url -%>); ">
-      
+      <div id="ground-picture<%= elm.id -%>" class="pettanr-comic-ground-picture" style="width:<%= panel.width -%>px; height:<%= panel.height -%>px; z-index:<%= elm.z -%>; background-image: url(<%= full_url elm.picture.url -%>); background-repeat: <%= MagicNumber['ground_picture_repeat_items'][elm.repeat] -%>; background-position: <%= elm.x -%>px, <%= elm.y -%>px;">
+        
       </div>
     <% end %>
   <% end %>
index e8e218d..9a6320e 100644 (file)
@@ -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 (file)
index 0000000..cdf0376
--- /dev/null
@@ -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
index e2e449f..5c8c283 100644 (file)
@@ -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\r
-      it '一覧取得オプションを利用している' do\r
-        GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})\r
-        GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+    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\r
-    end\r
+      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\r
-      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
-      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
-      @sbt = FactoryGirl.create :speech_balloon_template\r
+      @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\r
-      it '一覧取得オプションを利用している' do\r
-        GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})\r
-        GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+    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\r
-    end\r
+      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)\r
+        Author.stub(:default_ground_picture_page_size).and_return(2)
       end
       it '通常は全件(5件)を返す' do
         r = GroundPicture.mylist @author, 5, 0