saucy 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/Gemfile +15 -1
  2. data/Gemfile.lock +67 -1
  3. data/Rakefile +26 -0
  4. data/app/controllers/memberships_controller.rb +33 -1
  5. data/app/models/invitation.rb +1 -1
  6. data/app/models/membership.rb +22 -0
  7. data/app/models/permission.rb +17 -0
  8. data/app/models/signup.rb +3 -3
  9. data/app/views/memberships/edit.html.erb +18 -0
  10. data/app/views/memberships/index.html.erb +4 -4
  11. data/config/routes.rb +2 -3
  12. data/features/run_features.feature +4 -3
  13. data/features/step_definitions/rails_steps.rb +3 -0
  14. data/lib/generators/saucy/features/templates/factories.rb +4 -4
  15. data/lib/generators/saucy/features/templates/step_definitions/session_steps.rb +6 -3
  16. data/lib/generators/saucy/features/templates/step_definitions/user_steps.rb +6 -4
  17. data/lib/generators/saucy/install/templates/create_saucy_tables.rb +8 -6
  18. data/lib/saucy/account.rb +9 -5
  19. data/lib/saucy/project.rb +28 -5
  20. data/lib/saucy/user.rb +5 -12
  21. data/spec/controllers/memberships_controller_spec.rb +87 -5
  22. data/spec/environment.rb +91 -0
  23. data/spec/models/account_spec.rb +17 -6
  24. data/spec/models/membership_spec.rb +37 -0
  25. data/spec/models/permission_spec.rb +19 -0
  26. data/spec/models/project_spec.rb +39 -9
  27. data/spec/models/user_spec.rb +16 -42
  28. data/spec/scaffold/config/routes.rb +5 -0
  29. data/spec/spec_helper.rb +8 -1
  30. data/spec/support/authentication_helpers.rb +16 -6
  31. metadata +75 -74
  32. data/app/controllers/permissions_controller.rb +0 -17
  33. data/app/models/account_membership.rb +0 -8
  34. data/app/models/project_membership.rb +0 -14
  35. data/app/views/permissions/edit.html.erb +0 -15
  36. data/spec/controllers/permissions_controller_spec.rb +0 -69
  37. data/spec/models/account_membership_spec.rb +0 -13
  38. data/spec/models/project_membership_spec.rb +0 -22
@@ -5,20 +5,20 @@ describe User, "valid" do
5
5
 
6
6
  it { should validate_presence_of(:name) }
7
7
 
8
- it { should have_many(:account_memberships) }
9
- it { should have_many(:accounts).through(:account_memberships) }
10
- it { should have_many(:projects) }
11
- it { should have_many(:project_memberships) }
8
+ it { should have_many(:memberships) }
9
+ it { should have_many(:accounts).through(:memberships) }
10
+ it { should have_many(:permissions) }
11
+ it { should have_many(:projects).through(:permissions) }
12
12
 
13
13
  it "is an admin of an account with an admin membership" do
14
14
  account = Factory(:account)
15
- Factory(:account_membership, :user => subject, :admin => true, :account => account)
15
+ Factory(:membership, :user => subject, :admin => true, :account => account)
16
16
  subject.should be_admin_of(account)
17
17
  end
18
18
 
19
19
  it "isn't an admin of an account with a non admin membership" do
20
20
  account = Factory(:account)
21
- Factory(:account_membership, :user => subject, :admin => false, :account => account)
21
+ Factory(:membership, :user => subject, :admin => false, :account => account)
22
22
  subject.should_not be_admin_of(account)
23
23
  end
24
24
 
@@ -29,29 +29,33 @@ describe User, "valid" do
29
29
 
30
30
  it "is a member with a membership for the given account" do
31
31
  account = Factory(:account)
32
- Factory(:account_membership, :user => subject, :account => account)
32
+ Factory(:membership, :user => subject, :account => account)
33
33
  subject.should be_member_of(account)
34
34
  end
35
35
 
36
36
  it "isn't a member without a membership for the given account" do
37
37
  account = Factory(:account)
38
38
  other_account = Factory(:account)
