crashbreak 1.0.13 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7d7adc44cb4ad259ba9627c926170b36c080cea
4
- data.tar.gz: f51a90e5561978dd29a6836cad108b3507aa16c5
3
+ metadata.gz: 904203ea7ed2cd94f8d54f6284cd35e2a4fb8ebd
4
+ data.tar.gz: f020c5add4fd7dbf4bb64962417d019c57544335
5
5
  SHA512:
6
- metadata.gz: d1d37ea7d5404919d3728bd5ced392772882dd3f17bbf898b44d49313f55eae38a2a1c7d09a9258cea39c2ce8ef2295fcc3316c7d8ba81a4b8c8e9da35490fb1
7
- data.tar.gz: bac31d0b6f414665d9c6cbfff6c9d51fb95cdf6b4ca3c4cc2b76b784bc2ebe8161a75809087ca411d59057a3f7edf955000c7e93d81e5ad99779d05d1facd78e
6
+ metadata.gz: 2362b171d9a7d138aef122f2a23000c97b48f9db5639323f95447fd5c46b6fce620a27cff8529fcc3f8247a535ddb223f2ac015abbb2aafb3158fe69ef4b408a
7
+ data.tar.gz: 87d5b065264b13b7852ed3a44bbdb5dd54383bd65b5eb1d3fbb30f0e2f33de934b10e64131f0824000269d893d8544d8261d4bd08b6f99247497219839fc9ad0
@@ -1,4 +1,3 @@
1
- require 'rails'
2
1
  require 'faraday'
3
2
  require 'request_store'
4
3
  require 'octokit'
@@ -35,20 +34,16 @@ require 'restorers/database_restorer'
35
34
  require 'restorers/state_restorer'
36
35
  require 'restorers/request_restorer'
37
36
 
37
+ require 'crashbreak/railtie' if defined?(Rails::Railtie)
38
+
38
39
  module Crashbreak
39
40
  extend Configurable
40
41
 
41
- class Railtie < ::Rails::Railtie
42
- initializer 'crashbreak.add_middleware' do
43
- Rails.application.middleware.use Crashbreak::ExceptionCatcherMiddleware
44
- end
45
-
46
- rake_tasks do
47
- load 'tasks/crashbreak.rake'
48
- end
49
- end
50
-
51
42
  def self.root
52
43
  File.expand_path '../..', __FILE__
53
44
  end
54
- end
45
+
46
+ def self.project_root
47
+ self.configurator.project_root
48
+ end
49
+ end
@@ -8,6 +8,8 @@ module Crashbreak
8
8
  attr_accessor :dumper_options
9
9
  attr_accessor :restorer_options
10
10
  attr_accessor :request_spec_file_path
11
+ attr_accessor :request_spec_template_path
12
+ attr_accessor :project_root
11
13
 
12
14
  attr_accessor :github_login
13
15
  attr_accessor :github_password
@@ -27,10 +29,18 @@ module Crashbreak
27
29
  @error_serializers ||= []
28
30
  end
29
31
 
32
+ def project_root
33
+ @project_root ||= (Rails.root if defined?(Rails))
34
+ end
35
+
30
36
  def request_spec_file_path
31
37
  @request_spec_file_path ||= 'crashbreak_error_spec.rb'
32
38
  end
33
39
 
40
+ def request_spec_template_path
41
+ @request_spec_template_path ||= "#{Crashbreak.root}/lib/generators/crashbreak/templates/rspec_test.rb"
42
+ end
43
+
34
44
  def github_development_branch
35
45
  @github_development_branch ||= 'master'
36
46
  end
@@ -1,16 +1,24 @@
1
1
  module Crashbreak
2
2
  class ExceptionNotifier
3
3
  def notify
4
- response = exceptions_repository.create serialize_exception
5
- GithubIntegrationService.new(response).push_test if Crashbreak.configure.github_repo_name.present? && response['similar'] == false
4
+ RequestStore.store[:server_response] = exceptions_repository.create serialize_exception
5
+
6
+ if created_error_is_unique?
7
+ dump_system_and_update_report
8
+
9
+ GithubIntegrationService.new(server_response).push_test if Crashbreak.configure.github_repo_name.present?
10
+ end
6
11
  end
