Skip to content
Browse files

mock with mocha, keep content areas dirty all the time

  • Loading branch information...
1 parent 50137d0 commit bbe0b3e48bc5efcd4bc55912e33511faa1341d77 @drinks drinks committed Sep 27, 2012
Showing with 18 additions and 4 deletions.
  1. +0 −1 Gemfile
  2. +0 −2 Gemfile.lock
  3. +5 −0 app/models/content_area.rb
  4. +12 −0 spec/models/event_spec.rb
  5. +1 −1 spec/spec_helper.rb
View
1 Gemfile
@@ -43,7 +43,6 @@ end
group :development, :test do
gem 'rspec-rails', '~> 2.7'
- gem 'rr', '~> 1.0'
gem 'capybara', '~> 1.1'
gem 'mongoid-rspec', '~> 1.4'
gem 'database_cleaner', '~> 0.6'
View
2 Gemfile.lock
@@ -203,7 +203,6 @@ GEM
redis (2.2.2)
redis-namespace (0.10.0)
redis (< 3.0.0)
- rr (1.0.4)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
@@ -305,7 +304,6 @@ DEPENDENCIES
redis (~> 2.2)
redis-namespace (~> 0.10)
rocco!
- rr (~> 1.0)
rspec-rails (~> 2.7)
simple_form (~> 2.0)
sketches
View
5 app/models/content_area.rb
@@ -36,6 +36,11 @@ def as_json(options = {})
super.merge(:modal_class => self.class.modal_class)
end
+ # Always mark ContentAreas as dirty so that callbacks cascade properly
+ def changed?
+ true
+ end
+
protected
# A convenience for querying by class name.
View
12 spec/models/event_spec.rb
@@ -137,4 +137,16 @@
event = Event.create(name: 'Test Event', event_template: event_template, scheduled_at: Time.now)
event.persisted?.should be_false
end
+
+ it "cascades callbacks to content_areas" do
+ body = <<-ENDBODY.strip_heredoc
+ <div>{{ content_area: Test Content Area }}</div>
+ ENDBODY
+ ContentArea.set_callback(:save, :before, :foo)
+ template = EventTemplate.create(name: 'My Event Template', template: body)
+ event = Event.create(name: 'Test Event', event_template: template, scheduled_at: Time.now)
+ event.content_areas.first.expects(:foo)
+ event.save
+ ContentArea.skip_callback(:save, :before, :foo)
+ end
end
View
2 spec/spec_helper.rb
@@ -8,7 +8,7 @@
RSpec.configure do |config|
config.include Mongoid::Matchers
- config.mock_with :rr
+ config.mock_with :mocha
config.before(:all) do
@redis_db = REDIS

0 comments on commit bbe0b3e

Please sign in to comment.
Something went wrong with that request. Please try again.