saucy 0.2.25 → 0.2.26
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,13 +7,17 @@ Feature: Manage Projects
|
|
7
7
|
Given the following account exists:
|
8
8
|
| name | keyword |
|
9
9
|
| Test | test |
|
10
|
-
And
|
10
|
+
And the following user exists:
|
11
|
+
| name | email |
|
12
|
+
| Joe User | joe@example.com |
|
11
13
|
And "joe@example.com" is an admin of the "Test" account
|
14
|
+
And I sign in as "joe@example.com"
|
12
15
|
|
13
16
|
Scenario: Create new project
|
14
17
|
When I go to the projects page for the "Test" account
|
15
18
|
And I follow "New Project"
|
16
|
-
|
19
|
+
Then the "Joe User" checkbox should be checked
|
20
|
+
When I fill in "Name" with "Project 1"
|
17
21
|
And I fill in "Keyword" with "project1"
|
18
22
|
And I should see "http://www.example.com/accounts/test/projects/keyword"
|
19
23
|
And I press "Create"
|
data/lib/saucy/project.rb
CHANGED
@@ -15,14 +15,26 @@ module Saucy
|
|
15
15
|
:with => %r{^[a-z0-9]+$},
|
16
16
|
:message => "must be only lower case letters."
|
17
17
|
|
18
|
-
after_create :assign_default_memberships
|
19
18
|
after_save :update_memberships
|
20
19
|
|
21
|
-
# We have to define
|
22
|
-
# because ActiveRecord does the same
|
20
|
+
# We have to define these here instead of mixing them in,
|
21
|
+
# because ActiveRecord does the same.
|
22
|
+
|
23
23
|
def user_ids=(new_user_ids)
|
24
24
|
@new_user_ids = new_user_ids.reject { |user_id| user_id.blank? }
|
25
25
|
end
|
26
|
+
|
27
|
+
def users
|
28
|
+
if new_record?
|
29
|
+
permissions.map { |permission| permission.membership.user }
|
30
|
+
else
|
31
|
+
permissions.includes(:user).map { |permission| permission.user }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def user_ids
|
36
|
+
users.map(&:id)
|
37
|
+
end
|
26
38
|
end
|
27
39
|
|
28
40
|
module ClassMethods
|
@@ -33,6 +45,10 @@ module Saucy
|
|
33
45
|
def by_name
|
34
46
|
order("projects.name")
|
35
47
|
end
|
48
|
+
|
49
|
+
def build_with_default_permissions
|
50
|
+
new.assign_default_permissions
|
51
|
+
end
|
36
52
|
end
|
37
53
|
|
38
54
|
module InstanceMethods
|
@@ -46,14 +62,15 @@ module Saucy
|
|
46
62
|
exists?(:memberships => { :user_id => user.id })
|
47
63
|
end
|
48
64
|
|
49
|
-
|
50
|
-
|
51
|
-
def assign_default_memberships
|
65
|
+
def assign_default_permissions
|
52
66
|
account.memberships.where(:admin => true).each do |membership|
|
53
|
-
self.permissions.
|
67
|
+
self.permissions.build(:membership => membership)
|
54
68
|
end
|
69
|
+
self
|
55
70
|
end
|
56
71
|
|
72
|
+
private
|
73
|
+
|
57
74
|
def update_memberships
|
58
75
|
if @new_user_ids
|
59
76
|
removed_user_ids = self.user_ids - @new_user_ids
|
data/spec/models/project_spec.rb
CHANGED
@@ -4,7 +4,6 @@ describe Project do
|
|
4
4
|
it { should belong_to(:account) }
|
5
5
|
it { should validate_presence_of(:account_id) }
|
6
6
|
it { should have_many(:permissions) }
|
7
|
-
it { should have_many(:users).through(:permissions) }
|
8
7
|
it { should validate_presence_of(:keyword) }
|
9
8
|
it { should validate_presence_of(:name) }
|
10
9
|
|
@@ -50,13 +49,26 @@ describe Project, "keyword uniqueness" do
|
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
52
|
+
share_examples_for "default project permissions" do
|
53
|
+
it "is viewable by admins by default" do
|
54
|
+
admins.each do |admin|
|
55
|
+
subject.users.should include(admin)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "isn't viewable by non-members" do
|
60
|
+
subject.users.should_not include(non_admin)
|
61
|
+
subject.users.should_not include(non_member)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
describe Project, "for an account with admin and non-admin users" do
|
54
66
|
let!(:account) { Factory(:account, :name => "Account") }
|
55
67
|
let!(:other_account) { Factory(:account, :name => "Other") }
|
56
68
|
let!(:non_admin) { Factory(:user) }
|
57
69
|
let!(:admins) { [Factory(:user), Factory(:user)] }
|
58
70
|
let!(:non_member) { Factory(:user) }
|
59
|
-
subject { Factory(:project, :account => account) }
|
71
|
+
subject { Factory.build(:project, :account => account) }
|
60
72
|
|
61
73
|
before do
|
62
74
|
Factory(:membership, :account => account, :user => non_admin, :admin => false)
|
@@ -66,21 +78,21 @@ describe Project, "for an account with admin and non-admin users" do
|
|
66
78
|
admins.each do |admin|
|
67
79
|
Factory(:membership, :user => admin, :account => account, :admin => true)
|
68
80
|
end
|
81
|
+
|
82
|
+
subject.assign_default_permissions
|
69
83
|
end
|
70
84
|
|
71
|
-
|
72
|
-
|
85
|
+
context "before saving" do
|
86
|
+
it_behaves_like "default project permissions"
|
73
87
|
end
|
74
88
|
|
75
|
-
|
76
|
-
|
77
|
-
|
89
|
+
context "after saving" do
|
90
|
+
before do
|
91
|
+
subject.save!
|
92
|
+
subject.reload
|
78
93
|
end
|
79
|
-
end
|
80
94
|
|
81
|
-
|
82
|
-
should_not have_member(non_admin)
|
83
|
-
should_not have_member(non_member)
|
95
|
+
it_behaves_like "default project permissions"
|
84
96
|
end
|
85
97
|
end
|
86
98
|
|
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: 35
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 26
|
10
|
+
version: 0.2.26
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- thoughtbot, inc.
|