7
12
 
8
13
  private
9
14
 
15
+ def dump_system_and_update_report
16
+ exceptions_repository.update server_response['id'], dumpers_data: dumpers_data
17
+ end
18
+
10
19
  def serialize_exception
11
20
  {}.tap do |exception_hash|
12
21
  serializers.each { |serializer| exception_hash.deep_merge!(serializer.serialize) }
13
- exception_hash[:dumpers_data] = dumpers_data
14
22
  end
15
23
  end
16
24
 
@@ -33,5 +41,13 @@ module Crashbreak
33
41
  def exceptions_repository
34
42
  @exceptions_repository ||= ExceptionsRepository.new
35
43
  end
44
+
45
+ def created_error_is_unique?
46
+ !server_response['similar']
47
+ end
48
+
49
+ def server_response
50
+ RequestStore.store[:server_response]
51
+ end
36
52
  end
37
53
  end
@@ -10,6 +10,10 @@ module Crashbreak
10
10
  resolve_request error_id
11
11
  end
12
12
 
13
+ def update(error_id, hash)
14
+ update_request(error_id, hash)
15
+ end
16
+
13
17
  private
14
18
 
15
19
  def post_request(error_report_hash)
@@ -21,9 +25,13 @@ module Crashbreak
21
25
  end
22
26
 
23
27
  def resolve_request(error_id)
28
+ update_request(error_id, status: :resolved)
29
+ end
30
+
31
+ def update_request(error_id, body)
24
32
  connection.put do |req|
25
33
  req.url resolve_request_url(error_id)
26
- req.body = { error_report: { status: :resolved } }.to_json
34
+ req.body = { error_report: body }.to_json
27
35
  req.headers['Content-Type'] = 'application/json'
28
36
  end
29
37
  end
@@ -49,7 +49,7 @@ module Crashbreak
49
49
  end
50
50
 
51
51
  def file_content
52
- test_file_content = File.read("#{Crashbreak.root}/lib/generators/crashbreak/templates/test.rb")
52
+ test_file_content = File.read(Crashbreak.configurator.request_spec_template_path)
53
53
  test_file_content.gsub('<%= error_id %>', @error_id.to_s)
54
54
  end
55
55
 
@@ -1,57 +1,69 @@
1
1
  module Crashbreak
2
2
  class PredefinedSettings
3
- DEFAULT_DUMP_LOCATION = "#{Rails.root}/tmp/db.dump"
3
+ class << self
4
+ def dump_file_location
5
+ "#{Crashbreak.project_root}/tmp/:error_id:/db.dump"
6
+ end
4
7
 
5
- def postgresql(db_name)
6
- setup_restorer_for_postgresql
8
+ def dump_folder_location
9
+ "#{Crashbreak.project_root}/tmp/:error_id:/db_dump"
10
+ end
7
11
 
8
- config.dumper_options.reverse_merge!(
9
- dump_location: DEFAULT_DUMP_LOCATION,
10
- dump_command: "pg_dump -Fc #{db_name} > #{DEFAULT_DUMP_LOCATION}"
11
- )
12
- end
12
+ def postgresql(db_name)
13
+ setup_restorer_for_postgresql
13
14
 
14
- def heroku_postgresql(db_name, app_name)
15
- setup_restorer_for_postgresql
15
+ config.dumper_options.reverse_merge!(
16
+ dump_location: dump_file_location,
17
+ dump_command: "pg_dump -Fc #{db_name} > #{dump_file_location}"
18
+ )
19
+ end
16
20
 
17
- config.dumper_options.reverse_merge!(
18
- dump_location: DEFAULT_DUMP_LOCATION,
19
- dump_command: "/app/vendor/heroku-toolbelt/bin/heroku pg:backups capture #{db_name} -a #{app_name} &&" +
20
- "curl -o #{DEFAULT_DUMP_LOCATION} `/app/vendor/heroku-toolbelt/bin/heroku pg:backups public-url --app #{app_name}`"
21
- )
22
- end
21
+ def heroku_postgresql(db_name, app_name)
22
+ setup_restorer_for_postgresql
23
23
 
