saucy 0.1.5 → 0.1.6
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.
- data/app/controllers/invitations_controller.rb +8 -0
- data/app/models/invitation.rb +4 -1
- data/app/views/invitations/new.html.erb +1 -0
- data/lib/generators/saucy/features/templates/features/manage_users.feature +7 -0
- data/lib/generators/saucy/features/templates/step_definitions/user_steps.rb +8 -0
- data/lib/generators/saucy/install/templates/create_saucy_tables.rb +8 -0
- data/spec/controllers/invitations_controller_spec.rb +14 -0
- data/spec/environment.rb +2 -1
- data/spec/models/invitation_spec.rb +11 -2
- metadata +3 -3
@@ -4,6 +4,7 @@ class InvitationsController < ApplicationController
|
|
4
4
|
layout Saucy::Layouts.to_proc
|
5
5
|
|
6
6
|
def new
|
7
|
+
assign_projects
|
7
8
|
@invitation = Invitation.new
|
8
9
|
render
|
9
10
|
end
|
@@ -15,6 +16,7 @@ class InvitationsController < ApplicationController
|
|
15
16
|
flash[:success] = "User invited."
|
16
17
|
redirect_to account_memberships_url(current_account)
|
17
18
|
else
|
19
|
+
assign_projects
|
18
20
|
render :action => 'new'
|
19
21
|
end
|
20
22
|
end
|
@@ -33,4 +35,10 @@ class InvitationsController < ApplicationController
|
|
33
35
|
render :action => 'show'
|
34
36
|
end
|
35
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def assign_projects
|
42
|
+
@projects = current_account.projects_by_name
|
43
|
+
end
|
36
44
|
end
|
data/app/models/invitation.rb
CHANGED
@@ -2,6 +2,7 @@ class Invitation < ActiveRecord::Base
|
|
2
2
|
belongs_to :account
|
3
3
|
validates_presence_of :account_id
|
4
4
|
validates_presence_of :email
|
5
|
+
has_and_belongs_to_many :projects
|
5
6
|
|
6
7
|
after_create :deliver_invitation
|
7
8
|
|
@@ -22,7 +23,9 @@ class Invitation < ActiveRecord::Base
|
|
22
23
|
@user = existing_user || new_user
|
23
24
|
if valid?
|
24
25
|
@user.save!
|
25
|
-
@user.memberships.create!(:account
|
26
|
+
@user.memberships.create!(:account => account,
|
27
|
+
:admin => admin,
|
28
|
+
:projects => projects)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -7,10 +7,15 @@ Feature: Managing users
|
|
7
7
|
Given an account exists with a name of "Test"
|
8
8
|
And I am signed in as an admin of the "Test" account
|
9
9
|
And I am on the memberships page for the "Test" account
|
10
|
+
And the following projects exist:
|
11
|
+
| account | name |
|
12
|
+
| name: Test | See me |
|
13
|
+
| name: Test | Can't find me |
|
10
14
|
|
11
15
|
Scenario: Invite new users
|
12
16
|
When I follow "Invite user"
|
13
17
|
And I fill in "Email" with "invitee@example.com"
|
18
|
+
And I check "See me"
|
14
19
|
And I press "Invite User"
|
15
20
|
Then I should see "invited"
|
16
21
|
When I sign out
|
@@ -21,7 +26,9 @@ Feature: Managing users
|
|
21
26
|
| Confirm password | secret |
|
22
27
|
And I press "Accept Invitation"
|
23
28
|
Then I should be signed in
|
29
|
+
And "invitee@example.com" should be a member of the "See me" project
|
24
30
|
And "invitee@example.com" should be a member of the "Test" account
|
31
|
+
But "invitee@example.com" should not be a member of the "Can't find me" project
|
25
32
|
When I go to the settings page
|
26
33
|
Then the "Name" field should contain "Billy"
|
27
34
|
|
@@ -54,3 +54,11 @@ Then /^"([^"]*)" should be an admin member of the "([^"]*)" account$/ do |email,
|
|
54
54
|
User.find_by_email!(email).should be_admin_of(Account.find_by_name!(account_name))
|
55
55
|
end
|
56
56
|
|
57
|
+
Then /^"([^"]*)" should be a member of the "([^"]*)" project/ do |email, project_name|
|
58
|
+
User.find_by_email!(email).should be_member_of(Project.find_by_name!(project_name))
|
59
|
+
end
|
60
|
+
|
61
|
+
Then /^"([^"]*)" should not be a member of the "([^"]*)" project/ do |email, project_name|
|
62
|
+
User.find_by_email!(email).should_not be_member_of(Project.find_by_name!(project_name))
|
63
|
+
end
|
64
|
+
|
@@ -59,10 +59,18 @@ class CreateSaucyTables < ActiveRecord::Migration
|
|
59
59
|
end
|
60
60
|
|
61
61
|
add_index :plans, :name
|
62
|
+
|
63
|
+
create_table :invitations_projects, :id => false do |table|
|
64
|
+
table.integer :invitation_id, :null => false
|
65
|
+
table.integer :project_id, :null => false
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index :invitations_projects, [:invitation_id, :project_id], :unique => true
|
62
69
|
end
|
63
70
|
|
64
71
|
def self.down
|
65
72
|
remove_column :users, :name
|
73
|
+
drop_table :invitations_projects
|
66
74
|
drop_table :plans
|
67
75
|
drop_table :projects
|
68
76
|
drop_table :permissions
|
@@ -24,8 +24,11 @@ end
|
|
24
24
|
|
25
25
|
describe InvitationsController, "new", :as => :account_admin do
|
26
26
|
let(:invitation) { Invitation.new }
|
27
|
+
let(:projects) { ['one', 'two'] }
|
27
28
|
|
28
29
|
before do
|
30
|
+
Account.stubs(:find_by_url! => account)
|
31
|
+
account.stubs(:projects_by_name => projects)
|
29
32
|
Invitation.stubs(:new => invitation)
|
30
33
|
get :new, :account_id => account.to_param
|
31
34
|
end
|
@@ -39,6 +42,10 @@ describe InvitationsController, "new", :as => :account_admin do
|
|
39
42
|
Invitation.should have_received(:new)
|
40
43
|
should assign_to(:invitation).with(invitation)
|
41
44
|
end
|
45
|
+
|
46
|
+
it "assigns projects" do
|
47
|
+
should assign_to(:projects).with(projects)
|
48
|
+
end
|
42
49
|
end
|
43
50
|
|
44
51
|
describe InvitationsController, "valid create", :as => :account_admin do
|
@@ -69,10 +76,13 @@ end
|
|
69
76
|
|
70
77
|
describe InvitationsController, "invalid create", :as => :account_admin do
|
71
78
|
let(:invitation) { Factory.stub(:invitation) }
|
79
|
+
let(:projects) { ['one', 'two'] }
|
72
80
|
|
73
81
|
before do
|
74
82
|
Invitation.stubs(:new => invitation)
|
75
83
|
invitation.stubs(:save => false)
|
84
|
+
Account.stubs(:find_by_url! => account)
|
85
|
+
account.stubs(:projects_by_name => projects)
|
76
86
|
post :create, :account_id => account.to_param, :invitation => {}
|
77
87
|
end
|
78
88
|
|
@@ -84,6 +94,10 @@ describe InvitationsController, "invalid create", :as => :account_admin do
|
|
84
94
|
it "doesn't set a flash message" do
|
85
95
|
should_not set_the_flash
|
86
96
|
end
|
97
|
+
|
98
|
+
it "assigns projects" do
|
99
|
+
should assign_to(:projects).with(projects)
|
100
|
+
end
|
87
101
|
end
|
88
102
|
|
89
103
|
describe InvitationsController, "show" do
|
data/spec/environment.rb
CHANGED
@@ -7,6 +7,8 @@ require 'clearance'
|
|
7
7
|
require 'factory_girl'
|
8
8
|
require 'bourne'
|
9
9
|
|
10
|
+
FileUtils.rm_f(File.join(PROJECT_ROOT, 'tmp', 'test.sqlite3'))
|
11
|
+
|
10
12
|
class ApplicationController < ActionController::Base
|
11
13
|
include Clearance::Authentication
|
12
14
|
include Saucy::AccountAuthorization
|
@@ -85,7 +87,6 @@ end
|
|
85
87
|
Clearance.configure do |config|
|
86
88
|
end
|
87
89
|
|
88
|
-
FileUtils.rm_f(File.join(PROJECT_ROOT, 'tmp', 'test.sqlite3'))
|
89
90
|
ClearanceCreateUsers.suppress_messages { ClearanceCreateUsers.migrate(:up) }
|
90
91
|
CreateSaucyTables.suppress_messages { CreateSaucyTables.migrate(:up) }
|
91
92
|
|
@@ -4,6 +4,8 @@ describe Invitation do
|
|
4
4
|
it { should validate_presence_of(:account_id) }
|
5
5
|
it { should validate_presence_of(:email) }
|
6
6
|
it { should belong_to(:account) }
|
7
|
+
it { should have_and_belong_to_many(:projects) }
|
8
|
+
|
7
9
|
it { should_not allow_mass_assignment_of(:account_id) }
|
8
10
|
|
9
11
|
%w(new_user_name new_user_email new_user_password
|
@@ -40,9 +42,11 @@ describe Invitation, "saved" do
|
|
40
42
|
end
|
41
43
|
|
42
44
|
describe Invitation, "valid accept for a new user" do
|
45
|
+
let(:account) { Factory(:account) }
|
46
|
+
let(:projects) { [Factory(:project, :account => account)] }
|
43
47
|
let(:password) { 'secret' }
|
44
48
|
let(:name) { 'Rocket' }
|
45
|
-
subject { Factory(:invitation) }
|
49
|
+
subject { Factory(:invitation, :account => account, :projects => projects) }
|
46
50
|
|
47
51
|
let!(:result) do
|
48
52
|
subject.accept(:new_user_password => password,
|
@@ -51,7 +55,6 @@ describe Invitation, "valid accept for a new user" do
|
|
51
55
|
end
|
52
56
|
|
53
57
|
let(:user) { subject.user }
|
54
|
-
let(:account) { subject.account }
|
55
58
|
|
56
59
|
it "returns true" do
|
57
60
|
result.should be_true
|
@@ -67,6 +70,12 @@ describe Invitation, "valid accept for a new user" do
|
|
67
70
|
it "adds the user to the account" do
|
68
71
|
account.users.should include(user)
|
69
72
|
end
|
73
|
+
|
74
|
+
it "adds the user to each of the invitation's projects" do
|
75
|
+
projects.each do |project|
|
76
|
+
user.should be_member_of(project)
|
77
|
+
end
|
78
|
+
end
|
70
79
|
end
|
71
80
|
|
72
81
|
describe Invitation, "invalid accept for a new user" do
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- thoughtbot, inc.
|