39
- Factory(:account_membership, :user => subject, :account => other_account)
39
+ Factory(:membership, :user => subject, :account => other_account)
40
40
  subject.should_not be_member_of(account)
41
41
  end
42
42
 
43
43
  it "is a member with a membership for the given project" do
44
44
  project = Factory(:project)
45
- Factory(:account_membership, :user => subject, :account => project.account)
46
- Factory(:project_membership, :user => subject, :project => project)
45
+ membership = Factory(:membership, :user => subject,
46
+ :account => project.account)
47
+ Factory(:permission, :membership => membership,
48
+ :project => project)
47
49
  subject.should be_member_of(project)
48
50
  end
49
51
 
50
52
  it "isn't a member without a membership for the given project" do
51
53
  project = Factory(:project)
52
54
  other_project = Factory(:project)
53
- Factory(:account_membership, :user => subject, :account => other_project.account)
54
- Factory(:project_membership, :user => subject, :project => other_project)
55
+ membership = Factory(:membership, :user => subject,
56
+ :account => other_project.account)
57
+ Factory(:permission, :membership => membership,
58
+ :project => other_project)
55
59
  subject.should_not be_member_of(project)
56
60
  end
57
61
 
@@ -62,35 +66,5 @@ describe User, "valid" do
62
66
 
63
67
  User.by_name.map(&:name).should == %w(abc def ghi)
64
68
  end
65
-
66
- context "updating the permissions for an account" do
67
- let!(:account) { Factory(:account) }
68
- let!(:other_account) { Factory(:account) }
69
- let!(:member_project) { Factory(:project, :account => account) }
70
- let!(:nonmember_project) { Factory(:project, :account => account) }
71
- let!(:other_account_project) { Factory(:project, :account => other_account) }
72
-
73
- before do
74
- Factory(:account_membership, :account => account, :user => subject)
75
- Factory(:account_membership, :account => other_account, :user => subject)
76
- Factory(:project_membership, :project => member_project, :user => subject)
77
- Factory(:project_membership, :project => other_account_project, :user => subject)
78
- subject.reload
79
-
80
- subject.update_permissions_for(account, [nonmember_project.id])
81
- end
82
-
83
- it "adds an added project for that account" do
84
- subject.should be_member_of(nonmember_project)
85
- end
86
-
87
- it "removes a removed project for that account" do
88
- subject.should_not be_member_of(member_project)
89
- end
90
-
91
- it "ignores a project for another account" do
92
- subject.should be_member_of(other_account_project)
93
- end
94
- end
95
69
  end
96
70
 
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ match "sign_in" => "application#index", :as => "sign_in"
3
+ root :to => "application#index"
4
+ end
5
+
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,14 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  ENV["RAILS_ENV"] ||= 'test'
3
- require File.expand_path("../../config/environment", __FILE__)
3
+
4
+ if File.exist?("config/environment.rb")
5
+ require "config/environment"
6
+ else
7
+ require File.expand_path("../environment", __FILE__)
8
+ end
9
+
4
10
  require 'rspec/rails'
11
+ require 'shoulda'
5
12
 
6
13
  # Requires supporting ruby files with custom matchers and macros, etc,
7
14
  # in spec/support/ and its subdirectories.
@@ -21,24 +21,34 @@ module AuthenticationHelpers
21
21
 
22
22
  def sign_in_as_admin_of_account(account)
23
23
  user = Factory(:user)
24
- Factory(:account_membership, :user => user, :account => account, :admin => true)
24
+ Factory(:membership, :user => user, :account => account, :admin => true)
25
25
  sign_in_as user
26
26
  end
27
27
 
28
28
  def sign_in_as_non_admin_of_account(account)
29
29
  user = Factory(:user)
30
- Factory(:account_membership, :user => user, :account => account, :admin => false)
30
+ Factory(:membership, :user => user, :account => account, :admin => false)
31
31
  sign_in_as user
32
32
  end
33
33
 
34
34
  def sign_in_as_non_admin_of_project(project)