24
- def mongodb(db_name)
25
- setup_restorer_for_mongo(db_name)
24
+ config.dumper_options.reverse_merge!(
25
+ dump_location: dump_file_location,
26
+ dump_command: "/app/vendor/heroku-toolbelt/bin/heroku pg:backups capture #{db_name} -a #{app_name} &&" +
27
+ "curl -o #{dump_file_location} `/app/vendor/heroku-toolbelt/bin/heroku pg:backups public-url --app #{app_name}`"
28
+ )
29
+ end
26
30
 
27
- config.dumper_options.reverse_merge!(
28
- dump_location: DEFAULT_DUMP_LOCATION,
29
- dump_command: "mongodump --db #{db_name} --out #{Rails.root}/tmp/db_dump && tar -cvf #{DEFAULT_DUMP_LOCATION} #{Rails.root}/tmp/db_dump"
30
- )
31
- end
31
+ def mongodb(db_name)
32
+ setup_restorer_for_mongo(db_name)
32
33
 
33
- private
34
+ config.dumper_options.reverse_merge!(
35
+ dump_location: dump_file_location,
36
+ dump_command: "mongodump --db #{db_name} --out #{dump_folder_location} &&
37
+ tar -cvf #{dump_file_location} -C #{dump_folder_location} . &&
38
+ rm -rf #{dump_folder_location}"
39
+ )
40
+ end
34
41
 
35
- def setup_restorer_for_postgresql
36
- config.restorer_options.reverse_merge!(
37
- drop_test_database_command: 'dropdb crashbreak-test',
38
- create_test_database_command: 'createdb -T template0 crashbreak-test',
39
- restore_command: "pg_restore -O #{Rails.root}/tmp/db.dump -d crashbreak-test",
40
- setup_database_connection: -> { ActiveRecord::Base.establish_connection(YAML.load(File.read('config/database.yml'))[:crashbreak_test]) }
41
- )
42
- end
42
+ private
43
43
 
44
- def setup_restorer_for_mongo(db_name)
45
- config.restorer_options.reverse_merge!(
46
- drop_test_database_command: 'mongo crashbreak-test --eval "db.dropDatabase()"',
47
- create_test_database_command: '',
48
- restore_command: "tar -xf #{Rails.root}/tmp/db.dump -C #{Rails.root}/tmp/db_dump && mongorestore --db crashbreak-test #{Rails.root}/tmp/db_dump/#{db_name}",
49
- setup_database_connection: -> { Mongoid.load!("#{Rails.root}/config/mongoid.yml", :crashbreak_test) }
50
- )
51
- end
44
+ def setup_restorer_for_postgresql
45
+ config.restorer_options.reverse_merge!(
46
+ drop_test_database_command: 'dropdb crashbreak-test',
47
+ create_test_database_command: 'createdb -T template0 crashbreak-test',
48
+ restore_command: "pg_restore -O #{dump_file_location} -d crashbreak-test",
49
+ setup_database_connection: -> { ActiveRecord::Base.establish_connection(YAML.load(File.read("#{Crashbreak.project_root}/config/database.yml"))['crashbreak_test']) }
50
+ )
51
+ end
52
+
53
+ def setup_restorer_for_mongo(db_name)
54
+ config.restorer_options.reverse_merge!(
55
+ drop_test_database_command: 'mongo crashbreak-test --eval "db.dropDatabase()"',
56
+ create_test_database_command: '',
57
+ restore_command: "mkdir -p #{dump_folder_location} &&
58
+ tar -xf #{dump_file_location} -C #{dump_folder_location} &&
59
+ mongorestore --db crashbreak-test #{dump_folder_location}/#{db_name}",
60
+ setup_database_connection: -> { Mongoid.load!("#{Crashbreak.project_root}/config/mongoid.yml", :crashbreak_test) }
61
+ )
62
+ end
52
63
 
53
- def config
54
- Crashbreak.configurator
64
+ def config
65
+ Crashbreak.configurator
66
+ end
55
67
  end
56
68
  end
57
69
  end
