Commit fa3ae24ca7a11f3d87c8838cf05a95dfecfa4c5c
1 parent
2e1c3c52
Exists in
master
and in
4 other branches
Group entity. Group has many projects
Showing
8 changed files
with
116 additions
and
1 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +# == Schema Information | |
| 2 | +# | |
| 3 | +# Table name: groups | |
| 4 | +# | |
| 5 | +# id :integer not null, primary key | |
| 6 | +# name :string(255) not null | |
| 7 | +# code :string(255) not null | |
| 8 | +# owner_id :integer not null | |
| 9 | +# created_at :datetime not null | |
| 10 | +# updated_at :datetime not null | |
| 11 | +# | |
| 12 | + | |
| 13 | +class Group < ActiveRecord::Base | |
| 14 | + attr_accessible :code, :name, :owner_id | |
| 15 | + | |
| 16 | + has_many :projects | |
| 17 | + belongs_to :owner, class_name: "User" | |
| 18 | + | |
| 19 | + validates :name, presence: true, uniqueness: true | |
| 20 | + validates :code, presence: true, uniqueness: true | |
| 21 | + validates :owner_id, presence: true | |
| 22 | +end | ... | ... |
app/models/project.rb
| ... | ... | @@ -11,6 +11,7 @@ class Project < ActiveRecord::Base |
| 11 | 11 | attr_accessor :error_code |
| 12 | 12 | |
| 13 | 13 | # Relations |
| 14 | + belongs_to :group | |
| 14 | 15 | belongs_to :owner, class_name: "User" |
| 15 | 16 | has_many :users, through: :users_projects |
| 16 | 17 | has_many :events, dependent: :destroy |
| ... | ... | @@ -173,4 +174,6 @@ end |
| 173 | 174 | # wall_enabled :boolean default(TRUE), not null |
| 174 | 175 | # merge_requests_enabled :boolean default(TRUE), not null |
| 175 | 176 | # wiki_enabled :boolean default(TRUE), not null |
| 177 | +# group_id :integer | |
| 176 | 178 | # |
| 179 | + | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(:version => 20120905043334) do | |
| 14 | +ActiveRecord::Schema.define(:version => 20121002151033) do | |
| 15 | 15 | |
| 16 | 16 | create_table "events", :force => true do |t| |
| 17 | 17 | t.string "target_type" |
| ... | ... | @@ -25,6 +25,14 @@ ActiveRecord::Schema.define(:version => 20120905043334) do |
| 25 | 25 | t.integer "author_id" |
| 26 | 26 | end |
| 27 | 27 | |
| 28 | + create_table "groups", :force => true do |t| | |
| 29 | + t.string "name", :null => false | |
| 30 | + t.string "code", :null => false | |
| 31 | + t.integer "owner_id", :null => false | |
| 32 | + t.datetime "created_at", :null => false | |
| 33 | + t.datetime "updated_at", :null => false | |
| 34 | + end | |
| 35 | + | |
| 28 | 36 | create_table "issues", :force => true do |t| |
| 29 | 37 | t.string "title" |
| 30 | 38 | t.integer "assignee_id" |
| ... | ... | @@ -108,6 +116,7 @@ ActiveRecord::Schema.define(:version => 20120905043334) do |
| 108 | 116 | t.boolean "wall_enabled", :default => true, :null => false |
| 109 | 117 | t.boolean "merge_requests_enabled", :default => true, :null => false |
| 110 | 118 | t.boolean "wiki_enabled", :default => true, :null => false |
| 119 | + t.integer "group_id" | |
| 111 | 120 | end |
| 112 | 121 | |
| 113 | 122 | create_table "protected_branches", :force => true do |t| | ... | ... |
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +# == Schema Information | |
| 2 | +# | |
| 3 | +# Table name: groups | |
| 4 | +# | |
| 5 | +# id :integer not null, primary key | |
| 6 | +# name :string(255) not null | |
| 7 | +# code :string(255) not null | |
| 8 | +# owner_id :integer not null | |
| 9 | +# created_at :datetime not null | |
| 10 | +# updated_at :datetime not null | |
| 11 | +# | |
| 12 | + | |
| 13 | +# Read about factories at https://github.com/thoughtbot/factory_girl | |
| 14 | + | |
| 15 | +FactoryGirl.define do | |
| 16 | + factory :group do | |
| 17 | + name "MyString" | |
| 18 | + code "MyString" | |
| 19 | + owner_id 1 | |
| 20 | + end | |
| 21 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | +# == Schema Information | |
| 2 | +# | |
| 3 | +# Table name: groups | |
| 4 | +# | |
| 5 | +# id :integer not null, primary key | |
| 6 | +# name :string(255) not null | |
| 7 | +# code :string(255) not null | |
| 8 | +# owner_id :integer not null | |
| 9 | +# created_at :datetime not null | |
| 10 | +# updated_at :datetime not null | |
| 11 | +# | |
| 12 | + | |
| 13 | +require 'spec_helper' | |
| 14 | + | |
| 15 | +describe Group do | |
| 16 | + it { should have_many :projects } | |
| 17 | + it { should validate_presence_of :name } | |
| 18 | + it { should validate_uniqueness_of(:name) } | |
| 19 | + it { should validate_presence_of :code } | |
| 20 | + it { should validate_uniqueness_of(:code) } | |
| 21 | + it { should validate_presence_of :owner_id } | |
| 22 | +end | ... | ... |
spec/models/project_spec.rb
| 1 | +# == Schema Information | |
| 2 | +# | |
| 3 | +# Table name: projects | |
| 4 | +# | |
| 5 | +# id :integer not null, primary key | |
| 6 | +# name :string(255) | |
| 7 | +# path :string(255) | |
| 8 | +# description :text | |
| 9 | +# created_at :datetime not null | |
| 10 | +# updated_at :datetime not null | |
| 11 | +# private_flag :boolean default(TRUE), not null | |
| 12 | +# code :string(255) | |
| 13 | +# owner_id :integer | |
| 14 | +# default_branch :string(255) | |
| 15 | +# issues_enabled :boolean default(TRUE), not null | |
| 16 | +# wall_enabled :boolean default(TRUE), not null | |
| 17 | +# merge_requests_enabled :boolean default(TRUE), not null | |
| 18 | +# wiki_enabled :boolean default(TRUE), not null | |
| 19 | +# group_id :integer | |
| 20 | +# | |
| 21 | + | |
| 1 | 22 | require 'spec_helper' |
| 2 | 23 | |
| 3 | 24 | describe Project do |
| 4 | 25 | describe "Associations" do |
| 26 | + it { should belong_to(:group) } | |
| 5 | 27 | it { should belong_to(:owner).class_name('User') } |
| 6 | 28 | it { should have_many(:users) } |
| 7 | 29 | it { should have_many(:events).dependent(:destroy) } | ... | ... |