Commit c3b074acab554fc40a8fcb6060ed7ab10e4171a4

Authored by Dmitriy Zaporozhets
1 parent be1dc554

Service model and service hook

app/assets/images/service-gitlab-ci.png 0 → 100644

2.69 KB

app/models/service.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: services
  4 +#
  5 +# id :integer not null, primary key
  6 +# type :string(255)
  7 +# title :string(255)
  8 +# token :string(255)
  9 +# project_id :integer not null
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +#
  13 +
  14 +class Service < ActiveRecord::Base
  15 + attr_accessible :title, :token, :type
  16 +
  17 + belongs_to :project
  18 + has_one :service_hook
  19 +
  20 + validates :project_id, presence: true
  21 +end
... ...
app/models/service_hook.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: web_hooks
  4 +#
  5 +# id :integer not null, primary key
  6 +# url :string(255)
  7 +# project_id :integer
  8 +# created_at :datetime not null
  9 +# updated_at :datetime not null
  10 +# type :string(255) default("ProjectHook")
  11 +#
  12 +
  13 +class ServiceHook < WebHook
  14 + belongs_to :service
  15 +end
... ...
db/migrate/20121119170638_create_services.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CreateServices < ActiveRecord::Migration
  2 + def change
  3 + create_table :services do |t|
  4 + t.string :type
  5 + t.string :title
  6 + t.string :token
  7 + t.integer :project_id, null: false
  8 +
  9 + t.timestamps
  10 + end
  11 + end
  12 +end
... ...
db/migrate/20121120051432_add_service_id_to_web_hook.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class AddServiceIdToWebHook < ActiveRecord::Migration
  2 + def change
  3 + add_column :web_hooks, :service_id, :integer, null: true
  4 + end
  5 +end
... ...
spec/models/service_hook_spec.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: web_hooks
  4 +#
  5 +# id :integer not null, primary key
  6 +# url :string(255)
  7 +# project_id :integer
  8 +# created_at :datetime not null
  9 +# updated_at :datetime not null
  10 +# type :string(255) default("ProjectHook")
  11 +#
  12 +
  13 +require "spec_helper"
  14 +
  15 +describe ServiceHook do
  16 + describe "Associations" do
  17 + it { should belong_to :service }
  18 + end
  19 +end
... ...
spec/models/service_spec.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +# == Schema Information
  2 +#
  3 +# Table name: services
  4 +#
  5 +# id :integer not null, primary key
  6 +# type :string(255)
  7 +# title :string(255)
  8 +# token :string(255)
  9 +# project_id :integer not null
  10 +# created_at :datetime not null
  11 +# updated_at :datetime not null
  12 +#
  13 +
  14 +require 'spec_helper'
  15 +
  16 +describe Service do
  17 + describe "Associations" do
  18 + it { should belong_to :project }
  19 + it { should have_one :service_hook }
  20 + end
  21 +
  22 + describe "Mass assignment" do
  23 + it { should_not allow_mass_assignment_of(:project_id) }
  24 + end
  25 +end
... ...