@@ -0,0 +1,13 @@
1
+ require 'rails'
2
+
3
+ module Crashbreak
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'crashbreak.add_middleware' do
6
+ Rails.application.middleware.use Crashbreak::ExceptionCatcherMiddleware
7
+ end
8
+
9
+ rake_tasks do
10
+ load 'tasks/crashbreak.rake'
11
+ end
12
+ end
13
+ end
@@ -23,7 +23,7 @@ module Crashbreak
23
23
  end
24
24
 
25
25
  def request_hash_as_string
26
- @request['action_dispatch.request.request_parameters'] || '{}'
26
+ @request['rack.request.form_hash'] || '{}'
27
27
  end
28
28
 
29
29
  def request_headers
@@ -1,3 +1,3 @@
1
1
  module Crashbreak
2
- VERSION = '1.0.13'
2
+ VERSION = '1.0.14'
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'digest/md5'
1
+ require 'fileutils'
2
2
 
3
3
  module Crashbreak
4
4
  class DatabaseDumper < BasicFormatter
@@ -6,20 +6,22 @@ module Crashbreak
6
6
 
7
7
  def dump
8
8
  prepare_aws
9
-
10
- if dump_not_exist_yet?
11
- dump_database
12
- upload_dump
13
- remove_locally_dump
14
- end
9
+ make_directories
10
+ dump_database
11
+ upload_dump
12
+ remove_locally_dump
15
13
 
16
14
  { file_name: aws_file_name }
17
15
  end
18
16
 
19
17
  private
20
18
 
19
+ def make_directories
20
+ FileUtils::mkdir_p "#{Crashbreak.project_root}/tmp/#{error_id}/"
21
+ end
22
+
21
23
  def dump_database
22
- system(dump_command)
24
+ system(gsub_error_id(dump_command))
23
25
  end
24
26
 
25
27
  def upload_dump
@@ -31,19 +33,23 @@ module Crashbreak
31
33
  end
32
34
 
33
35
  def aws_file_name
34
- "Crashbreak - database dump #{Digest::MD5.hexdigest(ENV['RACK_ENV'] + exception.class.to_s + exception.backtrace[0])}"
35
- end
36
-
37
- def dump_not_exist_yet?
38
- !aws_resource_bucket.object(aws_file_name).exists?
36
+ @aws_file_name ||= "Crashbreak - database dump #{Time.now} (#{Time.now.to_f})"
39
37
  end
40
38
 
41
39
  def dump_location
42
- Crashbreak.configure.dumper_options[:dump_location]
40
+ gsub_error_id(Crashbreak.configure.dumper_options[:dump_location])
43
41
  end
44
42
 
45
43
  def dump_command
46
44
  Crashbreak.configure.dumper_options[:dump_command]
47
45
  end
46
+
47
+ def gsub_error_id(text)
48
+ text.gsub(':error_id:', error_id)
49
+ end
50
+
51
+ def error_id
52
+ RequestStore.store[:server_response]['id'].to_s
53
+ end
48
54
  end
49
55
  end
@@ -0,0 +1,14 @@
1
+ require_relative 'test/test_helper.rb'
2
+
3
+ class ErrorRequestTest < ActionDispatch::IntegrationTest
4
+ def setup
5
+ @restorers_data = StateRestorer.new('<%= error_id %>').restore
6
+ @request_parser = Crashbreak::RequestParser.new @restorers_data[:request]
7
+ end
8
+
9
+ def test_sending_request
10
+ @request_parser.request_data do |request_method, url, body, headers|
11
+ method(request_method).call url, body, headers
12
+ end
13
+ end
14
+ end
@@ -5,7 +5,7 @@ module Crashbreak
5
5
  argument :error_id, type: :string
6
6
 
7
7
  def create_test_file
8
- template 'test.rb', Crashbreak.configurator.request_spec_file_path
8
+ template Crashbreak.configurator.request_spec_template_path, Crashbreak.configurator.request_spec_file_path
9
9
  end
10
10
  end
11
11
  end
@@ -1,8 +1,11 @@
1
+ require 'fileutils'
2
+
1
3
  module Crashbreak
