clubhouse 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/routes.rb +1 -1
- data/lib/clubhouse.rb +0 -4
- data/lib/clubhouse/concerns/controllers/organizations_controller.rb +3 -2
- data/lib/clubhouse/concerns/models.rb +1 -0
- data/lib/clubhouse/concerns/models/attribute_validatable.rb +24 -0
- data/lib/clubhouse/concerns/models/organization.rb +4 -8
- data/lib/clubhouse/version.rb +1 -1
- data/spec/requests/organizations_spec.rb +17 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2165d37ca3a4f155a97f5385653daedb54fb8e84
|
4
|
+
data.tar.gz: 033b5365b61a3470ea507a30d6624192e6556899
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f185bc564d16063fd08a724690f1282a09ecf533b4baef53597e2699412e805aa9ea96f011cbe0dbb4d26b622aa86f4f3d6727df13eb32a57fde898526a8afd
|
7
|
+
data.tar.gz: dfe76e16fe982906e7731f6efbdf8bc5683a0f7313e769c7b374c6456a319faba90a03b7a0270f2a492b14e864dc0b2d19b4a008918cbee8214ae62a44b9f937
|
data/config/routes.rb
CHANGED
data/lib/clubhouse.rb
CHANGED
@@ -15,10 +15,6 @@ module Clubhouse
|
|
15
15
|
!!(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid::ACCEPTABLE_UUID =~ value)
|
16
16
|
end
|
17
17
|
|
18
|
-
def normalize_name(name)
|
19
|
-
name.to_s.downcase.gsub(/\s+/, "-")
|
20
|
-
end
|
21
|
-
|
22
18
|
def normalize_email(email)
|
23
19
|
email.to_s.downcase.gsub(/\s+/, "")
|
24
20
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Clubhouse
|
2
|
+
module Concerns
|
3
|
+
module Models
|
4
|
+
module AttributeValidatable
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def validate_attributes!(attributes)
|
9
|
+
record = new(attributes)
|
10
|
+
|
11
|
+
record.validate
|
12
|
+
|
13
|
+
ignorable = record.errors.keys - attributes.keys
|
14
|
+
ignorable.each { |attribute| record.errors.delete(attribute) }
|
15
|
+
|
16
|
+
raise ActiveRecord::RecordInvalid.new(record) unless record.errors.empty?
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -5,19 +5,19 @@ module Clubhouse
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
include Emailable
|
8
|
+
include AttributeValidatable
|
8
9
|
|
9
10
|
NAME_REGEX = /\A[a-z][a-z\d\-]*\z/
|
11
|
+
FORMAT_MESSAGE = "can only contain lowercase letters, numbers, and dashes"
|
10
12
|
|
11
13
|
included do
|
12
14
|
has_many :invitations
|
13
15
|
has_many :memberships
|
14
16
|
has_many :members, through: :memberships, class_name: Clubhouse.config.member_model
|
15
17
|
|
16
|
-
before_validation :normalize_name
|
17
|
-
|
18
18
|
validates :name, presence: true,
|
19
19
|
length: { maximum: 30 },
|
20
|
-
format: NAME_REGEX,
|
20
|
+
format: { with: NAME_REGEX, message: FORMAT_MESSAGE },
|
21
21
|
uniqueness: true
|
22
22
|
end
|
23
23
|
|
@@ -34,6 +34,7 @@ module Clubhouse
|
|
34
34
|
field = Clubhouse.is_id?(id_or_name) ? :id : :name
|
35
35
|
where(field => id_or_name)
|
36
36
|
end
|
37
|
+
|
37
38
|
end
|
38
39
|
|
39
40
|
def member?(member)
|
@@ -43,11 +44,6 @@ module Clubhouse
|
|
43
44
|
def admin?(member)
|
44
45
|
memberships.exists?(admin: true, member: member)
|
45
46
|
end
|
46
|
-
|
47
|
-
private
|
48
|
-
def normalize_name
|
49
|
-
self.name = Clubhouse.normalize_name(name)
|
50
|
-
end
|
51
47
|
end
|
52
48
|
end
|
53
49
|
end
|
data/lib/clubhouse/version.rb
CHANGED
@@ -23,22 +23,30 @@ describe "Organizations" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe "
|
27
|
-
it_requires_authentication(:
|
26
|
+
describe "GET /organizations/:name/check" do
|
27
|
+
it_requires_authentication(:get, "/organizations/name/check")
|
28
28
|
|
29
29
|
context "when name is taken" do
|
30
|
-
it "responds with
|
31
|
-
|
30
|
+
it "responds with unprocessable" do
|
31
|
+
a_get("/organizations/#{existing.name}/check", session)
|
32
32
|
|
33
|
-
expect_status(
|
33
|
+
expect_status(422)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when name is invalid" do
|
38
|
+
it "responds with unprocessable" do
|
39
|
+
a_get("/organization/#{'a' * 31}/check", session)
|
40
|
+
|
41
|
+
expect_status(422)
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
37
45
|
context "when name is available" do
|
38
|
-
it "responds with
|
39
|
-
|
40
|
-
|
41
|
-
|
46
|
+
it "responds with ok" do
|
47
|
+
a_get("/organizations/available/check", session)
|
48
|
+
|
49
|
+
expect_status(200)
|
42
50
|
end
|
43
51
|
end
|
44
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clubhouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Kriss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- lib/clubhouse/concerns/mailers.rb
|
195
195
|
- lib/clubhouse/concerns/mailers/mailer.rb
|
196
196
|
- lib/clubhouse/concerns/models.rb
|
197
|
+
- lib/clubhouse/concerns/models/attribute_validatable.rb
|
197
198
|
- lib/clubhouse/concerns/models/emailable.rb
|
198
199
|
- lib/clubhouse/concerns/models/invitation.rb
|
199
200
|
- lib/clubhouse/concerns/models/membership.rb
|