Commit 12640a498a255d9adf49a9479c2d07af5f2b2703
1 parent
5e0ed1f2
Exists in
master
and in
1 other branch
One issue tracker per app is enough.
Showing
5 changed files
with
24 additions
and
24 deletions
Show diff stats
app/controllers/apps_controller.rb
@@ -26,7 +26,7 @@ class AppsController < ApplicationController | @@ -26,7 +26,7 @@ class AppsController < ApplicationController | ||
26 | 26 | ||
27 | def edit | 27 | def edit |
28 | @app.watchers.build if @app.watchers.none? | 28 | @app.watchers.build if @app.watchers.none? |
29 | - @app.issue_trackers.build if @app.issue_trackers.none? | 29 | + @app.issue_tracker = IssueTracker.new if @app.issue_tracker.nil? |
30 | end | 30 | end |
31 | 31 | ||
32 | def create | 32 | def create |
app/models/app.rb
@@ -16,7 +16,7 @@ class App | @@ -16,7 +16,7 @@ class App | ||
16 | 16 | ||
17 | embeds_many :watchers | 17 | embeds_many :watchers |
18 | embeds_many :deploys | 18 | embeds_many :deploys |
19 | - embeds_many :issue_trackers | 19 | + embeds_one :issue_tracker |
20 | references_many :errs, :dependent => :destroy | 20 | references_many :errs, :dependent => :destroy |
21 | 21 | ||
22 | before_validation :generate_api_key, :on => :create | 22 | before_validation :generate_api_key, :on => :create |
@@ -25,11 +25,11 @@ class App | @@ -25,11 +25,11 @@ class App | ||
25 | validates_uniqueness_of :name, :allow_blank => true | 25 | validates_uniqueness_of :name, :allow_blank => true |
26 | validates_uniqueness_of :api_key, :allow_blank => true | 26 | validates_uniqueness_of :api_key, :allow_blank => true |
27 | validates_associated :watchers | 27 | validates_associated :watchers |
28 | - validate :check_issue_trackers | 28 | + validate :check_issue_tracker |
29 | 29 | ||
30 | accepts_nested_attributes_for :watchers, :allow_destroy => true, | 30 | accepts_nested_attributes_for :watchers, :allow_destroy => true, |
31 | :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } | 31 | :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } |
32 | - accepts_nested_attributes_for :issue_trackers, :allow_destroy => true, | 32 | + accepts_nested_attributes_for :issue_tracker, :allow_destroy => true, |
33 | :reject_if => proc { |attrs| !%w( lighthouseapp ).include?(attrs[:issue_tracker_type]) } | 33 | :reject_if => proc { |attrs| !%w( lighthouseapp ).include?(attrs[:issue_tracker_type]) } |
34 | 34 | ||
35 | # Mongoid Bug: find(id) on association proxies returns an Enumerator | 35 | # Mongoid Bug: find(id) on association proxies returns an Enumerator |
@@ -51,12 +51,12 @@ class App | @@ -51,12 +51,12 @@ class App | ||
51 | self.api_key ||= ActiveSupport::SecureRandom.hex | 51 | self.api_key ||= ActiveSupport::SecureRandom.hex |
52 | end | 52 | end |
53 | 53 | ||
54 | - def check_issue_trackers | ||
55 | - issue_trackers.map(&:valid?) | ||
56 | - issue_trackers.each do |tracker| | ||
57 | - tracker.errors.full_messages.each do |error| | 54 | + def check_issue_tracker |
55 | + if issue_tracker.present? | ||
56 | + issue_tracker.valid? | ||
57 | + issue_tracker.errors.full_messages.each do |error| | ||
58 | errors[:base] << error | 58 | errors[:base] << error |
59 | - end if tracker.errors | 59 | + end if issue_tracker.errors |
60 | end | 60 | end |
61 | end | 61 | end |
62 | end | 62 | end |
app/models/issue_tracker.rb
@@ -4,7 +4,7 @@ class IssueTracker | @@ -4,7 +4,7 @@ class IssueTracker | ||
4 | 4 | ||
5 | validate :check_lighthouseapp_params | 5 | validate :check_lighthouseapp_params |
6 | 6 | ||
7 | - embedded_in :app, :inverse_of => :issue_trackers | 7 | + embedded_in :app, :inverse_of => :issue_tracker |
8 | 8 | ||
9 | field :account, :type => String | 9 | field :account, :type => String |
10 | field :api_token, :type => String | 10 | field :api_token, :type => String |
app/views/apps/_fields.html.haml
@@ -23,8 +23,8 @@ | @@ -23,8 +23,8 @@ | ||
23 | = w.text_field :email | 23 | = w.text_field :email |
24 | 24 | ||
25 | %fieldset.nested-wrapper | 25 | %fieldset.nested-wrapper |
26 | - %legend Issue trackers | ||
27 | - = f.fields_for :issue_trackers do |w| | 26 | + %legend Issue tracker |
27 | + = f.fields_for :issue_tracker do |w| | ||
28 | %div.watcher.nested | 28 | %div.watcher.nested |
29 | %div.choose | 29 | %div.choose |
30 | = w.radio_button :issue_tracker_type, :lighthouseapp | 30 | = w.radio_button :issue_tracker_type, :lighthouseapp |
spec/controllers/apps_controller_spec.rb
@@ -179,25 +179,25 @@ describe AppsController do | @@ -179,25 +179,25 @@ describe AppsController do | ||
179 | context "setting up issue tracker", :cur => true do | 179 | context "setting up issue tracker", :cur => true do |
180 | context "unknown tracker type" do | 180 | context "unknown tracker type" do |
181 | before(:each) do | 181 | before(:each) do |
182 | - put :update, :id => @app.id, :app => { :issue_trackers_attributes => { '0' => { | 182 | + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { |
183 | :issue_tracker_type => 'unknown', :project_id => '1234', :api_token => '123123', :account => 'myapp' | 183 | :issue_tracker_type => 'unknown', :project_id => '1234', :api_token => '123123', :account => 'myapp' |
184 | - } } } | 184 | + } } |
185 | @app.reload | 185 | @app.reload |
186 | end | 186 | end |
187 | 187 | ||
188 | it "should not create issue tracker" do | 188 | it "should not create issue tracker" do |
189 | - @app.issue_trackers.should be_empty | 189 | + @app.issue_tracker.should be_nil |
190 | end | 190 | end |
191 | end | 191 | end |
192 | 192 | ||
193 | context "lighthouseapp" do | 193 | context "lighthouseapp" do |
194 | it "should save tracker params" do | 194 | it "should save tracker params" do |
195 | - put :update, :id => @app.id, :app => { :issue_trackers_attributes => { '0' => { | 195 | + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { |
196 | :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123', :account => 'myapp' | 196 | :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123', :account => 'myapp' |
197 | - } } } | 197 | + } } |
198 | @app.reload | 198 | @app.reload |
199 | 199 | ||
200 | - tracker = @app.issue_trackers.first | 200 | + tracker = @app.issue_tracker |
201 | tracker.issue_tracker_type.should == 'lighthouseapp' | 201 | tracker.issue_tracker_type.should == 'lighthouseapp' |
202 | tracker.project_id.should == '1234' | 202 | tracker.project_id.should == '1234' |
203 | tracker.api_token.should == '123123' | 203 | tracker.api_token.should == '123123' |
@@ -205,22 +205,22 @@ describe AppsController do | @@ -205,22 +205,22 @@ describe AppsController do | ||
205 | end | 205 | end |
206 | 206 | ||
207 | it "should show validation notice when sufficient params are not present" do | 207 | it "should show validation notice when sufficient params are not present" do |
208 | - put :update, :id => @app.id, :app => { :issue_trackers_attributes => { '0' => { | 208 | + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { |
209 | :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123' | 209 | :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123' |
210 | - } } } | 210 | + } } |
211 | @app.reload | 211 | @app.reload |
212 | 212 | ||
213 | - @app.issue_trackers.should be_empty | 213 | + @app.issue_tracker.should be_nil |
214 | response.body.should match(/You must specify your Lighthouseapp account, token and project id/) | 214 | response.body.should match(/You must specify your Lighthouseapp account, token and project id/) |
215 | end | 215 | end |
216 | 216 | ||
217 | it "should show validation notice when sufficient params are not present" do | 217 | it "should show validation notice when sufficient params are not present" do |
218 | - put :update, :id => @app.id, :app => { :issue_trackers_attributes => { '0' => { | 218 | + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { |
219 | :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123' | 219 | :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123' |
220 | - } } } | 220 | + } } |
221 | @app.reload | 221 | @app.reload |
222 | 222 | ||
223 | - @app.issue_trackers.should be_empty | 223 | + @app.issue_tracker.should be_nil |
224 | response.body.should match(/You must specify your Lighthouseapp account, token and project id/) | 224 | response.body.should match(/You must specify your Lighthouseapp account, token and project id/) |
225 | end | 225 | end |
226 | end | 226 | end |