Last active
August 29, 2015 14:14
-
-
Save tubbo/979c4c3536488d146f7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Group < ActiveRecord::Base | |
has_many :memberships | |
has_many :users, :through => :memberships | |
belongs_to :owner, class_name: 'User' | |
validates :owner, presence: true | |
validates :name, presence: true, length: { minimum: 6, maximum: 255 } | |
validates :description, length: { maximum: 255 }, allow_blank: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class GroupTest < ActiveSupport::TestCase | |
def setup | |
@group = Group.new(name: 'test group', description: 'test group description', owner: users(:michael)) | |
@group.users << users(:michael) | |
@user = users(:michael) | |
end | |
test "should be valid" do | |
assert @group.valid? | |
end | |
test "should have an owner" do | |
@group.owner = nil | |
assert_not @group.valid? | |
end | |
test "owner should be a member" do | |
assert @group.users.include?(@group.owner) | |
end | |
test "name should be present" do | |
@group.name = " " | |
assert_not @group.valid? | |
end | |
test "name should not be too short" do | |
@group.name = 'a' * 5 | |
assert_not @group.valid? | |
end | |
test "name should not be too long" do | |
@group.name = 'a' * 256 | |
assert_not @group.valid? | |
end | |
test "description can be empty" do | |
@group.description = "" | |
assert @group.valid? | |
end | |
test "description should not be too long" do | |
@group.description = 'a' * 256 | |
assert_not @group.valid? | |
end | |
test "group has an owner" do | |
assert @group.owner | |
end | |
test "owner has a group" do | |
# byebug | |
assert @user.groups.any? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Membership < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :group | |
validates :user, presence: true | |
validates :group, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12:29:55 - INFO - Running: test/models/group_test.rb | |
Run options: --seed 30869 | |
# Running: | |
...F...... | |
Finished in 0.705084s, 14.1827 runs/s, 14.1827 assertions/s. | |
1) Failure: | |
GroupTest#test_owner_has_a_group [/Users/matthew/Work/Shadowland7/shadowland/test/models/group_test.rb:55]: | |
Failed assertion, no message given. | |
10 runs, 10 assertions, 1 failures, 0 errors, 0 skips | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment