Commit a00c09a617c4c67d7c9f5fbba8f62e42253f709e

Authored by Heitor
1 parent 93df8ac0

Created Repository Attributes, joining Repository with User

Signed-off-by: Pedro Scocco <pedroscocco@gmail.com>
app/models/repository_attributes.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class RepositoryAttributes < ActiveRecord::Base
  2 + belongs_to :user
  3 + validates :repository_id, presence: true
  4 + validates :user, presence: true
  5 +
  6 + def repository
  7 + Repository.find(repository_id)
  8 + end
  9 +end
... ...
db/migrate/20150616164352_create_repository_attributes.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class CreateRepositoryAttributes < ActiveRecord::Migration
  2 + def change
  3 + create_table :repository_attributes do |t|
  4 + t.integer :repository_id
  5 + t.references :user, index: true, foreign_key: true
  6 +
  7 + t.timestamps null: false
  8 + end
  9 + end
  10 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(version: 20150515195059) do
  14 +ActiveRecord::Schema.define(version: 20150616164352) do
15 15  
16 16 create_table "kalibro_configuration_attributes", force: :cascade do |t|
17 17 t.integer "user_id"
... ... @@ -38,6 +38,15 @@ ActiveRecord::Schema.define(version: 20150515195059) do
38 38 t.boolean "public", default: true
39 39 end
40 40  
  41 + create_table "repository_attributes", force: :cascade do |t|
  42 + t.integer "repository_id"
  43 + t.integer "user_id"
  44 + t.datetime "created_at", null: false
  45 + t.datetime "updated_at", null: false
  46 + end
  47 +
  48 + add_index "repository_attributes", ["user_id"], name: "index_repository_attributes_on_user_id"
  49 +
41 50 create_table "users", force: :cascade do |t|
42 51 t.string "name", limit: 255, default: "", null: false
43 52 t.string "email", limit: 255, default: "", null: false
... ...
spec/factories/repository_attributes.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +FactoryGirl.define do
  2 + factory :repository_attribute do
  3 + repository_id 1
  4 + association :user, strategy: :build
  5 + end
  6 +end
... ...
spec/models/repository_attributes_spec.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require 'rails_helper'
  2 +
  3 +RSpec.describe RepositoryAttributes, type: :model do
  4 + context 'validations' do
  5 + it { is_expected.to validate_presence_of(:repository_id) }
  6 + it { is_expected.to validate_presence_of(:user) }
  7 + end
  8 +
  9 + describe 'associations' do
  10 + it { is_expected.to belong_to(:user) }
  11 + end
  12 +end
... ...