Commit e80da508cf60bd427281174ba31079abec2fc921
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/339' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/339 Conflicts: app/models/block.rb public/designs/icons/tango/style.css test/unit/block_test.rb
Showing
6 changed files
with
66 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
app/helpers/boxes_helper.rb
... | ... | @@ -212,6 +212,7 @@ module BoxesHelper |
212 | 212 | |
213 | 213 | if !block.main? |
214 | 214 | buttons << icon_button(:delete, _('Remove block'), { :action => 'remove', :id => block.id }, { :method => 'post', :confirm => _('Are you sure you want to remove this block?')}) |
215 | + buttons << icon_button(:clone, _('Clone'), { :action => 'clone', :id => block.id }, { :method => 'post' }) | |
215 | 216 | end |
216 | 217 | |
217 | 218 | if block.respond_to?(:help) | ... | ... |
app/models/block.rb
... | ... | @@ -168,4 +168,14 @@ class Block < ActiveRecord::Base |
168 | 168 | DISPLAY_OPTIONS[option] |
169 | 169 | end |
170 | 170 | |
171 | + def duplicate | |
172 | + duplicated_block = self.clone | |
173 | + duplicated_block.enabled = false | |
174 | + duplicated_block.created_at = nil | |
175 | + duplicated_block.updated_at = nil | |
176 | + duplicated_block.save! | |
177 | + duplicated_block.insert_at(self.position + 1) | |
178 | + duplicated_block | |
179 | + end | |
180 | + | |
171 | 181 | end | ... | ... |
public/designs/icons/tango/style.css
... | ... | @@ -99,6 +99,7 @@ |
99 | 99 | .icon-user-removed { background-image: url(Tango/16x16/actions/gtk-cancel.png) } |
100 | 100 | .icon-user-unknown { background-image: url(Tango/16x16/status/dialog-error.png) } |
101 | 101 | .icon-alert { background-image: url(Tango/16x16/status/dialog-warning.png) } |
102 | +.icon-clone { background-image: url(Tango/16x16/actions/edit-copy.png) } | |
102 | 103 | |
103 | 104 | .icon-activate-user { background-image: url(Tango/16x16/emblems/emblem-system.png) } |
104 | 105 | .icon-deactivate-user { background-image: url(Tango/16x16/emblems/emblem-unreadable.png) } | ... | ... |
test/functional/profile_design_controller_test.rb
... | ... | @@ -736,4 +736,12 @@ class ProfileDesignControllerTest < ActionController::TestCase |
736 | 736 | assert !@controller.available_blocks.include?(CustomBlock1) |
737 | 737 | end |
738 | 738 | |
739 | + should 'clone a block' do | |
740 | + block = ProfileImageBlock.create!(:box => profile.boxes.first) | |
741 | + assert_difference ProfileImageBlock, :count, 1 do | |
742 | + post :clone, :id => block.id, :profile => profile.identifier | |
743 | + assert_response :redirect | |
744 | + end | |
745 | + end | |
746 | + | |
739 | 747 | 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 |
... | ... | @@ -165,4 +167,42 @@ class BlockTest < ActiveSupport::TestCase |
165 | 167 | conditions = Block.expire_on |
166 | 168 | assert conditions[:environment].kind_of?(Array) |
167 | 169 | end |
170 | + | |
171 | + should 'create a cloned block' do | |
172 | + block = fast_create(Block, :title => 'test 1', :position => 1) | |
173 | + assert_difference Block, :count, 1 do | |
174 | + block.duplicate | |
175 | + end | |
176 | + end | |
177 | + | |
178 | + should 'clone and keep some fields' do | |
179 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
180 | + block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}) | |
181 | + duplicated = block.duplicate | |
182 | + DUPLICATABLE_FIELDS.each do |f| | |
183 | + assert_equal duplicated.send(f), block.send(f) | |
184 | + end | |
185 | + end | |
186 | + | |
187 | + should 'clone block and set fields' do | |
188 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
189 | + block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
190 | + block2 = TagsBlock.create!(:title => 'test 2', :box_id => box.id, :settings => {:test => 'test'}, :position => 2) | |
191 | + duplicated = block.duplicate | |
192 | + block2.reload | |
193 | + block.reload | |
194 | + assert_equal false, duplicated.enabled | |
195 | + assert_equal 1, block.position | |
196 | + assert_equal 2, duplicated.position | |
197 | + assert_equal 3, block2.position | |
198 | + end | |
199 | + | |
200 | + should 'not clone date creation and update attributes' do | |
201 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
202 | + block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
203 | + duplicated = block.duplicate | |
204 | + | |
205 | + assert_not_equal block.created_at, duplicated.created_at | |
206 | + assert_not_equal block.updated_at, duplicated.updated_at | |
207 | + end | |
168 | 208 | end | ... | ... |