summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-19 21:14:05 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-20 11:33:49 +0200
commitc3b074acab554fc40a8fcb6060ed7ab10e4171a4 (patch)
treeb524e4c96f998534522f2b4b4fea9994da8c6983
parentbe1dc5544a7840d17657d3d8fcecb0d0fd4401b5 (diff)
downloadgitlab-ce-c3b074acab554fc40a8fcb6060ed7ab10e4171a4.tar.gz
Service model and service hook
-rw-r--r--app/assets/images/service-gitlab-ci.pngbin0 -> 2758 bytes
-rw-r--r--app/models/service.rb21
-rw-r--r--app/models/service_hook.rb15
-rw-r--r--db/migrate/20121119170638_create_services.rb12
-rw-r--r--db/migrate/20121120051432_add_service_id_to_web_hook.rb5
-rw-r--r--spec/models/service_hook_spec.rb19
-rw-r--r--spec/models/service_spec.rb25
7 files changed, 97 insertions, 0 deletions
diff --git a/app/assets/images/service-gitlab-ci.png b/app/assets/images/service-gitlab-ci.png
new file mode 100644
index 00000000000..afaa10d02b0
--- /dev/null
+++ b/app/assets/images/service-gitlab-ci.png
Binary files differ
diff --git a/app/models/service.rb b/app/models/service.rb
new file mode 100644
index 00000000000..b29f5089a1e
--- /dev/null
+++ b/app/models/service.rb
@@ -0,0 +1,21 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# token :string(255)
+# project_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+class Service < ActiveRecord::Base
+ attr_accessible :title, :token, :type
+
+ belongs_to :project
+ has_one :service_hook
+
+ validates :project_id, presence: true
+end
diff --git a/app/models/service_hook.rb b/app/models/service_hook.rb
new file mode 100644
index 00000000000..aedd0eef271
--- /dev/null
+++ b/app/models/service_hook.rb
@@ -0,0 +1,15 @@
+# == Schema Information
+#
+# Table name: web_hooks
+#
+# id :integer not null, primary key
+# url :string(255)
+# project_id :integer
+# created_at :datetime not null
+# updated_at :datetime not null
+# type :string(255) default("ProjectHook")
+#
+
+class ServiceHook < WebHook
+ belongs_to :service
+end
diff --git a/db/migrate/20121119170638_create_services.rb b/db/migrate/20121119170638_create_services.rb
new file mode 100644
index 00000000000..f7cac1445a7
--- /dev/null
+++ b/db/migrate/20121119170638_create_services.rb
@@ -0,0 +1,12 @@
+class CreateServices < ActiveRecord::Migration
+ def change
+ create_table :services do |t|
+ t.string :type
+ t.string :title
+ t.string :token
+ t.integer :project_id, null: false
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20121120051432_add_service_id_to_web_hook.rb b/db/migrate/20121120051432_add_service_id_to_web_hook.rb
new file mode 100644
index 00000000000..77adf92578f
--- /dev/null
+++ b/db/migrate/20121120051432_add_service_id_to_web_hook.rb
@@ -0,0 +1,5 @@
+class AddServiceIdToWebHook < ActiveRecord::Migration
+ def change
+ add_column :web_hooks, :service_id, :integer, null: true
+ end
+end
diff --git a/spec/models/service_hook_spec.rb b/spec/models/service_hook_spec.rb
new file mode 100644
index 00000000000..25fc409646d
--- /dev/null
+++ b/spec/models/service_hook_spec.rb
@@ -0,0 +1,19 @@
+# == Schema Information
+#
+# Table name: web_hooks
+#
+# id :integer not null, primary key
+# url :string(255)
+# project_id :integer
+# created_at :datetime not null
+# updated_at :datetime not null
+# type :string(255) default("ProjectHook")
+#
+
+require "spec_helper"
+
+describe ServiceHook do
+ describe "Associations" do
+ it { should belong_to :service }
+ end
+end
diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb
new file mode 100644
index 00000000000..0329b9a94e3
--- /dev/null
+++ b/spec/models/service_spec.rb
@@ -0,0 +1,25 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# token :string(255)
+# project_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+require 'spec_helper'
+
+describe Service do
+ describe "Associations" do
+ it { should belong_to :project }
+ it { should have_one :service_hook }
+ end
+
+ describe "Mass assignment" do
+ it { should_not allow_mass_assignment_of(:project_id) }
+ end
+end