Commit dd55c842eff469a983e774214c484142b45ce2f5
Committed by
Daniela Feitosa
1 parent
5a911ba4
Exists in
master
and in
29 other branches
Clone blocks
Showing
6 changed files
with
68 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
app/helpers/boxes_helper.rb
... | ... | @@ -210,6 +210,7 @@ module BoxesHelper |
210 | 210 | |
211 | 211 | if !block.main? |
212 | 212 | buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post', :confirm => _('Are you sure you want to remove this block?')}) |
213 | + buttons << icon_button(:clone, _('Clone'), { :action => 'clone', :id => block.id }, { :method => 'post' }) | |
213 | 214 | end |
214 | 215 | |
215 | 216 | if block.respond_to?(:help) | ... | ... |
app/models/block.rb
... | ... | @@ -138,4 +138,14 @@ class Block < ActiveRecord::Base |
138 | 138 | 4.hours |
139 | 139 | end |
140 | 140 | |
141 | + def duplicate | |
142 | + duplicated_block = self.clone | |
143 | + duplicated_block.enabled = false | |
144 | + duplicated_block.created_at = nil | |
145 | + duplicated_block.updated_at = nil | |
146 | + duplicated_block.save! | |
147 | + duplicated_block.insert_at(self.position + 1) | |
148 | + duplicated_block | |
149 | + end | |
150 | + | |
141 | 151 | end | ... | ... |
public/designs/icons/tango/style.css
... | ... | @@ -100,6 +100,7 @@ |
100 | 100 | .icon-user-removed { background-image: url(Tango/16x16/actions/gtk-cancel.png) } |
101 | 101 | .icon-user-unknown { background-image: url(Tango/16x16/status/dialog-error.png) } |
102 | 102 | .icon-alert { background-image: url(Tango/16x16/status/dialog-warning.png) } |
103 | +.icon-clone { background-image: url(Tango/16x16/actions/edit-copy.png) } | |
103 | 104 | |
104 | 105 | /******************LARGE ICONS********************/ |
105 | 106 | .image-gallery-item .folder { background-image: url(mod/96x96/places/folder.png) } | ... | ... |
test/functional/profile_design_controller_test.rb
... | ... | @@ -714,4 +714,12 @@ class ProfileDesignControllerTest < ActionController::TestCase |
714 | 714 | assert !@controller.available_blocks.include?(CustomBlock1) |
715 | 715 | end |
716 | 716 | |
717 | + should 'clone a block' do | |
718 | + block = ProfileImageBlock.create!(:box => profile.boxes.first) | |
719 | + assert_difference ProfileImageBlock, :count, 1 do | |
720 | + post :clone, :id => block.id, :profile => profile.identifier | |
721 | + assert_response :redirect | |
722 | + end | |
723 | + end | |
724 | + | |
717 | 725 | end | ... | ... |
test/unit/block_test.rb
... | ... | @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class BlockTest < ActiveSupport::TestCase |
4 | 4 | |
5 | + DUPLICATABLE_FIELDS = [:settings, :title, :box_id, :type] | |
6 | + | |
5 | 7 | should 'describe itself' do |
6 | 8 | assert_kind_of String, Block.description |
7 | 9 | end |
... | ... | @@ -150,10 +152,49 @@ class BlockTest < ActiveSupport::TestCase |
150 | 152 | |
151 | 153 | should 'delegate environment to box' do |
152 | 154 | box = fast_create(Box, :owner_id => fast_create(Profile).id) |
153 | - block = Block.new(:box => box) | |
155 | + block = Block.new(:bo => box) | |
154 | 156 | box.stubs(:environment).returns(Environment.default) |
155 | 157 | |
156 | 158 | assert_equal box.environment, block.environment |
157 | 159 | end |
158 | 160 | |
161 | + should 'create a clone block' do | |
162 | + block = fast_create(Block, :title => 'test 1', :position => 1) | |
163 | + assert_difference Block, :count, 1 do | |
164 | + block.duplicate | |
165 | + end | |
166 | + end | |
167 | + | |
168 | + should 'clone and keep some fields' do | |
169 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
170 | + block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}) | |
171 | + duplicated = block.duplicate | |
172 | + DUPLICATABLE_FIELDS.each do |f| | |
173 | + assert_equal duplicated.send(f), block.send(f) | |
174 | + end | |
175 | + end | |
176 | + | |
177 | + should 'clone block and set fields' do | |
178 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
179 | + block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
180 | + block2 = TagsBlock.create!(:title => 'test 2', :box_id => box.id, :settings => {:test => 'test'}, :position => 2) | |
181 | + duplicated = block.duplicate | |
182 | + block2.reload | |
183 | + block.reload | |
184 | + assert_equal false, duplicated.enabled | |
185 | + assert_equal 1, block.position | |
186 | + assert_equal 2, duplicated.position | |
187 | + assert_equal 3, block2.position | |
188 | + end | |
189 | + | |
190 | + should 'not clone date creation and update attributes' do | |
191 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
192 | + block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
193 | + duplicated = block.duplicate | |
194 | + | |
195 | + assert_not_equal block.created_at, duplicated.created_at | |
196 | + assert_not_equal block.updated_at, duplicated.updated_at | |
197 | + end | |
198 | + | |
199 | + | |
159 | 200 | end | ... | ... |