2
4
  class DatabaseRestorer
3
5
  include AWS
4
6
 
5
7
  def initialize(dump_data)
8
+ @error_id = dump_data['error_id']
6
9
  @file_name = dump_data['file_name']
7
10
  end
8
11
 
@@ -10,33 +13,40 @@ module Crashbreak
10
13
  system(drop_test_database_command)
11
14
  system(create_test_database_command)
12
15
  prepare_aws
13
- download_dump
16
+ make_directories
17
+ download_dump unless dump_already_downloaded
14
18
  restore_database
15
19
  setup_connection_to_restored_database
16
20
  end
17
21
 
18
22
  private
19
23
 
24
+ def make_directories
25
+ FileUtils::mkdir_p "#{Crashbreak.project_root}/tmp/#{@error_id}/"
26
+ end
27
+
20
28
  def restore_database
21
29
  system(restore_command)
22
30
  end
23
31
 
24
32
  def download_dump
25
- Dir.mkdir("#{Rails.root}/tmp/") unless File.exists?("#{Rails.root}/tmp/")
26
-
27
- File.open("#{Rails.root}/tmp/db.dump", 'wb') do |file|
33
+ File.open(restore_location, 'wb') do |file|
28
34
  client.get_object(bucket: bucket_name, key: @file_name) do |data|
29
35
  file.write(data)
30
36
  end
31
37
  end
32
38
  end
33
39
 
40
+ def dump_already_downloaded
41
+ File.exists?(restore_location)
42
+ end
43
+
34
44
  def setup_connection_to_restored_database
35
45
  Crashbreak.configure.restorer_options[:setup_database_connection].call
36
46
  end
37
47
 
38
48
  def restore_command
39
- Crashbreak.configure.restorer_options[:restore_command]
49
+ gsub_error_id(Crashbreak.configure.restorer_options[:restore_command])
40
50
  end
41
51
 
42
52
  def drop_test_database_command
@@ -46,5 +56,13 @@ module Crashbreak
46
56
  def create_test_database_command
47
57
  Crashbreak.configure.restorer_options[:create_test_database_command]
48
58
  end
59
+
60
+ def restore_location
61
+ gsub_error_id(Crashbreak.configure.dumper_options[:dump_location])
62
+ end
63
+
64
+ def gsub_error_id(text)
65
+ text.gsub(':error_id:', @error_id)
66
+ end
49
67
  end
50
68
  end
@@ -28,7 +28,7 @@ class StateRestorer
28
28
 
29
29
  def dumper_data(restorer)
30
30
  dumper_name = restorer.to_s.gsub('Restorer', 'Dumper')
31
- dumpers_data[dumper_name]
31
+ dumpers_data[dumper_name].merge('error_id' => @error_id)
32
32
  end
33
33
 
34
34
  def key_name(restorer)
@@ -18,8 +18,8 @@ namespace :crashbreak do
18
18
  error_id = ENV['error_id']
19
19
 
20
20
  unless error_id
21
- next unless File.exist?("#{Rails.root}/#{Crashbreak.configurator.request_spec_file_path}")
22
- error_id = File.read("#{Rails.root}/#{Crashbreak.configurator.request_spec_file_path}").scan(/error id: \d+/).first.gsub('error id: ', '').to_i
21
+ next unless File.exist?("#{Crashbreak.project_root}/#{Crashbreak.configurator.request_spec_file_path}")
22
+ error_id = File.read("#{Crashbreak.project_root}/#{Crashbreak.configurator.request_spec_file_path}").scan(/error id: \d+/).first.gsub('error id: ', '').to_i
23
23
  end
24
24
 
25
25
  service = Crashbreak::GithubIntegrationService.new 'id' => error_id
@@ -35,7 +35,7 @@ namespace :crashbreak do
35
35
  end
36
36
 
37
37
  task run_test: :environment do
38
- unless File.exist?("#{Rails.root}/#{Crashbreak.configurator.request_spec_file_path}")
38
+ unless File.exist?("#{Crashbreak.project_root}/#{Crashbreak.configurator.request_spec_file_path}")
39
39
  next puts 'Crashbreak spec not found, skipping.'
