README.md in action_tracker_client-0.0.1 vs README.md in action_tracker_client-0.1.0

- old
+ new

@@ -1,12 +1,11 @@ # ActionTracker [![Build Status](https://semaphoreci.com/api/v1/ipm/action_tracker/branches/master/badge.svg)](https://semaphoreci.com/ipm/action_tracker) [![Maintainability](https://api.codeclimate.com/v1/badges/cfdcabfc3610c6eac895/maintainability)](https://codeclimate.com/github/psyipm/action_tracker/maintainability) -[![Gem Version](https://badge.fury.io/rb/action_tracker.svg)](https://badge.fury.io/rb/action_tracker) +[![Gem Version](https://badge.fury.io/rb/action_tracker_client.svg)](https://badge.fury.io/rb/action_tracker_client) - ## Installation Add this line to your application's Gemfile: ```ruby @@ -32,10 +31,19 @@ ActionTracker.configure do |config| config.api_url = ENV['ACTION_TRACKING_API_URL'] config.api_key = ENV['ACTION_TRACKING_API_KEY'] config.api_secret = ENV['ACTION_TRACKING_API_SECRET'] + + # Avalilable options: + # + # :inline (default) -> performs request to external API + # :test -> stores request parameters, can be accessed via ActionTracker.records + # :custom -> calls custom labda + # + config.tracking_method = :custom + config.custom_worker_proc = ->(form) { MyCustomActionTrackingJob.perform_later(form.attributes) } end ``` ### Reading records @@ -140,9 +148,49 @@ end # Call recorder ActionTracker::Recorder.new(:state_change).call(target) ActionTracker::Recorder.new('Orders::SomeCustomEvent').call(target) +``` + +## Testing + +Set tracking method to `:test` in application environment config and clear records after each spec + +```ruby + # config/environments/test.rb + + config.after_initialize do + ActionTracker.config.tracking_method = :test + end + + # spec/rails_helper.rb + + config.after(:each) do + ActionTracker.clear_records + end +``` + +```ruby + ActionTracker.records + + => [{:target_id=>76, :target_type=>"Order", :payload=>{:event=>"Created payment #89", :content=>"amount 100.0", :user=>{:id=>0, :name=>"Anonymous", :type=>"System"}}, :reference_id=>89, :reference_type=>"PaymentTransaction"}] + + ActionTracker.last_event + + => "Created payment #89" + + ActionTracker.records.select_by('payload.user.name', 'Anonymous') + + => [{:target_id=>76, :target_type=>"Order"..... + + ActionTracker.records.last_content + + => "amount 100.0" + + ActionTracker.records.select_by('payload.user.name', 'SomeUser') + + => [] ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.