35
- user = sign_in_as_non_admin_of_account(project.account)
36
- Factory(:project_membership, :user => user, :project => project)
35
+ user = Factory(:user)
36
+ membership = Factory(:membership, :user => user,
37
+ :account => account,
38
+ :admin => false)
39
+ Factory(:permission, :membership => membership,
40
+ :project => project)
41
+ sign_in_as user
37
42
  end
38
43
 
39
44
  def sign_in_as_admin_of_project(project)
40
- user = sign_in_as_admin_of_account(project.account)
41
- Factory(:project_membership, :user => user, :project => project)
45
+ user = Factory(:user)
46
+ membership = Factory(:membership, :user => user,
47
+ :account => account,
48
+ :admin => true)
49
+ Factory(:permission, :membership => membership,
50
+ :project => project)
51
+ sign_in_as user
42
52
  end
43
53
  end
44
54
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saucy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - thoughtbot, inc.
@@ -17,13 +17,14 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-12-09 00:00:00 -05:00
20
+ date: 2010-12-17 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
- name: formtastic
24
+ type: :runtime
25
25
  prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
26
+ name: formtastic
27
+ version_requirements: &id001 !ruby/object:Gem::Requirement
27
28
  none: false
28
29
  requirements:
29
30
  - - ">="
@@ -33,12 +34,12 @@ dependencies:
33
34
  - 1
34
35
  - 2
35
36
  version: "1.2"
36
- type: :runtime
37
- version_requirements: *id001
37
+ requirement: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: railties
39
+ type: :runtime
40
40
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
41
+ name: railties
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
43
  none: false
43
44
  requirements:
44
45
  - - ">="
@@ -49,12 +50,12 @@ dependencies:
49
50
  - 0
50
51
  - 3
51
52
  version: 3.0.3
52
- type: :runtime
53
- version_requirements: *id002
53
+ requirement: *id002
54
54
  - !ruby/object:Gem::Dependency
55
- name: aruba
55
+ type: :development
56
56
  prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
57
+ name: aruba
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
59
  none: false
59
60
  requirements:
60
61
  - - "="
@@ -65,9 +66,8 @@ dependencies:
65
66
  - 2
66
67
  - 6
67
68
  version: 0.2.6
68
- type: :development
69
- version_requirements: *id003
70
- description: BLAH BLAH BLAH
69
+ requirement: *id003
70
+ description: Clearance-based Rails engine for Software as a Service (Saas) that provides account and project management
71
71
  email: support@thoughtbot.com
72
72
  executables: []
73
73
 
@@ -76,92 +76,93 @@ extensions: []
76
76
  extra_rdoc_files: []
77
77
 
78
78
  files:
79
+ - Gemfile
79
80
  - Gemfile.lock
81
+ - Rakefile
80
82
  - README
81
- - Gemfile
82
83
  - config/routes.rb
83
- - app/views/invitations/new.html.erb
84
- - app/views/invitations/show.html.erb
85
- - app/views/accounts/new.html.erb
84
+ - app/controllers/accounts_controller.rb
85
+ - app/controllers/invitations_controller.rb
86
+ - app/controllers/memberships_controller.rb
87
+ - app/controllers/plans_controller.rb
88
+ - app/controllers/profiles_controller.rb
89
+ - app/models/invitation.rb
90
+ - app/models/membership.rb
91
+ - app/models/permission.rb
92
+ - app/models/signup.rb
93
+ - app/views/accounts/_account.html.erb
94
+ - app/views/accounts/_blank_slate.html.erb
86
95
  - app/views/accounts/_projects.html.erb
87
- - app/views/accounts/edit.html.erb
88
96
  - app/views/accounts/_tab_bar.html.erb
89
- - app/views/accounts/_blank_slate.html.erb
90
- - app/views/accounts/_account.html.erb
97
+ - app/views/accounts/edit.html.erb
91
98
  - app/views/accounts/index.html.erb
99
+ - app/views/accounts/new.html.erb
92
100
  - app/views/invitation_mailer/invitation.text.erb