40
40
  end
41
41
 
@@ -17,6 +17,7 @@ describe 'Sending error report to server' do
17
17
  allow(crashing_app).to receive(:call).and_raise(example_error)
18
18
  allow(example_error).to receive(:backtrace).and_return(%w(example backtrace))
19
19
  allow_any_instance_of(Crashbreak::BasicFormatter).to receive(:request).and_return(example_request)
20
+ allow(Crashbreak.configurator).to receive(:ignored_environments).and_return([])
20
21
  end
21
22
 
22
23
  let!(:create_exception_request) do
@@ -29,13 +30,21 @@ describe 'Sending error report to server' do
29
30
  name: example_error.to_s, message: example_error.message, backtrace: example_error.backtrace, environment: 'test',
30
31
  summary: { action: example_request.env['PATH_INFO'], controller_name: example_controller.class.to_s,
31
32
  file: example_error.backtrace[0], url: example_request.env['REQUEST_URI'], user_agent: example_request.env['HTTP_USER_AGENT'] },
32
- additional_data: { environment: ENV.to_hash, test: { formatter: true } },
33
- dumpers_data: { 'RequestDumper' => example_request.env }
33
+ additional_data: { environment: ENV.to_hash, test: { formatter: true } }
34
34
  }
35
35
  end
36
36
 
37
+ let!(:update_exception_request) do
38
+ stub_request(:put, "#{Crashbreak::ExceptionsRepository::BASE_URL}/projects/#{project_token}/errors/1").
39
+ with(body: dumpers_data.to_json).to_return(status: 200)
40
+ end
41
+
42
+ let(:dumpers_data) { Hash[error_report: { dumpers_data: { 'RequestDumper' => example_request.env } }] }
43
+
37
44
  it 'sends error report on exception' do
38
45
  expect{ catching_middleware.call(env) }.to raise_error(TestError)
46
+
39
47
  expect(create_exception_request).to have_been_made
48
+ expect(update_exception_request).to have_been_made
40
49
  end
41
50
  end
@@ -16,6 +16,7 @@ describe Crashbreak::ExceptionCatcherMiddleware do
16
16
 
17
17
  before(:each) do
18
18
  expect_any_instance_of(Crashbreak::ExceptionNotifier).to receive(:notify).and_return(true)
19
+ allow(Crashbreak.configurator).to receive(:ignored_environments).and_return([])
19
20
  expect{ subject.call(env) }.to raise_error(error.class)
20
21
  end
21
22
 
@@ -9,24 +9,32 @@ describe Crashbreak::ExceptionNotifier do
9
9
  allow_any_instance_of(Crashbreak::Configurator).to receive(:error_serializers).and_return([])
10
10
  allow_any_instance_of(described_class).to receive(:dumpers).and_return([])
11
11
  allow_any_instance_of(Crashbreak::GithubIntegrationService).to receive(:push_test).and_return(true)
12
+ allow_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:update).and_return(true)
12
13
 
13
14
  RequestStore[:exception] = error
14
15
  RequestStore[:request] = double(:request, env: { request: :example_request_data } )
15
16
  end
16
17
 
17
18
  let(:exception_basic_hash) do
18
- { name: error_name, message: error_message, backtrace: error.backtrace, environment: ENV['RACK_ENV'], dumpers_data: {} }
19
+ { name: error_name, message: error_message, backtrace: error.backtrace, environment: ENV['RACK_ENV'] }
20
+ end
21
+
22
+ let(:example_response) { Hash['error_id' => 1, 'similar_error' => false] }
23
+
24
+ it 'stores server response in request store' do
25
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(exception_basic_hash).and_return(:example_server_response)
26
+ subject.notify
27
+
28
+ expect(RequestStore.store[:server_response]).to eq(:example_server_response)
19
29
  end
20
30
 
21
31
  context 'without additional serializers' do
22
32
  it 'sends pure error' do
23
- expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(exception_basic_hash)
33
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(exception_basic_hash).and_return(:example_server_response)
24
34
  subject.notify
25
35
  end
26
36
 
27
37
  context 'with dumpers' do
