Skip to content

Commit

Permalink
Improved tests [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Feb 6, 2021
1 parent 5c03f2d commit 2eb7cdf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 0 additions & 6 deletions test/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
class ControllerTest < ActionDispatch::IntegrationTest
include ActiveJob::TestHelper # for Rails < 6

def setup
Ahoy::Visit.delete_all
Ahoy::Event.delete_all
User.delete_all
end

def test_works
get products_url
assert_response :success
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
Ahoy.logger = logger

class Minitest::Test
def setup
Ahoy::Visit.delete_all
Ahoy::Event.delete_all
User.delete_all
end

def with_options(options)
previous_options = {}
options.each_key do |k|
Expand Down
14 changes: 12 additions & 2 deletions test/tracker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
class TrackerTest < Minitest::Test
def test_no_request
ahoy = Ahoy::Tracker.new
assert ahoy.track("Some event", some_prop: true)
ahoy.track("Some event", some_prop: true)

event = Ahoy::Event.last
assert_equal "Some event", event.name
assert_equal({"some_prop" => true}, event.properties)
assert_nil event.user_id
end

def test_user_option
user = OpenStruct.new(id: "123")
user = OpenStruct.new(id: 123)
ahoy = Ahoy::Tracker.new(user: user)
assert_equal ahoy.user.id, user.id

ahoy.track("Some event", some_prop: true)

event = Ahoy::Event.last
assert_equal user.id, event.user_id
end
end

0 comments on commit 2eb7cdf

Please sign in to comment.