Skip to content

Commit

Permalink
Write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
binarygit committed Jul 23, 2024
1 parent 09c8b20 commit 1196118
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/dummy/app/models/team_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
class TeamMembership < ApplicationRecord
belongs_to :team
belongs_to :user
before_destroy :say_goodbye, if: -> { Rails.env.test? }

def name
"#{team&.name} - #{user&.name}"
end

private

def say_goodbye
raise "Callback Called"
end
end
25 changes: 25 additions & 0 deletions spec/features/avo/has_many_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,29 @@
}.not_to raise_error
end
end

describe "through relationship" do
let!(:team) { create :team }
let!(:user) { create :user }

it "triggers callbacks on through model" do
team.team_members << user
expect(team.team_members.count).to eq 1
team_membership = team.memberships.first

Check failure on line 165 in spec/features/avo/has_many_field_spec.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Correctable] Lint/UselessAssignment: Useless assignment to variable - team_membership. Raw Output: spec/features/avo/has_many_field_spec.rb:165:7: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - team_membership. team_membership = team.memberships.first ^^^^^^^^^^^^^^^

visit "/admin/resources/teams/#{team.id}/team_members?view=show&turbo_frame=has_many_field_show_team_members"

expect { find("tr[data-resource-id='#{user.to_param}'] [data-control='detach']").click }.to raise_error("Callback Called")
end

it "triggers callbacks when called from the other model too" do
user.teams << team
expect(user.teams.count).to eq 1
team_membership = user.team_memberships.first

Check failure on line 175 in spec/features/avo/has_many_field_spec.rb

View workflow job for this annotation

GitHub Actions / lint / runner / standardrb

[rubocop] reported by reviewdog 🐶 [Correctable] Lint/UselessAssignment: Useless assignment to variable - team_membership. Raw Output: spec/features/avo/has_many_field_spec.rb:175:7: W: [Correctable] Lint/UselessAssignment: Useless assignment to variable - team_membership. team_membership = user.team_memberships.first ^^^^^^^^^^^^^^^

visit "/admin/resources/users/#{user.to_param}/teams?view=show&turbo_frame=has_and_belongs_to_many_field_show_teams"

expect { find("tr[data-resource-id='#{team.id}'] [data-control='detach']").click }.to raise_error("Callback Called")
end
end
end

0 comments on commit 1196118

Please sign in to comment.