28
- let(:expected_hash) { exception_basic_hash.merge(dumpers_hash) }
29
-
30
38
  let(:dumpers_hash) do
31
39
  { dumpers_data: { 'RequestDumper' => { request: 'example_request_data' } } }
32
40
  end
@@ -36,7 +44,16 @@ describe Crashbreak::ExceptionNotifier do
36
44
  end
37
45
 
38
46
  it 'sends dump data' do
39
- expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(expected_hash)
47
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).and_return('id' => 1, 'similar' => false)
48
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:update).with(1, dumpers_hash)
49
+
50
+ subject.notify
51
+ end
52
+
53
+ it 'skips dump if error is similar' do
54
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).and_return('id' => 1, 'similar' => true)
55
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to_not receive(:update).with(1, dumpers_hash)
56
+
40
57
  subject.notify
41
58
  end
42
59
  end
@@ -56,7 +73,7 @@ describe Crashbreak::ExceptionNotifier do
56
73
  end
57
74
 
58
75
  it 'sends formatted error' do
59
- expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(expected_hash)
76
+ expect_any_instance_of(Crashbreak::ExceptionsRepository).to receive(:create).with(expected_hash).and_return(example_response)
60
77
  subject.notify
61
78
  end
62
79
  end
@@ -21,7 +21,7 @@ describe Crashbreak::RequestParser do
21
21
  context 'post with body' do
22
22
  let(:request_data) { Hash['REQUEST_METHOD' => 'POST', 'PATH_INFO' => '/projects',
23
23
  'HTTP_ACCEPT' => 'text/html', 'HTTP_CACHE_CONTROL' => 'max-age=0',
24
- 'action_dispatch.request.request_parameters' => request_parameters.to_json
24
+ 'rack.request.form_hash' => request_parameters.to_json
25
25
  ]}
26
26
 
27
27
  let(:request_parameters) { Hash[test_parameter: 'test_value', second_test_parameter: 'second_test_value'] }
@@ -10,12 +10,17 @@ describe StateRestorer do
10
10
  to_return(status: 200, body: dumpers_data.to_json)
11
11
  end
12
12
 
13
- let(:dumpers_data) { Hash['TestDumper' => 'test_data'] }
13
+ let(:dumpers_data) { Hash['TestDumper' => { test_key: 'test_data' } ] }
14
14
 
15
15
  it 'returns a hash with all restorers data' do
16
- expect_any_instance_of(TestRestorer).to receive(:initialize).with('test_data')
16
+ expect_any_instance_of(TestRestorer).to receive(:initialize)
17
17
  expect(subject.restore).to eq(test: 'restored_test_data')
18
18
  end
19
+
20
+ it 'passes dumper data with error id to restorer' do
21
+ expect_any_instance_of(TestRestorer).to receive(:initialize).with('test_key' => 'test_data', 'error_id' => error_id)
22
+ subject.restore
23
+ end
19
24
  end
20
25
 
21
26
  class TestRestorer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crashbreak
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Janeczek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-08 00:00:00.000000000 Z
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -241,6 +241,7 @@ files:
241
241
  - lib/crashbreak/formatters/summary_formatter.rb
242
242
  - lib/crashbreak/github_integration_service.rb
243
243
  - lib/crashbreak/predefined_settings.rb
244
+ - lib/crashbreak/railtie.rb
244
245
  - lib/crashbreak/request_parser.rb
245
246
  - lib/crashbreak/tiny_exception_notifier.rb
246
247
  - lib/crashbreak/version.rb
@@ -248,7 +249,8 @@ files:
248
249
  - lib/dumpers/request_dumper.rb
249
250
  - lib/generators/crashbreak/install_generator.rb
250
251
  - lib/generators/crashbreak/templates/crashbreak.rb
251
- - lib/generators/crashbreak/templates/test.rb
252
+ - lib/generators/crashbreak/templates/minitest_test.rb
253
+ - lib/generators/crashbreak/templates/rspec_test.rb
252
254
  - lib/generators/crashbreak/test_generator.rb
253
255
  - lib/restorers/database_restorer.rb
254
256
  - lib/restorers/request_restorer.rb