93
- - app/views/plans/index.html.erb
101
+ - app/views/invitations/new.html.erb
102
+ - app/views/invitations/show.html.erb
103
+ - app/views/memberships/edit.html.erb
94
104
  - app/views/memberships/index.html.erb
95
- - app/views/profiles/edit.html.erb
105
+ - app/views/plans/index.html.erb
96
106
  - app/views/profiles/_inputs.html.erb
97
- - app/views/projects/new.html.erb
107
+ - app/views/profiles/edit.html.erb
108
+ - app/views/projects/_form.html.erb
98
109
  - app/views/projects/edit.html.erb
99
110
  - app/views/projects/index.html.erb
100
- - app/views/projects/_form.html.erb
101
- - app/views/permissions/edit.html.erb
102
- - app/controllers/profiles_controller.rb
103
- - app/controllers/accounts_controller.rb
104
- - app/controllers/memberships_controller.rb
105
- - app/controllers/plans_controller.rb
106
- - app/controllers/invitations_controller.rb
107
- - app/controllers/permissions_controller.rb
108
- - app/models/project_membership.rb
109
- - app/models/invitation.rb
110
- - app/models/signup.rb
111
- - app/models/account_membership.rb
112
- - lib/generators/saucy/views/views_generator.rb
111
+ - app/views/projects/new.html.erb
113
112
  - lib/generators/saucy/base.rb
114
- - lib/generators/saucy/install/install_generator.rb
115
- - lib/generators/saucy/install/templates/create_saucy_tables.rb
116
- - lib/generators/saucy/install/templates/controllers/projects_controller.rb
117
- - lib/generators/saucy/install/templates/models/project.rb
118
- - lib/generators/saucy/install/templates/models/plan.rb
119
- - lib/generators/saucy/install/templates/models/account.rb
120
- - lib/generators/saucy/install/templates/models/invitation_mailer.rb
121
113
  - lib/generators/saucy/features/features_generator.rb
122
114
  - lib/generators/saucy/features/templates/factories.rb
115
+ - lib/generators/saucy/features/templates/step_definitions/email_steps.rb
123
116
  - lib/generators/saucy/features/templates/step_definitions/factory_girl_steps.rb
124
117
  - lib/generators/saucy/features/templates/step_definitions/html_steps.rb
125
- - lib/generators/saucy/features/templates/step_definitions/session_steps.rb
126
118
  - lib/generators/saucy/features/templates/step_definitions/project_steps.rb
127
- - lib/generators/saucy/features/templates/step_definitions/email_steps.rb
119
+ - lib/generators/saucy/features/templates/step_definitions/session_steps.rb
128
120
  - lib/generators/saucy/features/templates/step_definitions/user_steps.rb
129
- - lib/saucy.rb
130
- - lib/saucy/layouts.rb
121
+ - lib/generators/saucy/install/install_generator.rb
122
+ - lib/generators/saucy/install/templates/controllers/projects_controller.rb
123
+ - lib/generators/saucy/install/templates/create_saucy_tables.rb
124
+ - lib/generators/saucy/install/templates/models/account.rb
125
+ - lib/generators/saucy/install/templates/models/invitation_mailer.rb
126
+ - lib/generators/saucy/install/templates/models/plan.rb
127
+ - lib/generators/saucy/install/templates/models/project.rb
128
+ - lib/generators/saucy/views/views_generator.rb
129
+ - lib/saucy/account.rb
131
130
  - lib/saucy/account_authorization.rb
132
131
  - lib/saucy/configuration.rb
133
132
  - lib/saucy/engine.rb
134
- - lib/saucy/project.rb
133
+ - lib/saucy/layouts.rb
135
134
  - lib/saucy/plan.rb
136
- - lib/saucy/account.rb
137
- - lib/saucy/user.rb
135
+ - lib/saucy/project.rb
138
136
  - lib/saucy/projects_controller.rb
137
+ - lib/saucy/user.rb
138
+ - lib/saucy.rb
139
139
  - features/run_features.feature
140
- - features/support/file.rb
141
- - features/support/env.rb
142
- - features/step_definitions/rails_steps.rb
143
140
  - features/step_definitions/clearance_steps.rb
