solidus_events_tracker 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +73 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +26 -0
  5. data/README.md +52 -0
  6. data/Rakefile +21 -0
  7. data/app/assets/javascripts/spree/backend/solidus_events_tracker.js +2 -0
  8. data/app/assets/javascripts/spree/frontend/solidus_events_tracker.js +2 -0
  9. data/app/assets/stylesheets/spree/backend/solidus_events_tracker.css +4 -0
  10. data/app/assets/stylesheets/spree/frontend/solidus_events_tracker.css +4 -0
  11. data/app/controllers/concerns/spree/checkout_event_tracker.rb +28 -0
  12. data/app/controllers/concerns/spree/page_tracker.rb +55 -0
  13. data/app/controllers/spree/checkout_controller_decorator.rb +22 -0
  14. data/app/controllers/spree/home_controller_decorator.rb +4 -0
  15. data/app/controllers/spree/orders_controller_decorator.rb +32 -0
  16. data/app/controllers/spree/products_controller_decorator.rb +4 -0
  17. data/app/controllers/spree/taxons_controller_decorator.rb +4 -0
  18. data/app/models/concerns/spree/order_contents_decorator.rb +38 -0
  19. data/app/models/spree/cart_event.rb +20 -0
  20. data/app/models/spree/checkout_event.rb +11 -0
  21. data/app/models/spree/page_event.rb +14 -0
  22. data/app/trackers/spree/cart/event/tracker.rb +44 -0
  23. data/app/trackers/spree/checkout/event/tracker.rb +18 -0
  24. data/app/trackers/spree/event/tracker.rb +17 -0
  25. data/app/trackers/spree/page/event/tracker.rb +17 -0
  26. data/bin/rails +7 -0
  27. data/config/locales/en.yml +4 -0
  28. data/config/routes.rb +3 -0
  29. data/db/migrate/20160313145434_create_spree_cart_events.rb +15 -0
  30. data/db/migrate/20160314080710_create_spree_page_events.rb +14 -0
  31. data/db/migrate/20160314080822_create_spree_checkout_events.rb +14 -0
  32. data/lib/generators/solidus_events_tracker/install/install_generator.rb +31 -0
  33. data/lib/solidus_events_tracker.rb +2 -0
  34. data/lib/solidus_events_tracker/engine.rb +20 -0
  35. data/lib/solidus_events_tracker/factories.rb +6 -0
  36. data/solidus_events_tracker.gemspec +37 -0
  37. data/spec/controllers/spree/checkout_controller_decorator_spec.rb +132 -0
  38. data/spec/controllers/spree/orders_controller_decorator_spec.rb +136 -0
  39. data/spec/models/spree/cart_event_spec.rb +18 -0
  40. data/spec/models/spree/checkout_event_spec.rb +16 -0
  41. data/spec/models/spree/page_event_spec.rb +15 -0
  42. data/spec/spec_helper.rb +97 -0
  43. data/spec/trackers/spree/cart/event/tracker_spec.rb +67 -0
  44. data/spec/trackers/spree/checkout/event/tracker_spec.rb +33 -0
  45. data/spec/trackers/spree/event/tracker_spec.rb +29 -0
  46. data/spec/trackers/spree/page/event/tracker_spec.rb +32 -0
  47. metadata +47 -2
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::CartEvent do
4
+
5
+ describe 'associations' do
6
+ it { is_expected.to belong_to(:actor) }
7
+ it { is_expected.to belong_to(:target) }
8
+ end
9
+
10
+ describe 'validations' do
11
+ it { is_expected.to validate_presence_of(:quantity) }
12
+ it { is_expected.to validate_presence_of(:activity) }
13
+ it { is_expected.to validate_presence_of(:target) }
14
+ it { is_expected.to validate_presence_of(:actor) }
15
+ it { is_expected.to validate_presence_of(:total) }
16
+ end
17
+
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::CheckoutEvent do
4
+
5
+ describe 'associations' do
6
+ it { is_expected.to belong_to(:actor) }
7
+ it { is_expected.to belong_to(:target) }
8
+ end
9
+
10
+ describe 'validations' do
11
+ it { is_expected.to validate_presence_of(:session_id) }
12
+ it { is_expected.to validate_presence_of(:activity) }
13
+ it { is_expected.to validate_presence_of(:target) }
14
+ end
15
+
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::PageEvent do
4
+
5
+ describe 'associations' do
6
+ it { is_expected.to belong_to(:actor) }
7
+ it { is_expected.to belong_to(:target) }
8
+ end
9
+
10
+ describe 'validations' do
11
+ it { is_expected.to validate_presence_of(:session_id) }
12
+ it { is_expected.to validate_presence_of(:activity) }
13
+ end
14
+
15
+ end
@@ -0,0 +1,97 @@
1
+ # Run Coverage report
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'spec/dummy'
5
+ add_group 'Controllers', 'app/controllers'
6
+ add_group 'Helpers', 'app/helpers'
7
+ add_group 'Mailers', 'app/mailers'
8
+ add_group 'Models', 'app/models'
9
+ add_group 'Views', 'app/views'
10
+ add_group 'Libraries', 'lib'
11
+ end
12
+
13
+ # Configure Rails Environment
14
+ ENV['RAILS_ENV'] = 'test'
15
+
16
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
17
+
18
+ require 'rspec/rails'
19
+ require 'database_cleaner'
20
+ require 'ffaker'
21
+ require 'shoulda/matchers'
22
+ require 'rspec/active_model/mocks'
23
+
24
+ # Requires supporting ruby files with custom matchers and macros, etc,
25
+ # in spec/support/ and its subdirectories.
26
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
27
+
28
+ # Requires factories and other useful helpers defined in spree_core.
29
+ require 'spree/testing_support/authorization_helpers'
30
+ require 'spree/testing_support/capybara_ext'
31
+ require 'spree/testing_support/controller_requests'
32
+ require 'spree/testing_support/factories'
33
+ require 'spree/testing_support/url_helpers'
34
+
35
+ # Requires factories defined in lib/solidus_events_tracker/factories.rb
36
+ require 'solidus_events_tracker/factories'
37
+
38
+ RSpec.configure do |config|
39
+ config.include FactoryGirl::Syntax::Methods
40
+
41
+ # Infer an example group's spec type from the file location.
42
+ config.infer_spec_type_from_file_location!
43
+
44
+ # == URL Helpers
45
+ #
46
+ # Allows access to Spree's routes in specs:
47
+ #
48
+ # visit spree.admin_path
49
+ # current_path.should eql(spree.products_path)
50
+ config.include Spree::TestingSupport::UrlHelpers
51
+
52
+ # == Requests support
53
+ #
54
+ # Adds convenient methods to request Spree's controllers
55
+ # spree_get :index
56
+ config.include Spree::TestingSupport::ControllerRequests, type: :controller
57
+
58
+ # == Mock Framework
59
+ #
60
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
61
+ #
62
+ # config.mock_with :mocha
63
+ # config.mock_with :flexmock
64
+ # config.mock_with :rr
65
+ config.mock_with :rspec
66
+ config.color = true
67
+
68
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
69
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
70
+
71
+ # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
72
+ # to cleanup after each test instead. Without transactional fixtures set to false the records created
73
+ # to setup a test will be unavailable to the browser, which runs under a separate server instance.
74
+ config.use_transactional_fixtures = false
75
+
76
+ # Ensure Suite is set to use transactions for speed.
77
+ config.before :suite do
78
+ DatabaseCleaner.strategy = :transaction
79
+ DatabaseCleaner.clean_with :truncation
80
+ end
81
+
82
+ # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
83
+ config.before :each do
84
+ DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
85
+ DatabaseCleaner.start
86
+ end
87
+
88
+ # After each spec clean the database.
89
+ config.after :each do
90
+ DatabaseCleaner.clean
91
+ end
92
+
93
+ config.fail_fast = ENV['FAIL_FAST'] || false
94
+ config.order = "random"
95
+ config.include Spree::TestingSupport::ControllerRequests, type: :controller
96
+ config.infer_spec_type_from_file_location!
97
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Cart::Event::Tracker do
4
+ let(:actor) { create(:order) }
5
+ let(:target) { create(:line_item) }
6
+ let(:tracker) { Spree::Cart::Event::Tracker.new(
7
+ activity: 'test_activity',
8
+ actor: actor,
9
+ target: target,
10
+ session_id: 'test_session_id',
11
+ referrer: 'test_referrer',
12
+ quantity: 'test_quantity',
13
+ total: 'test_total'
14
+ )
15
+ }
16
+
17
+ describe '#initialize' do
18
+ it { expect(tracker.instance_variable_get(:@activity)).to eq('test_activity') }
19
+ it { expect(tracker.instance_variable_get(:@actor)).to eq(actor) }
20
+ it { expect(tracker.instance_variable_get(:@target)).to eq(target) }
21
+ it { expect(tracker.instance_variable_get(:@referrer)).to eq('test_referrer') }
22
+ it { expect(tracker.instance_variable_get(:@session_id)).to eq('test_session_id') }
23
+ it { expect(tracker.instance_variable_get(:@quantity)).to eq('test_quantity') }
24
+ it { expect(tracker.instance_variable_get(:@total)).to eq('test_total') }
25
+ end
26
+
27
+ describe '#track' do
28
+ it 'should create CartEvent object' do
29
+ expect(tracker.track).to be_instance_of(Spree::CartEvent)
30
+ end
31
+ end
32
+
33
+ describe '#changed_quantity' do
34
+ let(:previous_quantity_changes) { target.previous_changes[:quantity].map(&:to_i) }
35
+
36
+ before do
37
+ target.quantity = 8
38
+ target.save
39
+ end
40
+
41
+ it 'should return previous quantity changes' do
42
+ expect(tracker.send(:changed_quantity, previous_quantity_changes)).to be_instance_of(Fixnum)
43
+ end
44
+ end
45
+
46
+ describe '#activity' do
47
+ context 'when item is added' do
48
+ let(:changed_quantity) { target.quantity }
49
+ it { expect(tracker.send(:activity, changed_quantity, target)).to eq(:add) }
50
+ end
51
+
52
+ context 'when item is removed' do
53
+ let(:changed_quantity) { -1 }
54
+
55
+ before do
56
+ target.quantity = 0
57
+ target.save
58
+ end
59
+
60
+ it { expect(tracker.send(:activity, changed_quantity, target)).to eq(:remove) }
61
+ end
62
+
63
+ context 'when item is updated' do
64
+ it { expect(tracker.send(:activity, 7, target)).to eq(:update) }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Checkout::Event::Tracker do
4
+
5
+ let(:actor) { create(:user) }
6
+ let(:target) { create(:order) }
7
+ let(:tracker) { Spree::Checkout::Event::Tracker.new(
8
+ activity: 'test_activity',
9
+ actor: actor,
10
+ target: target,
11
+ session_id: 'test_session_id',
12
+ referrer: 'test_referrer',
13
+ previous_state: 'test_previous_state',
14
+ next_state: 'test_next_state'
15
+ )
16
+ }
17
+
18
+ describe '#initialize' do
19
+ it { expect(tracker.instance_variable_get(:@activity)).to eq('test_activity') }
20
+ it { expect(tracker.instance_variable_get(:@actor)).to eq(actor) }
21
+ it { expect(tracker.instance_variable_get(:@target)).to eq(target) }
22
+ it { expect(tracker.instance_variable_get(:@referrer)).to eq('test_referrer') }
23
+ it { expect(tracker.instance_variable_get(:@session_id)).to eq('test_session_id') }
24
+ it { expect(tracker.instance_variable_get(:@previous_state)).to eq('test_previous_state') }
25
+ it { expect(tracker.instance_variable_get(:@next_state)).to eq('test_next_state') }
26
+ end
27
+
28
+ describe '#track' do
29
+ it 'should create CheckoutEvent instance' do
30
+ expect(tracker.track).to be_instance_of(Spree::CheckoutEvent)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Event::Tracker do
4
+
5
+ let(:actor) { create(:user) }
6
+ let(:target) { create(:order) }
7
+ let(:tracker) { Spree::Event::Tracker.new(
8
+ activity: 'test_activity',
9
+ actor: actor,
10
+ target: target,
11
+ session_id: 'test_session_id',
12
+ referrer: 'test_referrer'
13
+ )
14
+ }
15
+
16
+ describe '#initialize' do
17
+ it { expect(tracker.instance_variable_get(:@activity)).to eq('test_activity') }
18
+ it { expect(tracker.instance_variable_get(:@actor)).to eq(actor) }
19
+ it { expect(tracker.instance_variable_get(:@target)).to eq(target) }
20
+ it { expect(tracker.instance_variable_get(:@referrer)).to eq('test_referrer') }
21
+ it { expect(tracker.instance_variable_get(:@session_id)).to eq('test_session_id') }
22
+ end
23
+
24
+ describe '#track' do
25
+ it 'should raise exception' do
26
+ expect{ tracker.track }.to raise_error('#track should be implemented in a sub-class of Event::Tracker')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Page::Event::Tracker do
4
+
5
+ let(:actor) { create(:user) }
6
+ let(:target) { create(:order) }
7
+ let(:tracker) { Spree::Page::Event::Tracker.new(
8
+ activity: 'test_activity',
9
+ actor: actor,
10
+ target: target,
11
+ session_id: 'test_session_id',
12
+ referrer: 'test_referrer',
13
+ search_keywords: 'test_search_keywords',
14
+ next_state: 'test_next_state'
15
+ )
16
+ }
17
+
18
+ describe '#initialize' do
19
+ it { expect(tracker.instance_variable_get(:@activity)).to eq('test_activity') }
20
+ it { expect(tracker.instance_variable_get(:@actor)).to eq(actor) }
21
+ it { expect(tracker.instance_variable_get(:@target)).to eq(target) }
22
+ it { expect(tracker.instance_variable_get(:@referrer)).to eq('test_referrer') }
23
+ it { expect(tracker.instance_variable_get(:@session_id)).to eq('test_session_id') }
24
+ it { expect(tracker.instance_variable_get(:@search_keywords)).to eq('test_search_keywords') }
25
+ end
26
+
27
+ describe '#track' do
28
+ it 'should create PageEvent object' do
29
+ expect(tracker.track).to be_instance_of(Spree::PageEvent)
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_events_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nimish Mehta
@@ -200,7 +200,52 @@ email: info@vinsol.com
200
200
  executables: []
