Skip to content

Commit

Permalink
Merge pull request #337 from airbrake/fix/rails4-is-here
Browse files Browse the repository at this point in the history
Add 4 to version sniffing code
  • Loading branch information
dvdplm committed Sep 24, 2014
2 parents 8b14c68 + f1729f9 commit c1332d6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
12 changes: 6 additions & 6 deletions features/support/rails.rb
Expand Up @@ -24,16 +24,16 @@ def application_controller_filename
controller_filename = File.join(rails_root, 'app', 'controllers', "application_controller.rb")
end

def rails3?
rails_version =~ /^3/
def rails_3_or_4?
rails_version =~ /\A[34]/
end

def rails_root
LOCAL_RAILS_ROOT
end

def rails_uses_rack?
rails3? || rails_version =~ /^2\.3/
rails_3_or_4? || rails_version =~ /^2\.3/
end

def rails_version
Expand All @@ -58,15 +58,15 @@ def gemfile_path
end

def rails_manages_gems?
rails_version =~ /^2\.[123]/
rails_version =~ /\A2\.[123]/
end

def rails_supports_initializers?
rails3? || rails_version =~ /^2\./
rails_3_or_4? || rails_version =~ /\A2\./
end

def rails_finds_generators_in_gems?
rails3? || rails_version =~ /^2\./
rails_3_or_4? || rails_version =~ /\A2\./
end

def version_string
Expand Down
9 changes: 5 additions & 4 deletions lib/airbrake/rails/controller_methods.rb
Expand Up @@ -44,20 +44,21 @@ def airbrake_filter_if_filtering(hash)

if respond_to?(:filter_parameters) # Rails 2
filter_parameters(hash)
elsif rails3?
elsif rails_3_or_4?
filter_rails3_parameters(hash)
else
hash
end
end

def rails3?
defined?(::Rails.version) && ::Rails.version =~ /\A3/
def rails_3_or_4?
defined?(::Rails.version) && ::Rails.version =~ /\A[34]/
end

def filter_rails3_parameters(hash)
ActionDispatch::Http::ParameterFilter.new(
::Rails.application.config.filter_parameters).filter(hash)
::Rails.application.config.filter_parameters
).filter(hash)
end

def airbrake_session_data
Expand Down
29 changes: 27 additions & 2 deletions test/controller_methods_test.rb
Expand Up @@ -61,9 +61,11 @@ def id
::Rails = Object.new
::Rails.stubs(:version).returns("3.2.17")
end
should "respond to rails3? with true" do
assert @controller.send(:rails3?)

should "respond to rails_3_or_4? with true" do
assert @controller.send(:rails_3_or_4?)
end

should "call filter_rails3_parameters" do
hash = {:a => "b"}
filtered_hash = {:c => "d"}
Expand All @@ -74,4 +76,27 @@ def id
@controller.send(:airbrake_filter_if_filtering, hash)
end
end

context "Rails 4.x" do
setup do
@controller = TestController.new
::Rails = Object.new
::Rails.stubs(:version).returns("4.5.6.7")
end

should 'be true when running Rails 4.x' do
assert @controller.send(:rails_3_or_4?)
end

should "call filter_rails3_parameters" do
hash = {:a => "b"}
filtered_hash = {:c => "d"}

@controller.expects(:filter_rails3_parameters).with(hash).
returns(filtered_hash)
assert_equal filtered_hash,
@controller.send(:airbrake_filter_if_filtering, hash)
end
end

end

0 comments on commit c1332d6

Please sign in to comment.