Skip to content

Commit

Permalink
Avoid testing conflicts with 2 diff users
Browse files Browse the repository at this point in the history
  • Loading branch information
petecheslock committed Jun 21, 2024
1 parent f21b3c3 commit aa64a4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
bundler-cache: true

- name: Run tests
run: PARALLEL_WORKERS=1 bundle exec rails test
run: bundle exec rails test

- name: Save AppMaps
uses: actions/cache/save@v3
Expand Down
31 changes: 17 additions & 14 deletions test/integration/billing_address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class BillingAddressTest < ActionDispatch::IntegrationTest
def setup
@user = users(:michael)
@michael = users(:michael)
@archer = users(:archer)
DatabaseCleaner.strategy = :deletion
DatabaseCleaner.start
end
Expand All @@ -12,40 +13,42 @@ def setup
DatabaseCleaner.clean
end

test "create new billing address" do
get billing_user_path(@user)
test "create new billing address as michael" do
user = @michael
get billing_user_path(user)
assert_template 'users/billing'

patch billing_user_path(@user), params: { billing: { address: "123 Main Street", city: "Sample City", state: "SC", zip_code: "12345" } }
patch billing_user_path(user), params: { billing: { address: "123 Main Street", city: "Sample City", state: "SC", zip_code: "12345" } }

assert_redirected_to billing_user_path(@user)
assert_redirected_to billing_user_path(user)
follow_redirect!
assert_match "Billing address updated", response.body
@user.reload
user_billing = UserBilling.find_by(user_id: @user.id)
user.reload
user_billing = UserBilling.find_by(user_id: user.id)
assert_not_nil user_billing
assert_equal "123 Main Street", user_billing.address
assert_equal "Sample City", user_billing.city
assert_equal "SC", user_billing.state
assert_equal "12345", user_billing.zip_code
end

test "update existing billing address" do
test "update existing billing address as archer" do

Check failure on line 35 in test/integration/billing_address_test.rb

View workflow job for this annotation

GitHub Actions / appmap-annotations

Test Failure

Mongoid::Errors::DocumentNotFound: message: Document not found for class UserBilling with attributes {:user_id=>950961012}. summary: When calling UserBilling.find_by with a hash of attributes, all attributes provided must match a document in the database or this error will be raised. resolution: Search for attributes that are in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause nil to be returned instead of raising this error. test/integration/billing_address_test.rb:51:in `block in <class:BillingAddressTest>'
user = @archer
# Ensure a billing address exists before this test
UserBilling.create(user_id: @user.id, address: "Initial Address", city: "Initial City", state: "Initial State", zip_code: "00000")
UserBilling.create(user_id: user.id, address: "Initial Address", city: "Initial City", state: "Initial State", zip_code: "00000")

get billing_user_path(@user)
get billing_user_path(user)
assert_template 'users/billing'

patch billing_user_path(@user), params: { billing: { address: "456 Another St", city: "Updated City", state: "UC", zip_code: "67890" } }
patch billing_user_path(user), params: { billing: { address: "456 Another St", city: "Updated City", state: "UC", zip_code: "67890" } }

assert_redirected_to billing_user_path(@user)
assert_redirected_to billing_user_path(user)
follow_redirect!
assert_match "Billing address updated", response.body

# Verify the attributes are updated
@user.reload
user_billing = UserBilling.find_by(user_id: @user.id)
user.reload
user_billing = UserBilling.find_by(user_id: user.id)
assert_not_nil user_billing
assert_equal "456 Another St", user_billing.address
assert_equal "Updated City", user_billing.city
Expand Down

0 comments on commit aa64a4d

Please sign in to comment.