144
- - spec/views/accounts/_account.html.erb_spec.rb
141
+ - features/step_definitions/rails_steps.rb
142
+ - features/support/env.rb
143
+ - features/support/file.rb
144
+ - spec/controllers/accounts_controller_spec.rb
145
145
  - spec/controllers/application_controller_spec.rb
146
146
  - spec/controllers/invitations_controller_spec.rb
147
- - spec/controllers/accounts_controller_spec.rb
148
147
  - spec/controllers/memberships_controller_spec.rb
149
- - spec/controllers/permissions_controller_spec.rb
150
148
  - spec/controllers/profiles_controller_spec.rb
151
149
  - spec/controllers/projects_controller_spec.rb
150
+ - spec/environment.rb
152
151
  - spec/layouts_spec.rb
153
- - spec/saucy_spec.rb
154
- - spec/support/clearance_matchers.rb
155
- - spec/support/authorization_helpers.rb
156
- - spec/support/authentication_helpers.rb
157
- - spec/models/user_spec.rb
158
- - spec/models/signup_spec.rb
159
- - spec/models/project_spec.rb
160
- - spec/models/project_membership_spec.rb
161
- - spec/models/invitation_spec.rb
162
152
  - spec/models/account_spec.rb
163
- - spec/models/account_membership_spec.rb
153
+ - spec/models/invitation_spec.rb
154
+ - spec/models/membership_spec.rb
155
+ - spec/models/permission_spec.rb
156
+ - spec/models/project_spec.rb
157
+ - spec/models/signup_spec.rb
158
+ - spec/models/user_spec.rb
159
+ - spec/saucy_spec.rb
160
+ - spec/scaffold/config/routes.rb
164
161
  - spec/spec_helper.rb
162
+ - spec/support/authentication_helpers.rb
163
+ - spec/support/authorization_helpers.rb
164
+ - spec/support/clearance_matchers.rb
165
+ - spec/views/accounts/_account.html.erb_spec.rb
165
166
  has_rdoc: true
166
167
  homepage: http://github.com/thoughtbot/saucy
167
168
  licenses: []
@@ -195,10 +196,10 @@ rubyforge_project:
195
196
  rubygems_version: 1.3.7
196
197
  signing_key:
197
198
  specification_version: 3
198
- summary: blah blah blah
199
+ summary: Clearance-based Rails engine for SaaS
199
200
  test_files:
200
201
  - features/run_features.feature
201
- - features/support/file.rb
202
- - features/support/env.rb
203
- - features/step_definitions/rails_steps.rb
204
202
  - features/step_definitions/clearance_steps.rb
203
+ - features/step_definitions/rails_steps.rb
204
+ - features/support/env.rb
205
+ - features/support/file.rb
@@ -1,17 +0,0 @@
1
- class PermissionsController < ApplicationController
2
- before_filter :authorize_admin
3
- layout Saucy::Layouts.to_proc
4
-
5
- def edit
6
- @user = User.find(params[:user_id])
7
- @projects = current_account.projects_by_name
8
- render
9
- end
10
-
11
- def update
12
- user = User.find(params[:user_id])
13
- user.update_permissions_for(current_account, params[:permissions][:project_ids])
14
- flash[:success] = "Permissions updated."
15
- redirect_to account_memberships_url(current_account)
16
- end
17
- end
@@ -1,8 +0,0 @@
1
- class AccountMembership < ActiveRecord::Base
2
- belongs_to :user
3
- belongs_to :account
4
-
5
- validates_presence_of :user_id
6
- validates_presence_of :account_id
7
- validates_uniqueness_of :user_id, :scope => :account_id
8
- end
@@ -1,14 +0,0 @@
1
- class ProjectMembership < ActiveRecord::Base
2
- belongs_to :user
3
- belongs_to :project
4
-
5
- validate :ensure_account_member
6
-
7
- private
8
-
9
- def ensure_account_member
10
- unless user.member_of?(project.account)
11
- errors.add(:base, "This user is not a member of #{project.name}'s account")
12
- end
13
- end
14
- end