forked from westarete/karma-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.txt
248 lines (233 loc) · 7.01 KB
/
diff.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
diff --git a/app/controllers/websites_controller.rb b/app/controllers/websites_controller.rb
index 7e6bb72..3dabbf2 100644
--- a/app/controllers/websites_controller.rb
+++ b/app/controllers/websites_controller.rb
@@ -25,6 +25,7 @@ class WebsitesController < ApplicationController
def edit
@website = Website.find(params[:id])
+ @admins = Admin.all
end
def update
diff --git a/app/models/admin.rb b/app/models/admin.rb
index d2d3d99..8f24959 100644
--- a/app/models/admin.rb
+++ b/app/models/admin.rb
@@ -1,5 +1,8 @@
class Admin < ActiveRecord::Base
+
+ has_many :websites, :through => :admins_websites
validates_presence_of :name, :message => "can't be blank"
+
end
diff --git a/app/models/admins_websites.rb b/app/models/admins_websites.rb
new file mode 100644
index 0000000..654b293
--- /dev/null
+++ b/app/models/admins_websites.rb
@@ -0,0 +1,16 @@
+class AdminsWebsites < ActiveRecord::Base
+ belongs_to :admin
+ belongs_to :website
+end
+
+# == Schema Information
+#
+# Table name: admins_websites
+#
+# id :integer not null, primary key
+# admin_id :integer not null
+# website_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+#
+
diff --git a/app/models/website.rb b/app/models/website.rb
index 5669a8d..73dfe3c 100644
--- a/app/models/website.rb
+++ b/app/models/website.rb
@@ -1,9 +1,13 @@
class Website < ActiveRecord::Base
+ has_many :admins, :through => :admins_websites
validates_presence_of :name, :url
validates_format_of :url,
:with => /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix,
:message => "needs to be a well-formed URL with protocol, eg. http://www.google.com"
validates_uniqueness_of :url
+
+ accepts_nested_attributes_for :admins
+
end
# == Schema Information
diff --git a/app/views/admins/show.html.haml b/app/views/admins/show.html.haml
index 818c850..f5fa21f 100644
--- a/app/views/admins/show.html.haml
+++ b/app/views/admins/show.html.haml
@@ -1,4 +1,12 @@
= render :partial => "/shared/header", :locals => { :title => @admin.name, :subtitle => "", :flash => flash }
+- if @admin.websites.blank?
+ %h3== #{@admin.name} is not administering any websites
+- else
+ %h3 Websites this Admin can administor
+ %ul
+ %li MOCK 1
+ %li MOCK 2
+
.button_row
= link_to "Edit #{@admin.name}", edit_admin_path(@admin), :class => "button"
\ No newline at end of file
diff --git a/app/views/websites/_form.html.haml b/app/views/websites/_form.html.haml
index 9618ab0..bbc9056 100644
--- a/app/views/websites/_form.html.haml
+++ b/app/views/websites/_form.html.haml
@@ -6,4 +6,11 @@
%p
= f.label :url, "URL"
%br
- = f.text_field :url
\ No newline at end of file
+ = f.text_field :url
+
+- f.fields_for :admin do |a|
+ %p
+ %label Admins with access
+ %ul
+ - for admin in @admins
+ %li= admin.name
\ No newline at end of file
diff --git a/db/migrate/20100308214229_create_admins_websites.rb b/db/migrate/20100308214229_create_admins_websites.rb
new file mode 100644
index 0000000..00cd77a
--- /dev/null
+++ b/db/migrate/20100308214229_create_admins_websites.rb
@@ -0,0 +1,13 @@
+class CreateAdminsWebsites < ActiveRecord::Migration
+ def self.up
+ create_table :admins_websites do |t|
+ t.integer :admin_id, :null => false
+ t.integer :website_id, :null => false
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :admins_websites
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 7674eec..0ebedc3 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100304154635) do
+ActiveRecord::Schema.define(:version => 20100308214229) do
create_table "adjustments", :force => true do |t|
t.integer "user_id", :null => false
@@ -27,6 +27,13 @@ ActiveRecord::Schema.define(:version => 20100304154635) do
add_index "admins", ["name"], :name => "index_admins_on_name"
+ create_table "admins_websites", :force => true do |t|
+ t.integer "admin_id", :null => false
+ t.integer "website_id", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "buckets", :force => true do |t|
t.string "permalink"
t.datetime "created_at"
diff --git a/spec/blueprints.rb b/spec/blueprints.rb
index 01d7730..6a79d63 100644
--- a/spec/blueprints.rb
+++ b/spec/blueprints.rb
@@ -39,4 +39,9 @@ Client.blueprint do
hostname { Faker::Internet.domain_name }
ip_address { (1..4).collect { rand(255) }.join('.') }
api_key { ActiveSupport::SecureRandom.hex(16) }
+end
+
+AdminsWebsites.blueprint do
+ admin
+ website
end
\ No newline at end of file
diff --git a/spec/fixtures/admins_websites.yml b/spec/fixtures/admins_websites.yml
new file mode 100644
index 0000000..26db362
--- /dev/null
+++ b/spec/fixtures/admins_websites.yml
@@ -0,0 +1,19 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
+
+# == Schema Information
+#
+# Table name: admins_websites
+#
+# id :integer not null, primary key
+# admin_id :integer not null
+# website_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+#
+
diff --git a/spec/models/administrator_spec.rb b/spec/models/administrator_spec.rb
index 76e68d5..9febf90 100644
--- a/spec/models/administrator_spec.rb
+++ b/spec/models/administrator_spec.rb
@@ -1,8 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Admin do
-
- it { should validate_presence_of(:name) }
+
+ it { should have_and_belong_to_many(:websites) }
+ it { should validate_presence_of(:name) }
end
diff --git a/spec/models/admins_websites_spec.rb b/spec/models/admins_websites_spec.rb
new file mode 100644
index 0000000..a69c354
--- /dev/null
+++ b/spec/models/admins_websites_spec.rb
@@ -0,0 +1,20 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe AdminsWebsites do
+
+ it { should belong_to(:website) }
+ it { should belong_to(:admin) }
+
+end
+
+# == Schema Information
+#
+# Table name: admins_websites
+#
+# id :integer not null, primary key
+# admin_id :integer not null
+# website_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+#
+
diff --git a/spec/models/website_spec.rb b/spec/models/website_spec.rb
index f6e2a08..996cd0e 100644
--- a/spec/models/website_spec.rb
+++ b/spec/models/website_spec.rb
@@ -8,9 +8,10 @@ describe Website do
Website.make
end
- it { should validate_presence_of(:name) }
- it { should validate_presence_of(:url) }
- it { should validate_uniqueness_of(:url) }
+ it { should_have_and_belong_to_many(:admins) }
+ it { should validate_presence_of(:name) }
+ it { should validate_presence_of(:url) }
+ it { should validate_uniqueness_of(:url) }
describe "#url" do
it "should be valid when url is well-formed" do