Make '.save' work identically between ContentBlocks and ActiveRecord #582

peakpg opened this Issue Mar 20, 2013 · 1 comment

1 participant


Currently there are some gotchas when developers work with Content Blocks that behave differently then working with ActiveRecord. This makes it harder for developers familiar with Rails to work with BrowserCMS writing custom code. Specific issue:

class Event < ActiveRecord::Base

event = Event.create!(:name=>"Event #1", :save_and_publish=>true) = "Event #2"!

refute  "Event #2" == Event.find( 

event.publish! # This will both publish and save the record.
assert_equals "Event #2", Event.find( # This is now true.
@peakpg peakpg was assigned Mar 25, 2013

This is complete. When upgrading to 4.0, if you have custom code that wants to save blocks as unpublished, you will need to update your code from:

# In 3.5.x, this would save a draft block
# In 4.0, this will save a published block

# In 4.0, this saves a draft block

# In 4.0, this will also save a draft block
@block.update_attributes(name: "New Name", publish_on_save: false)
@peakpg peakpg closed this Mar 26, 2013
@peakpg peakpg added a commit that referenced this issue Mar 27, 2013
@peakpg peakpg [#582] Make .save work identically to ActiveRecord
* Calling .save on a content block will by default publish it now (it used to save a draft copy)
* Refactor tests to ensure create/create! work identically to ActiveRecord
* Add some custom matchers.

[#256] .publish now has consistent behavior.
* Changed the behavior of block.publish
* It will no longer save new records, but will return false and generate a deprecation warning.
* It will now only ever publish the latest draft, returning true if there was something to publish.
* Add additional coverage for publish/publish! on new blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment