Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Upgraded to use the latest middelware implementation from riot

  • Loading branch information...
commit 812ce65522cf2c9c64deb6cac9c3523ddc1fbfe9 1 parent 0c7f60f
@gus gus authored
View
15 lib/riot/action_controller/context_middleware.rb
@@ -2,16 +2,19 @@ module RiotRails
class ActionControllerMiddleware < Riot::ContextMiddleware
register
+ def call(context)
+ if handle?(context)
+ setup_context_macros(context)
+ setup_situation(context)
+ end
+ middleware.call(context)
+ end
+ private
def handle?(context)
description = context.description
description.kind_of?(Class) && description.ancestors.include?(::ActionController::Base)
- end # handle?
-
- def call(context)
- setup_context_macros(context)
- setup_situation(context)
end
- private
+
def setup_context_macros(context)
context.class_eval do
include RiotRails::ActionController::AssertsResponse
View
12 lib/riot/active_record/context_middleware.rb
@@ -2,14 +2,16 @@ module RiotRails
class ActiveRecordMiddleware < Riot::ContextMiddleware
register
+ def call(context)
+ if handle?(context)
+ context.setup(true) { context.description.new }
+ end
+ middleware.call(context)
+ end
+ private
def handle?(context)
description = context.description
description.kind_of?(Class) && description.ancestors.include?(::ActiveRecord::Base)
end
-
- def call(context)
- context.setup(true) { context.description.new }
- end
-
end # ActiveRecordMiddleware
end # RiotRails
View
19 lib/riot/active_record/transactional_middleware.rb
@@ -2,20 +2,27 @@ module RiotRails
class TransactionalMiddleware < Riot::ContextMiddleware
register
+ def call(context)
+ middleware.call(context)
+ hijack_local_run(context) if handle?(context)
+ end
+ private
def handle?(context)
context.option(:transactional) == true
end
- def call(context)
- context.class.class_eval do
+ # Don't you just love mr. metaclass?
+ def hijack_local_run(context)
+ (class << context; self; end).class_eval do
alias_method :transactionless_local_run, :local_run
def local_run(*args)
::ActiveRecord::Base.transaction do
transactionless_local_run(*args)
raise ::ActiveRecord::Rollback
end
- end
- end
- end
- end
+ end # local_run
+ end # metaclass
+ end # hijack_local_run
+
+ end # TransactionalMiddleware
end # RiotRails
View
17 test/transactional_middleware_test.rb
@@ -8,14 +8,6 @@ def transaction(&block) yield; end
end
end
- context "when :transactional is not set" do
- setup { Riot::Context.new("Room") {} }
-
- asserts("executing context does not raise errors") do
- topic.local_run(Riot::SilentReporter.new, Riot::Situation.new)
- end
- end # when :transactional is not set
-
context "when :transactional is set to true" do
setup { Riot::Context.new("Room") { set(:transactional, true) } }
@@ -23,4 +15,13 @@ def transaction(&block) yield; end
topic.local_run(Riot::SilentReporter.new, Riot::Situation.new)
end.raises(ActiveRecord::Rollback)
end # when :transactional is set to true
+
+ context "when :transactional is not set to true" do
+ setup { Riot::Context.new("Room") {} }
+
+ asserts("executing context does not raise errors") do
+ topic.local_run(Riot::SilentReporter.new, Riot::Situation.new)
+ end.exists
+ end # when :transactional is not set
+
end # Transactional middleware

0 comments on commit 812ce65

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