clubhouse 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c071c2f20d58b6b72686bea0e764f062ade1cbfe
4
- data.tar.gz: 591afe4fbd09c83cec779630e43ade13f7cfafdf
3
+ metadata.gz: 2165d37ca3a4f155a97f5385653daedb54fb8e84
4
+ data.tar.gz: 033b5365b61a3470ea507a30d6624192e6556899
5
5
  SHA512:
6
- metadata.gz: 19311d1ea71c6b1f76bf6b1c2cc3b7fc08978fecea20c453afa1f6485b0da9dc5e44f074921d7b71e08168fe6d50917167365a3663149b92e92cb0f3de41defd
7
- data.tar.gz: 6a5d16af03b10a06e11c3666d46716768019a7493e7ba1d024701698e21bc5566adedd4ad6937b830db9e57ff5f3c943de5cf0554ebd094a4127a6f51ac34f22
6
+ metadata.gz: 8f185bc564d16063fd08a724690f1282a09ecf533b4baef53597e2699412e805aa9ea96f011cbe0dbb4d26b622aa86f4f3d6727df13eb32a57fde898526a8afd
7
+ data.tar.gz: dfe76e16fe982906e7731f6efbdf8bc5683a0f7313e769c7b374c6456a319faba90a03b7a0270f2a492b14e864dc0b2d19b4a008918cbee8214ae62a44b9f937
@@ -1,7 +1,7 @@
1
1
  Clubhouse::Engine.routes.draw do
2
2
  scope shallow: true, format: false do
3
3
  resources :organizations, except: [:new, :edit] do
4
- match ":id", action: :check, on: :collection, via: :head
4
+ get :check, on: :member
5
5
 
6
6
  resources :invitations, except: [:new, :edit]
7
7
 
@@ -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
@@ -21,8 +21,9 @@ module Clubhouse
21
21
  end
22
22
 
23
23
  def check
24
- authorize!(fetch_organization)
25
- head :ok
24
+ skip_authorization
25
+
26
+ head :ok if Organization.validate_attributes!(name: params[:id])
26
27
  end
27
28
 
28
29
  def show
@@ -1,3 +1,4 @@
1
+ require "clubhouse/concerns/models/attribute_validatable"
1
2
  require "clubhouse/concerns/models/invitation"
2
3
  require "clubhouse/concerns/models/membership"
3
4
  require "clubhouse/concerns/models/organization"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Clubhouse
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,22 +23,30 @@ describe "Organizations" do
23
23
  end
24
24
  end
25
25
 
26
- describe "HEAD /organizations/:name" do
27
- it_requires_authentication(:head, "/organizations/name")
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 ok" do
31
- a_head("/organizations/#{existing.name}", session)
30
+ it "responds with unprocessable" do
31
+ a_get("/organizations/#{existing.name}/check", session)
32
32
 
33
- expect_status(200)
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 not found" do
39
- expect do
40
- a_head("/organizations/available", session)
41
- end.to raise_error(ActiveRecord::RecordNotFound)
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.1.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-08-16 00:00:00.000000000 Z
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