Skip to content
Browse files

Merge branch 'js_notifier_default_fields'

  • Loading branch information...
2 parents 3c65260 + 49512d1 commit e704f67fa12c1c751f2ac6913dc2c042e7712187 Emma Lindsay committed
View
3 features/rails_with_js_notifier.feature
@@ -21,6 +21,9 @@ Feature: Install the Gem in a Rails application and enable the JavaScript notifi
Then I should see the notifier JavaScript for the following:
| api_key | environment | host |
| myapikey | production | hoptoadapp.com |
+ And the notifier JavaScript should provide the following errorDefaults:
+ | url | component | action |
+ | http://example.com:123/test/index | test | index |
Scenario: Include the Javascript notifier when enabled using custom configuration settings
When I generate a new Rails application
View
15 features/step_definitions/rails_application_steps.rb
@@ -338,6 +338,21 @@ def rails_non_initializer_hoptoad_config_file
end
end
+Then "the notifier JavaScript should provide the following errorDefaults:" do |table|
+ hash = table.hashes.first
+
+ document_body = '<html>' + @terminal.output.split('<html>').last
+
+ response = Nokogiri::HTML.parse(document_body)
+ response.css("script[type='text/javascript']:last-child").each do |element|
+ content = element.content
+
+ hash.each do |key, value|
+ content.should =~ %r{Hoptoad\.setErrorDefaults.*#{key}: "#{value}}m
+ end
+ end
+end
+
Then /^I should not see notifier JavaScript$/ do
response = Nokogiri::HTML.parse('<html>' + @terminal.output.split('<html>').last)
response.at_css("script[type='text/javascript'][src$='/javascripts/notifier.js']").should be_nil
View
5 lib/templates/javascript_notifier.erb
@@ -9,4 +9,9 @@ document.write(unescape("%3Cscript src='" + notifierJsScheme + "<%= host %>/java
Hoptoad.setKey('<%= api_key %>');
Hoptoad.setHost('<%= host %>');
Hoptoad.setEnvironment('<%= environment %>');
+ Hoptoad.setErrorDefaults({
+ url: "<%= request.url %>",
+ component: "<%= controller_name %>",
+ action: "<%= action_name %>"
+ });
</script>

0 comments on commit e704f67

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