File tree Expand file tree Collapse file tree 3 files changed +104
-0
lines changed
Expand file tree Collapse file tree 3 files changed +104
-0
lines changed Original file line number Diff line number Diff line change 1+ require " ../spec_helper"
2+
3+ describe App ::Models ::Domain do
4+ org = App ::Models ::Organization .new
5+ domain = App ::Models ::Domain .new
6+
7+ Spec .before_each do
8+ org.destroy rescue nil
9+ domain.destroy rescue nil
10+ org = App ::Models ::Organization .new
11+ org.name = " Testing"
12+ org.save!
13+
14+ domain = App ::Models ::Domain .new
15+ end
16+
17+ it " should be able to create a domain" do
18+ domain.name = " Production"
19+ domain.domain = " Production.What.com"
20+ domain.organization = org
21+ domain.save!
22+
23+ domain.domain.should eq " production.what.com"
24+ org.domains.map(& .id).should contain(domain.id)
25+ end
26+
27+ it " should not allow two domains with the same domain name" do
28+ domain.name = " Production"
29+ domain.domain = " Production.What.com"
30+ domain.organization = org
31+ domain.save!
32+
33+ domain2 = App ::Models ::Domain .new
34+ domain2.name = " Dev"
35+ domain2.domain = " Production.What.com"
36+ domain2.organization = org
37+
38+ expect_raises(PgORM ::Error ::RecordInvalid ) { domain2.save! }
39+ end
40+ end
Original file line number Diff line number Diff line change 1+ require " ../spec_helper"
2+
3+ describe App ::Models ::OrganizationInvite do
4+ org = App ::Models ::Organization .new
5+ user = App ::Models ::User .new
6+ invite = App ::Models ::OrganizationInvite .new
7+
8+ Spec .before_each do
9+ org.destroy rescue nil
10+ user.destroy rescue nil
11+ invite.destroy rescue nil
12+ org = App ::Models ::Organization .new
13+ user = App ::Models ::User .new
14+ invite = App ::Models ::OrganizationInvite .new
15+ end
16+
17+ it " should be able to invite a user to an organization" do
18+ org.name = " Testing"
19+ org.save!
20+
21+ invite.email = " test@test.com"
22+ invite.permission = App ::Permissions ::Viewer
23+ invite.organization = org
24+ invite.save!
25+ invite.secret.nil?.should be_false
26+
27+ user.email = " test@test.com"
28+ user.name = " testing"
29+ user.save!
30+
31+ user.organizations.map(& .id).should_not contain(org.id)
32+
33+ App ::Models ::OrganizationInvite .accept!(
34+ id: invite.id,
35+ secret: invite.secret,
36+ user: user,
37+ )
38+ user.organizations.map(& .id).should contain(org.id)
39+ end
40+ end
Original file line number Diff line number Diff line change 1+ class App::Models::Domain < ::PgORM::Base
2+ table :domains
3+
4+ default_primary_key id : UUID , autogenerated: true
5+ attribute name : String
6+ attribute domain : String
7+ attribute description : String ?
8+
9+ attribute organization_id : UUID
10+ belongs_to :organization , class_name: Organization
11+
12+ include PgORM ::Timestamps
13+
14+ before_save do
15+ self .name = name.strip
16+ self .domain = domain.strip.downcase
17+ self .description = description.try(& .strip.presence)
18+ end
19+
20+ validates :domain , presence: true
21+ validates :name , presence: true
22+
23+ ensure_unique :domain
24+ end
You can’t perform that action at this time.
0 commit comments