mercredi 8 mars 2017

is this a good written test or is it ugly?

describe "Team::Membership" do
  let(:team) { Team.last }
  let(:user) { User.last }
  let(:membership) {user.apply_for(team)}

  it "can be rejected" do
    assert_difference "team.denied_applications.reload.count", +1 do
      assert_difference "team.applications.reload.count", -1 do
        assert_difference "team.members.reload.count", 0 do
          membership.reject!
        end
      end
    end
    membership.state.must_equal "denied"
  end

if the application is rejected, then the scope denied_applications increase by one, applications is -1 and memberswon't change at all.

# team.rb
has_many :member
ships, dependent: :destroy
  has_many :members, -> { where(team_memberships: {state: :confirmed}) }, through: :memberships, source: :user
  has_many :ex_members, -> { where(team_memberships: {state: :left}) }, through: :memberships, source: :user
  has_many :applications, -> { where(state: :pending) }, class_name: "Membership"
  has_many :denied_applications, -> { where(state: :denied) }, class_name: "Membership"

so my question is more likely: is this a good writte test or would you just write

team.denied_applications.reload.count.must_equal(1)
team.applications.reload.count.must_equal(0)
team.members.reload.count.must_equal(0)

Aucun commentaire:

Enregistrer un commentaire