201
201
  extensions: []
202
202
  extra_rdoc_files: []
203
- files: []
203
+ files:
204
+ - ".gitignore"
205
+ - Gemfile
206
+ - LICENSE
207
+ - README.md
208
+ - Rakefile
209
+ - app/assets/javascripts/spree/backend/solidus_events_tracker.js
210
+ - app/assets/javascripts/spree/frontend/solidus_events_tracker.js
211
+ - app/assets/stylesheets/spree/backend/solidus_events_tracker.css
212
+ - app/assets/stylesheets/spree/frontend/solidus_events_tracker.css
213
+ - app/controllers/concerns/spree/checkout_event_tracker.rb
214
+ - app/controllers/concerns/spree/page_tracker.rb
215
+ - app/controllers/spree/checkout_controller_decorator.rb
216
+ - app/controllers/spree/home_controller_decorator.rb
217
+ - app/controllers/spree/orders_controller_decorator.rb
218
+ - app/controllers/spree/products_controller_decorator.rb
219
+ - app/controllers/spree/taxons_controller_decorator.rb
220
+ - app/models/concerns/spree/order_contents_decorator.rb
221
+ - app/models/spree/cart_event.rb
222
+ - app/models/spree/checkout_event.rb
223
+ - app/models/spree/page_event.rb
224
+ - app/trackers/spree/cart/event/tracker.rb
225
+ - app/trackers/spree/checkout/event/tracker.rb
226
+ - app/trackers/spree/event/tracker.rb
227
+ - app/trackers/spree/page/event/tracker.rb
228
+ - bin/rails
229
+ - config/locales/en.yml
230
+ - config/routes.rb
231
+ - db/migrate/20160313145434_create_spree_cart_events.rb
232
+ - db/migrate/20160314080710_create_spree_page_events.rb
233
+ - db/migrate/20160314080822_create_spree_checkout_events.rb
234
+ - lib/generators/solidus_events_tracker/install/install_generator.rb
235
+ - lib/solidus_events_tracker.rb
236
+ - lib/solidus_events_tracker/engine.rb
237
+ - lib/solidus_events_tracker/factories.rb
238
+ - solidus_events_tracker.gemspec
239
+ - spec/controllers/spree/checkout_controller_decorator_spec.rb
240
+ - spec/controllers/spree/orders_controller_decorator_spec.rb
241
+ - spec/models/spree/cart_event_spec.rb
242
+ - spec/models/spree/checkout_event_spec.rb
243
+ - spec/models/spree/page_event_spec.rb
244
+ - spec/spec_helper.rb
245
+ - spec/trackers/spree/cart/event/tracker_spec.rb
246
+ - spec/trackers/spree/checkout/event/tracker_spec.rb
247
+ - spec/trackers/spree/event/tracker_spec.rb
248
+ - spec/trackers/spree/page/event/tracker_spec.rb
204
249
  homepage: http://vinsol.com
205
250
  licenses:
206
251
  - BSD-3