Commit fa877b63126c84cb304228cf37b61d186d5e4477
1 parent
95965d3f
Exists in
master
and in
4 other branches
UsersGroup specs. Fixed db/schema
Showing
5 changed files
with
63 additions
and
45 deletions
Show diff stats
app/models/users_group.rb
@@ -15,7 +15,7 @@ class UsersGroup < ActiveRecord::Base | @@ -15,7 +15,7 @@ class UsersGroup < ActiveRecord::Base | ||
15 | } | 15 | } |
16 | end | 16 | end |
17 | 17 | ||
18 | - attr_accessible :group_access, :group_id, :user_id | 18 | + attr_accessible :group_access, :user_id |
19 | 19 | ||
20 | belongs_to :user | 20 | belongs_to :user |
21 | belongs_to :project | 21 | belongs_to :project |
@@ -33,6 +33,8 @@ class UsersGroup < ActiveRecord::Base | @@ -33,6 +33,8 @@ class UsersGroup < ActiveRecord::Base | ||
33 | validates :user_id, presence: true | 33 | validates :user_id, presence: true |
34 | validates :group_id, presence: true | 34 | validates :group_id, presence: true |
35 | 35 | ||
36 | + delegate :name, :username, :email, to: :user, prefix: true | ||
37 | + | ||
36 | def human_group_access | 38 | def human_group_access |
37 | UsersGroup.group_access_roles.index(self.group_access) | 39 | UsersGroup.group_access_roles.index(self.group_access) |
38 | end | 40 | end |
app/views/groups/people.html.haml
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | = render (@project ? "new_member" : "new_group_member") | 6 | = render (@project ? "new_member" : "new_group_member") |
7 | .ui-box | 7 | .ui-box |
8 | %h5.title | 8 | %h5.title |
9 | - Team | 9 | + #{@group.name} Team |
10 | %small | 10 | %small |
11 | (#{@users_groups.count}) | 11 | (#{@users_groups.count}) |
12 | %ul.well-list | 12 | %ul.well-list |
db/schema.rb
@@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
53 | t.integer "assignee_id" | 53 | t.integer "assignee_id" |
54 | t.integer "author_id" | 54 | t.integer "author_id" |
55 | t.integer "project_id" | 55 | t.integer "project_id" |
56 | - t.datetime "created_at", :null => false | ||
57 | - t.datetime "updated_at", :null => false | 56 | + t.datetime "created_at" |
57 | + t.datetime "updated_at" | ||
58 | t.integer "position", :default => 0 | 58 | t.integer "position", :default => 0 |
59 | t.string "branch_name" | 59 | t.string "branch_name" |
60 | t.text "description" | 60 | t.text "description" |
@@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
71 | 71 | ||
72 | create_table "keys", :force => true do |t| | 72 | create_table "keys", :force => true do |t| |
73 | t.integer "user_id" | 73 | t.integer "user_id" |
74 | - t.datetime "created_at", :null => false | ||
75 | - t.datetime "updated_at", :null => false | 74 | + t.datetime "created_at" |
75 | + t.datetime "updated_at" | ||
76 | t.text "key" | 76 | t.text "key" |
77 | t.string "title" | 77 | t.string "title" |
78 | t.string "identifier" | 78 | t.string "identifier" |
@@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
89 | t.integer "author_id" | 89 | t.integer "author_id" |
90 | t.integer "assignee_id" | 90 | t.integer "assignee_id" |
91 | t.string "title" | 91 | t.string "title" |
92 | - t.datetime "created_at", :null => false | ||
93 | - t.datetime "updated_at", :null => false | 92 | + t.datetime "created_at" |
93 | + t.datetime "updated_at" | ||
94 | t.text "st_commits", :limit => 2147483647 | 94 | t.text "st_commits", :limit => 2147483647 |
95 | t.text "st_diffs", :limit => 2147483647 | 95 | t.text "st_diffs", :limit => 2147483647 |
96 | t.integer "milestone_id" | 96 | t.integer "milestone_id" |
@@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
139 | t.text "note" | 139 | t.text "note" |
140 | t.string "noteable_type" | 140 | t.string "noteable_type" |
141 | t.integer "author_id" | 141 | t.integer "author_id" |
142 | - t.datetime "created_at", :null => false | ||
143 | - t.datetime "updated_at", :null => false | 142 | + t.datetime "created_at" |
143 | + t.datetime "updated_at" | ||
144 | t.integer "project_id" | 144 | t.integer "project_id" |
145 | t.string "attachment" | 145 | t.string "attachment" |
146 | t.string "line_code" | 146 | t.string "line_code" |
@@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
158 | t.string "name" | 158 | t.string "name" |
159 | t.string "path" | 159 | t.string "path" |
160 | t.text "description" | 160 | t.text "description" |
161 | - t.datetime "created_at", :null => false | ||
162 | - t.datetime "updated_at", :null => false | 161 | + t.datetime "created_at" |
162 | + t.datetime "updated_at" | ||
163 | t.integer "creator_id" | 163 | t.integer "creator_id" |
164 | t.string "default_branch" | 164 | t.string "default_branch" |
165 | t.boolean "issues_enabled", :default => true, :null => false | 165 | t.boolean "issues_enabled", :default => true, :null => false |
@@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
206 | t.text "content" | 206 | t.text "content" |
207 | t.integer "author_id", :null => false | 207 | t.integer "author_id", :null => false |
208 | t.integer "project_id" | 208 | t.integer "project_id" |
209 | - t.datetime "created_at", :null => false | ||
210 | - t.datetime "updated_at", :null => false | 209 | + t.datetime "created_at" |
210 | + t.datetime "updated_at" | ||
211 | t.string "file_name" | 211 | t.string "file_name" |
212 | t.datetime "expires_at" | 212 | t.datetime "expires_at" |
213 | t.boolean "private", :default => true, :null => false | 213 | t.boolean "private", :default => true, :null => false |
@@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
228 | t.datetime "created_at" | 228 | t.datetime "created_at" |
229 | end | 229 | end |
230 | 230 | ||
231 | - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" | ||
232 | - add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context" | ||
233 | - | ||
234 | create_table "tags", :force => true do |t| | 231 | create_table "tags", :force => true do |t| |
235 | t.string "name" | 232 | t.string "name" |
236 | end | 233 | end |
@@ -262,50 +259,49 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -262,50 +259,49 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
262 | end | 259 | end |
263 | 260 | ||
264 | create_table "users", :force => true do |t| | 261 | create_table "users", :force => true do |t| |
265 | - t.string "email", :default => "", :null => false | ||
266 | - t.string "encrypted_password", :default => "", :null => false | 262 | + t.string "email", :default => "", :null => false |
263 | + t.string "encrypted_password", :limit => 128, :default => "", :null => false | ||
267 | t.string "reset_password_token" | 264 | t.string "reset_password_token" |
268 | t.datetime "reset_password_sent_at" | 265 | t.datetime "reset_password_sent_at" |
269 | t.datetime "remember_created_at" | 266 | t.datetime "remember_created_at" |
270 | - t.integer "sign_in_count", :default => 0 | 267 | + t.integer "sign_in_count", :default => 0 |
271 | t.datetime "current_sign_in_at" | 268 | t.datetime "current_sign_in_at" |
272 | t.datetime "last_sign_in_at" | 269 | t.datetime "last_sign_in_at" |
273 | t.string "current_sign_in_ip" | 270 | t.string "current_sign_in_ip" |
274 | t.string "last_sign_in_ip" | 271 | t.string "last_sign_in_ip" |
275 | - t.datetime "created_at", :null => false | ||
276 | - t.datetime "updated_at", :null => false | 272 | + t.datetime "created_at" |
273 | + t.datetime "updated_at" | ||
277 | t.string "name" | 274 | t.string "name" |
278 | - t.boolean "admin", :default => false, :null => false | ||
279 | - t.integer "projects_limit", :default => 10 | ||
280 | - t.string "skype", :default => "", :null => false | ||
281 | - t.string "linkedin", :default => "", :null => false | ||
282 | - t.string "twitter", :default => "", :null => false | 275 | + t.boolean "admin", :default => false, :null => false |
276 | + t.integer "projects_limit", :default => 10 | ||
277 | + t.string "skype", :default => "", :null => false | ||
278 | + t.string "linkedin", :default => "", :null => false | ||
279 | + t.string "twitter", :default => "", :null => false | ||
283 | t.string "authentication_token" | 280 | t.string "authentication_token" |
284 | - t.integer "theme_id", :default => 1, :null => false | 281 | + t.integer "theme_id", :default => 1, :null => false |
285 | t.string "bio" | 282 | t.string "bio" |
286 | - t.integer "failed_attempts", :default => 0 | 283 | + t.integer "failed_attempts", :default => 0 |
287 | t.datetime "locked_at" | 284 | t.datetime "locked_at" |
288 | t.string "extern_uid" | 285 | t.string "extern_uid" |
289 | t.string "provider" | 286 | t.string "provider" |
290 | t.string "username" | 287 | t.string "username" |
291 | - t.boolean "can_create_group", :default => true, :null => false | ||
292 | - t.boolean "can_create_team", :default => true, :null => false | 288 | + t.boolean "can_create_group", :default => true, :null => false |
289 | + t.boolean "can_create_team", :default => true, :null => false | ||
293 | t.string "state" | 290 | t.string "state" |
294 | - t.integer "color_scheme_id", :default => 1, :null => false | ||
295 | - t.integer "notification_level", :default => 1, :null => false | 291 | + t.integer "color_scheme_id", :default => 1, :null => false |
292 | + t.integer "notification_level", :default => 1, :null => false | ||
296 | t.datetime "password_expires_at" | 293 | t.datetime "password_expires_at" |
297 | t.integer "created_by_id" | 294 | t.integer "created_by_id" |
298 | end | 295 | end |
299 | 296 | ||
300 | add_index "users", ["admin"], :name => "index_users_on_admin" | 297 | add_index "users", ["admin"], :name => "index_users_on_admin" |
301 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true | 298 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true |
302 | - add_index "users", ["extern_uid", "provider"], :name => "index_users_on_extern_uid_and_provider", :unique => true | ||
303 | add_index "users", ["name"], :name => "index_users_on_name" | 299 | add_index "users", ["name"], :name => "index_users_on_name" |
304 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true | 300 | add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true |
305 | add_index "users", ["username"], :name => "index_users_on_username" | 301 | add_index "users", ["username"], :name => "index_users_on_username" |
306 | 302 | ||
307 | create_table "users_groups", :force => true do |t| | 303 | create_table "users_groups", :force => true do |t| |
308 | - t.integer "access_level", :null => false | 304 | + t.integer "group_access", :null => false |
309 | t.integer "group_id", :null => false | 305 | t.integer "group_id", :null => false |
310 | t.integer "user_id", :null => false | 306 | t.integer "user_id", :null => false |
311 | t.datetime "created_at", :null => false | 307 | t.datetime "created_at", :null => false |
@@ -315,8 +311,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -315,8 +311,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
315 | create_table "users_projects", :force => true do |t| | 311 | create_table "users_projects", :force => true do |t| |
316 | t.integer "user_id", :null => false | 312 | t.integer "user_id", :null => false |
317 | t.integer "project_id", :null => false | 313 | t.integer "project_id", :null => false |
318 | - t.datetime "created_at", :null => false | ||
319 | - t.datetime "updated_at", :null => false | 314 | + t.datetime "created_at" |
315 | + t.datetime "updated_at" | ||
320 | t.integer "project_access", :default => 0, :null => false | 316 | t.integer "project_access", :default => 0, :null => false |
321 | t.integer "notification_level", :default => 3, :null => false | 317 | t.integer "notification_level", :default => 3, :null => false |
322 | end | 318 | end |
@@ -328,8 +324,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | @@ -328,8 +324,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do | ||
328 | create_table "web_hooks", :force => true do |t| | 324 | create_table "web_hooks", :force => true do |t| |
329 | t.string "url" | 325 | t.string "url" |
330 | t.integer "project_id" | 326 | t.integer "project_id" |
331 | - t.datetime "created_at", :null => false | ||
332 | - t.datetime "updated_at", :null => false | 327 | + t.datetime "created_at" |
328 | + t.datetime "updated_at" | ||
333 | t.string "type", :default => "ProjectHook" | 329 | t.string "type", :default => "ProjectHook" |
334 | t.integer "service_id" | 330 | t.integer "service_id" |
335 | end | 331 | end |
spec/factories/users_groups.rb
1 | -# Read about factories at https://github.com/thoughtbot/factory_girl | ||
2 | - | ||
3 | FactoryGirl.define do | 1 | FactoryGirl.define do |
4 | factory :users_group do | 2 | factory :users_group do |
5 | - access_level 1 | ||
6 | - group_id 1 | ||
7 | - user_id 1 | 3 | + group_access { UsersGroup::OWNER } |
4 | + group | ||
5 | + user | ||
8 | end | 6 | end |
9 | end | 7 | end |
spec/models/users_group_spec.rb
1 | require 'spec_helper' | 1 | require 'spec_helper' |
2 | 2 | ||
3 | describe UsersGroup do | 3 | describe UsersGroup do |
4 | - pending "add some examples to (or delete) #{__FILE__}" | 4 | + describe "Associations" do |
5 | + it { should belong_to(:group) } | ||
6 | + it { should belong_to(:user) } | ||
7 | + end | ||
8 | + | ||
9 | + describe "Mass assignment" do | ||
10 | + it { should_not allow_mass_assignment_of(:group_id) } | ||
11 | + end | ||
12 | + | ||
13 | + describe "Validation" do | ||
14 | + let!(:users_group) { create(:users_group) } | ||
15 | + | ||
16 | + it { should validate_presence_of(:user) } | ||
17 | + it { should validate_uniqueness_of(:user_id).scoped_to(:group_id).with_message(/already exists/) } | ||
18 | + | ||
19 | + it { should validate_presence_of(:group) } | ||
20 | + it { should ensure_inclusion_of(:group_access).in_array(UsersGroup.group_access_roles.values) } | ||
21 | + end | ||
22 | + | ||
23 | + describe "Delegate methods" do | ||
24 | + it { should respond_to(:user_name) } | ||
25 | + it { should respond_to(:user_email) } | ||
26 | + end | ||
5 | end | 27 | end |