Commit fa877b63126c84cb304228cf37b61d186d5e4477

Authored by Dmitriy Zaporozhets
1 parent 95965d3f

UsersGroup specs. Fixed db/schema

app/models/users_group.rb
... ... @@ -15,7 +15,7 @@ class UsersGroup < ActiveRecord::Base
15 15 }
16 16 end
17 17  
18   - attr_accessible :group_access, :group_id, :user_id
  18 + attr_accessible :group_access, :user_id
19 19  
20 20 belongs_to :user
21 21 belongs_to :project
... ... @@ -33,6 +33,8 @@ class UsersGroup < ActiveRecord::Base
33 33 validates :user_id, presence: true
34 34 validates :group_id, presence: true
35 35  
  36 + delegate :name, :username, :email, to: :user, prefix: true
  37 +
36 38 def human_group_access
37 39 UsersGroup.group_access_roles.index(self.group_access)
38 40 end
... ...
app/views/groups/people.html.haml
... ... @@ -6,7 +6,7 @@
6 6 = render (@project ? "new_member" : "new_group_member")
7 7 .ui-box
8 8 %h5.title
9   - Team
  9 + #{@group.name} Team
10 10 %small
11 11 (#{@users_groups.count})
12 12 %ul.well-list
... ...
db/schema.rb
... ... @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
53 53 t.integer "assignee_id"
54 54 t.integer "author_id"
55 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 58 t.integer "position", :default => 0
59 59 t.string "branch_name"
60 60 t.text "description"
... ... @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
71 71  
72 72 create_table "keys", :force => true do |t|
73 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 76 t.text "key"
77 77 t.string "title"
78 78 t.string "identifier"
... ... @@ -89,8 +89,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
89 89 t.integer "author_id"
90 90 t.integer "assignee_id"
91 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 94 t.text "st_commits", :limit => 2147483647
95 95 t.text "st_diffs", :limit => 2147483647
96 96 t.integer "milestone_id"
... ... @@ -139,8 +139,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
139 139 t.text "note"
140 140 t.string "noteable_type"
141 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 144 t.integer "project_id"
145 145 t.string "attachment"
146 146 t.string "line_code"
... ... @@ -158,8 +158,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
158 158 t.string "name"
159 159 t.string "path"
160 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 163 t.integer "creator_id"
164 164 t.string "default_branch"
165 165 t.boolean "issues_enabled", :default => true, :null => false
... ... @@ -206,8 +206,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
206 206 t.text "content"
207 207 t.integer "author_id", :null => false
208 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 211 t.string "file_name"
212 212 t.datetime "expires_at"
213 213 t.boolean "private", :default => true, :null => false
... ... @@ -228,9 +228,6 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
228 228 t.datetime "created_at"
229 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 231 create_table "tags", :force => true do |t|
235 232 t.string "name"
236 233 end
... ... @@ -262,50 +259,49 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
262 259 end
263 260  
264 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 264 t.string "reset_password_token"
268 265 t.datetime "reset_password_sent_at"
269 266 t.datetime "remember_created_at"
270   - t.integer "sign_in_count", :default => 0
  267 + t.integer "sign_in_count", :default => 0
271 268 t.datetime "current_sign_in_at"
272 269 t.datetime "last_sign_in_at"
273 270 t.string "current_sign_in_ip"
274 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 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 280 t.string "authentication_token"
284   - t.integer "theme_id", :default => 1, :null => false
  281 + t.integer "theme_id", :default => 1, :null => false
285 282 t.string "bio"
286   - t.integer "failed_attempts", :default => 0
  283 + t.integer "failed_attempts", :default => 0
287 284 t.datetime "locked_at"
288 285 t.string "extern_uid"
289 286 t.string "provider"
290 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 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 293 t.datetime "password_expires_at"
297 294 t.integer "created_by_id"
298 295 end
299 296  
300 297 add_index "users", ["admin"], :name => "index_users_on_admin"
301 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 299 add_index "users", ["name"], :name => "index_users_on_name"
304 300 add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
305 301 add_index "users", ["username"], :name => "index_users_on_username"
306 302  
307 303 create_table "users_groups", :force => true do |t|
308   - t.integer "access_level", :null => false
  304 + t.integer "group_access", :null => false
309 305 t.integer "group_id", :null => false
310 306 t.integer "user_id", :null => false
311 307 t.datetime "created_at", :null => false
... ... @@ -315,8 +311,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
315 311 create_table "users_projects", :force => true do |t|
316 312 t.integer "user_id", :null => false
317 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 316 t.integer "project_access", :default => 0, :null => false
321 317 t.integer "notification_level", :default => 3, :null => false
322 318 end
... ... @@ -328,8 +324,8 @@ ActiveRecord::Schema.define(:version => 20130617095603) do
328 324 create_table "web_hooks", :force => true do |t|
329 325 t.string "url"
330 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 329 t.string "type", :default => "ProjectHook"
334 330 t.integer "service_id"
335 331 end
... ...
spec/factories/users_groups.rb
1   -# Read about factories at https://github.com/thoughtbot/factory_girl
2   -
3 1 FactoryGirl.define do
4 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 6 end
9 7 end
... ...
spec/models/users_group_spec.rb
1 1 require 'spec_helper'
2 2  
3 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 27 end
... ...