Commit c7507da105837bb5177d9fd54ddae5e43b19b600

Authored by Cyril Mougel
1 parent d8b03d4d
Exists in master and in 1 other branch production

Refactoring of AppsController

 * Stop using inherited_resources and only decent_exposure
 * Use decent_exposure when it's possible
 * Extract some translation
@@ -11,7 +11,6 @@ gem 'htmlentities' @@ -11,7 +11,6 @@ gem 'htmlentities'
11 gem 'rack-ssl', :require => 'rack/ssl' # force SSL 11 gem 'rack-ssl', :require => 'rack/ssl' # force SSL
12 12
13 gem 'useragent' 13 gem 'useragent'
14 -gem 'inherited_resources'  
15 gem 'decent_exposure' 14 gem 'decent_exposure'
16 gem 'strong_parameters' 15 gem 'strong_parameters'
17 gem 'SystemTimer', :platform => :ruby_18 16 gem 'SystemTimer', :platform => :ruby_18
@@ -123,6 +123,7 @@ GEM @@ -123,6 +123,7 @@ GEM
123 multipart-post (~> 1.1) 123 multipart-post (~> 1.1)
124 faraday_middleware (0.8.8) 124 faraday_middleware (0.8.8)
125 faraday (>= 0.7.4, < 0.9) 125 faraday (>= 0.7.4, < 0.9)
  126 + ffi (1.9.0)
126 flowdock (0.3.1) 127 flowdock (0.3.1)
127 httparty (~> 0.7) 128 httparty (~> 0.7)
128 multi_json 129 multi_json
@@ -133,7 +134,6 @@ GEM @@ -133,7 +134,6 @@ GEM
133 tilt 134 tilt
134 happymapper (0.4.0) 135 happymapper (0.4.0)
135 libxml-ruby (~> 2.0) 136 libxml-ruby (~> 2.0)
136 - has_scope (0.5.1)  
137 hashie (1.2.0) 137 hashie (1.2.0)
138 highline (1.6.19) 138 highline (1.6.19)
139 hike (1.2.3) 139 hike (1.2.3)
@@ -151,9 +151,6 @@ GEM @@ -151,9 +151,6 @@ GEM
151 multi_xml (>= 0.5.2) 151 multi_xml (>= 0.5.2)
152 httpauth (0.2.0) 152 httpauth (0.2.0)
153 i18n (0.6.1) 153 i18n (0.6.1)
154 - inherited_resources (1.4.0)  
155 - has_scope (~> 0.5.0)  
156 - responders (~> 0.9)  
157 journey (1.0.4) 154 journey (1.0.4)
158 jquery-rails (2.1.4) 155 jquery-rails (2.1.4)
159 railties (>= 3.0, < 5.0) 156 railties (>= 3.0, < 5.0)
@@ -288,8 +285,6 @@ GEM @@ -288,8 +285,6 @@ GEM
288 rdoc (3.12.2) 285 rdoc (3.12.2)
289 json (~> 1.4) 286 json (~> 1.4)
290 ref (1.0.5) 287 ref (1.0.5)
291 - responders (0.9.3)  
292 - railties (~> 3.1)  
293 rest-client (1.6.7) 288 rest-client (1.6.7)
294 mime-types (>= 1.16) 289 mime-types (>= 1.16)
295 ri_cal (0.8.8) 290 ri_cal (0.8.8)
@@ -412,7 +407,6 @@ DEPENDENCIES @@ -412,7 +407,6 @@ DEPENDENCIES
412 hoptoad_notifier (~> 2.4) 407 hoptoad_notifier (~> 2.4)
413 htmlentities 408 htmlentities
414 httparty 409 httparty
415 - inherited_resources  
416 jquery-rails (~> 2.1.4) 410 jquery-rails (~> 2.1.4)
417 kaminari (>= 0.14.1) 411 kaminari (>= 0.14.1)
418 launchy 412 launchy
app/controllers/apps_controller.rb
1 -class AppsController < InheritedResources::Base 1 +class AppsController < ApplicationController
2 2
3 include ProblemsSearcher 3 include ProblemsSearcher
4 4
@@ -7,57 +7,86 @@ class AppsController &lt; InheritedResources::Base @@ -7,57 +7,86 @@ class AppsController &lt; InheritedResources::Base
7 before_filter :parse_notice_at_notices_or_set_default, :only => [:create, :update] 7 before_filter :parse_notice_at_notices_or_set_default, :only => [:create, :update]
8 respond_to :html 8 respond_to :html
9 9
10 - def show  
11 - respond_to do |format|  
12 - format.html do  
13 - @all_errs = !!params[:all_errs] 10 + expose(:app_scope) {
  11 + (current_user.admin? ? App : current_user.apps)
  12 + }
  13 +
  14 + expose(:apps) {
  15 + app_scope.all.sort
  16 + }
  17 +
  18 + expose(:app, :ancestor => :app_scope)
  19 +
  20 + expose(:all_errs) {
  21 + !!params[:all_errs]
  22 + }
  23 + expose(:problems) {
  24 + if request.format == :atom
  25 + app.problems.unresolved.ordered
  26 + else
  27 + pr = app.problems
  28 + pr = pr.unresolved unless all_errs
  29 + pr.in_env(
  30 + params[:environment]
  31 + ).ordered_by(params_sort, params_order).page(params[:page]).per(current_user.per_page)
  32 + end
  33 + }
14 34
15 - @problems = resource.problems  
16 - @problems = @problems.unresolved unless @all_errs  
17 - @problems = @problems.in_env(params[:environment]).ordered_by(params_sort, params_order).page(params[:page]).per(current_user.per_page) 35 + expose(:deploys) {
  36 + app.deploys.order_by(:created_at.desc).limit(5)
  37 + }
18 38
19 - @deploys = @app.deploys.order_by(:created_at.desc).limit(5)  
20 - end  
21 - format.atom do  
22 - @problems = resource.problems.unresolved.ordered  
23 - end  
24 - end 39 + def index; end
  40 + def show
  41 + app
  42 + end
  43 +
  44 + def new
  45 + plug_params(app)
25 end 46 end
26 47
27 def create 48 def create
28 - @app = App.new(params[:app])  
29 initialize_subclassed_issue_tracker 49 initialize_subclassed_issue_tracker
30 initialize_subclassed_notification_service 50 initialize_subclassed_notification_service
31 - create! 51 + if app.save
  52 + redirect_to app_url(app), :flash => { :success => I18n.t('controllers.apps.flash.create.success') }
  53 + else
  54 + flash[:error] = I18n.t('controllers.apps.flash.create.error')
  55 + render :new
  56 + end
32 end 57 end
33 58
34 def update 59 def update
35 - @app = resource  
36 initialize_subclassed_issue_tracker 60 initialize_subclassed_issue_tracker
37 initialize_subclassed_notification_service 61 initialize_subclassed_notification_service
38 - update! 62 + if app.save
  63 + redirect_to app_url(app), :flash => { :success => I18n.t('controllers.apps.flash.update.success') }
  64 + else
  65 + flash[:error] = I18n.t('controllers.apps.flash.update.error')
  66 + render :edit
  67 + end
39 end 68 end
40 69
41 - def new  
42 - plug_params(build_resource)  
43 - new! 70 + def edit
  71 + plug_params(app)
44 end 72 end
45 73
46 - def edit  
47 - plug_params(resource)  
48 - edit! 74 + def destroy
  75 + if app.destroy
  76 + redirect_to apps_url, :flash => { :success => I18n.t('controllers.apps.flash.destroy.success') }
  77 + else
  78 + flash[:error] = I18n.t('controllers.apps.flash.destroy.error')
  79 + render :show
  80 + end
49 end 81 end
50 82
51 protected 83 protected
52 - def collection  
53 - @apps ||= end_of_association_chain.all.sort  
54 - end  
55 84
56 def initialize_subclassed_issue_tracker 85 def initialize_subclassed_issue_tracker
57 # set the app's issue tracker 86 # set the app's issue tracker
58 if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type] 87 if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type]
59 if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type) 88 if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type)
60 - @app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes]) 89 + app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes])
61 end 90 end
62 end 91 end
63 end 92 end
@@ -66,21 +95,11 @@ class AppsController &lt; InheritedResources::Base @@ -66,21 +95,11 @@ class AppsController &lt; InheritedResources::Base
66 # set the app's notification service 95 # set the app's notification service
67 if params[:app][:notification_service_attributes] && notification_type = params[:app][:notification_service_attributes][:type] 96 if params[:app][:notification_service_attributes] && notification_type = params[:app][:notification_service_attributes][:type]
68 if NotificationService.subclasses.map(&:name).concat(["NotificationService"]).include?(notification_type) 97 if NotificationService.subclasses.map(&:name).concat(["NotificationService"]).include?(notification_type)
69 - @app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes]) 98 + app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes])
70 end 99 end
71 end 100 end
72 end 101 end
73 102
74 - def begin_of_association_chain  
75 - # Filter the @apps collection to apps watched by the current user, unless user is an admin.  
76 - # If user is an admin, then no filter is applied, and all apps are shown.  
77 - current_user unless current_user.admin?  
78 - end  
79 -  
80 - def interpolation_options  
81 - {:app_name => resource.name}  
82 - end  
83 -  
84 def plug_params app 103 def plug_params app
85 app.watchers.build if app.watchers.none? 104 app.watchers.build if app.watchers.none?
86 app.issue_tracker = IssueTracker.new unless app.issue_tracker_configured? 105 app.issue_tracker = IssueTracker.new unless app.issue_tracker_configured?
app/controllers/problems_searcher.rb
@@ -29,5 +29,6 @@ module ProblemsSearcher @@ -29,5 +29,6 @@ module ProblemsSearcher
29 expose(:err_ids) { 29 expose(:err_ids) {
30 (params[:problems] || []).compact 30 (params[:problems] || []).compact
31 } 31 }
  32 +
32 end 33 end
33 end 34 end
app/helpers/apps_helper.rb
@@ -41,7 +41,7 @@ module AppsHelper @@ -41,7 +41,7 @@ module AppsHelper
41 def detect_any_apps_with_attributes 41 def detect_any_apps_with_attributes
42 @any_github_repos = @any_issue_trackers = @any_deploys = @any_bitbucket_repos = @any_notification_services = false 42 @any_github_repos = @any_issue_trackers = @any_deploys = @any_bitbucket_repos = @any_notification_services = false
43 43
44 - @apps.each do |app| 44 + apps.each do |app|
45 @any_github_repos ||= app.github_repo? 45 @any_github_repos ||= app.github_repo?
46 @any_bitbucket_repos ||= app.bitbucket_repo? 46 @any_bitbucket_repos ||= app.bitbucket_repo?
47 @any_issue_trackers ||= app.issue_tracker_configured? 47 @any_issue_trackers ||= app.issue_tracker_configured?
app/views/apps/_fields.html.haml
1 -= errors_for @app 1 += errors_for app
2 2
3 %div.required 3 %div.required
4 = f.label :name 4 = f.label :name
app/views/apps/edit.html.haml
1 - content_for :title, 'Edit App' 1 - content_for :title, 'Edit App'
2 - content_for :action_bar do 2 - content_for :action_bar do
3 = link_to_copy_attributes_from_other_app 3 = link_to_copy_attributes_from_other_app
4 - = link_to 'destroy application', app_path(@app), :method => :delete, :data => { :confirm => 'Seriously?' }, :class => 'button'  
5 - = link_to('cancel', app_path(@app), :class => 'button') 4 + = link_to 'destroy application', app_path(app), :method => :delete, :data => { :confirm => 'Seriously?' }, :class => 'button'
  5 + = link_to('cancel', app_path(app), :class => 'button')
6 6
7 -= form_for @app do |f| 7 += form_for app do |f|
8 8
9 = render 'fields', :f => f 9 = render 'fields', :f => f
10 10
app/views/apps/index.html.haml
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 %th Last Deploy 16 %th Last Deploy
17 %th Errors 17 %th Errors
18 %tbody 18 %tbody
19 - - @apps.each do |app| 19 + - apps.each do |app|
20 %tr 20 %tr
21 %td.name= link_to app.name, app_path(app) 21 %td.name= link_to app.name, app_path(app)
22 - if any_github_repos? or any_bitbucket_repos? 22 - if any_github_repos? or any_bitbucket_repos?
@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 - if app.problem_count > 0 50 - if app.problem_count > 0
51 - unresolved = app.unresolved_count 51 - unresolved = app.unresolved_count
52 = link_to unresolved, app_path(app), :class => (unresolved == 0 ? "resolved" : nil) 52 = link_to unresolved, app_path(app), :class => (unresolved == 0 ? "resolved" : nil)
53 - - if @apps.none? 53 + - if apps.none?
54 %tr 54 %tr
55 %td{:colspan => 3} 55 %td{:colspan => 3}
56 %em 56 %em
app/views/apps/new.html.haml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 = link_to_copy_attributes_from_other_app 3 = link_to_copy_attributes_from_other_app
4 = link_to('cancel', apps_path, :class => 'button') 4 = link_to('cancel', apps_path, :class => 'button')
5 5
6 -= form_for @app do |f| 6 += form_for app do |f|
7 7
8 = render 'fields', :f => f 8 = render 'fields', :f => f
9 9
app/views/apps/show.atom.builder
1 atom_feed do |feed| 1 atom_feed do |feed|
2 - feed.title("Errbit notices for #{h @app.name} at #{root_url}") 2 + feed.title("Errbit notices for #{h app.name} at #{root_url}")
3 render "problems/list", :feed => feed 3 render "problems/list", :feed => feed
4 end 4 end
app/views/apps/show.html.haml
1 -- content_for :title, @app.name 1 +- content_for :title, app.name
2 - content_for :head do 2 - content_for :head do
3 - = auto_discovery_link_tag :atom, app_path(@app, User.token_authentication_key => current_user.authentication_token, :format => "atom"), :title => "Errbit notices for #{@app.name} at #{request.host}" 3 + = auto_discovery_link_tag :atom, app_path(app, User.token_authentication_key => current_user.authentication_token, :format => "atom"), :title => "Errbit notices for #{app.name} at #{request.host}"
4 - content_for :meta do 4 - content_for :meta do
5 %strong Errors Caught: 5 %strong Errors Caught:
6 - = @app.problems.count 6 + = app.problems.count
7 %strong Deploy Count: 7 %strong Deploy Count:
8 - = @app.deploys.count 8 + = app.deploys.count
9 %strong API Key: 9 %strong API Key:
10 - = @app.api_key 10 + = app.api_key
11 - content_for :action_bar do 11 - content_for :action_bar do
12 - if current_user.admin? 12 - if current_user.admin?
13 - = link_to 'edit', edit_app_path(@app), :class => 'button'  
14 - - if @all_errs  
15 - = link_to 'unresolved errs', app_path(@app), :class => 'button' 13 + = link_to 'edit', edit_app_path(app), :class => 'button'
  14 + - if all_errs
  15 + = link_to 'unresolved errs', app_path(app), :class => 'button'
16 - else 16 - else
17 - = link_to 'all errs', app_path(@app, :all_errs => true), :class => 'button' 17 + = link_to 'all errs', app_path(app, :all_errs => true), :class => 'button'
18 18
19 %h3#watchers_toggle 19 %h3#watchers_toggle
20 Watchers 20 Watchers
21 %span.click_span (show/hide) 21 %span.click_span (show/hide)
22 #watchers_div 22 #watchers_div
23 - - if @app.notify_all_users 23 + - if app.notify_all_users
24 %table.watchers 24 %table.watchers
25 %thead 25 %thead
26 %tr 26 %tr
@@ -31,15 +31,15 @@ @@ -31,15 +31,15 @@
31 %tr 31 %tr
32 %th User or Email 32 %th User or Email
33 %tbody 33 %tbody
34 - - @app.watchers.each do |watcher| 34 + - app.watchers.each do |watcher|
35 %tr 35 %tr
36 %td= watcher.label 36 %td= watcher.label
37 - - if @app.watchers.none? 37 + - if app.watchers.none?
38 %tr 38 %tr
39 %td 39 %td
40 %em Sadly, no one is watching this app 40 %em Sadly, no one is watching this app
41 41
42 -- if @app.github_repo? 42 +- if app.github_repo?
43 %h3#repository_toggle 43 %h3#repository_toggle
44 Repository 44 Repository
45 %span.click_span (show/hide) 45 %span.click_span (show/hide)
@@ -50,13 +50,13 @@ @@ -50,13 +50,13 @@
50 %th GitHub Repo 50 %th GitHub Repo
51 %tbody 51 %tbody
52 %tr 52 %tr
53 - %td= link_to(@app.github_repo, @app.github_url, :target => '_blank') 53 + %td= link_to(app.github_repo, app.github_url, :target => '_blank')
54 54
55 %h3#deploys_toggle 55 %h3#deploys_toggle
56 Latest Deploys 56 Latest Deploys
57 %span.click_span (show/hide) 57 %span.click_span (show/hide)
58 #deploys_div 58 #deploys_div
59 - - if @deploys.any? 59 + - if deploys.any?
60 %table.deploys 60 %table.deploys
61 %thead 61 %thead
62 %tr 62 %tr
@@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
68 %th Revision 68 %th Revision
69 69
70 %tbody 70 %tbody
71 - - @deploys.each do |deploy| 71 + - deploys.each do |deploy|
72 %tr 72 %tr
73 %td.when #{deploy.created_at.to_s(:micro)} 73 %td.when #{deploy.created_at.to_s(:micro)}
74 %td.environment #{deploy.environment} 74 %td.environment #{deploy.environment}
@@ -76,20 +76,20 @@ @@ -76,20 +76,20 @@
76 %td.message #{deploy.message} 76 %td.message #{deploy.message}
77 %td.repository #{deploy.repository} 77 %td.repository #{deploy.repository}
78 %td.revision #{deploy.short_revision} 78 %td.revision #{deploy.short_revision}
79 - = link_to "All Deploys (#{@app.deploys.count})", app_deploys_path(@app), :class => 'button' 79 + = link_to "All Deploys (#{app.deploys.count})", app_deploys_path(app), :class => 'button'
80 - else 80 - else
81 %h3 No deploys 81 %h3 No deploys
82 82
83 -- if @app.problems.any? 83 +- if app.problems.any?
84 %h3.clear Errors 84 %h3.clear Errors
85 %section 85 %section
86 - = form_tag search_problems_path(:all_errs => @all_errs, :app_id => @app.id), :method => :get, :remote => true do 86 + = form_tag search_problems_path(:all_errs => all_errs, :app_id => app.id), :method => :get, :remote => true do
87 = text_field_tag :search, params[:search], :placeholder => 'Search for issues' 87 = text_field_tag :search, params[:search], :placeholder => 'Search for issues'
88 %br 88 %br
89 %section 89 %section
90 .problem_table{:id => 'problem_table'} 90 .problem_table{:id => 'problem_table'}
91 - = render 'problems/table', :problems => @problems 91 + = render 'problems/table', :problems => problems
92 - else 92 - else
93 %h3.clear No errs have been caught yet, make sure you setup your app 93 %h3.clear No errs have been caught yet, make sure you setup your app
94 - = render 'configuration_instructions', :app => @app 94 + = render 'configuration_instructions', :app => app
95 95
app/views/problems/_list.atom.builder
1 -feed.updated(@problems.first.try(:created_at) || Time.now) 1 +feed.updated(problems.first.try(:created_at) || Time.now)
2 2
3 -for problem in @problems 3 +for problem in problems
4 notice = problem.notices.first 4 notice = problem.notices.first
5 5
6 feed.entry(problem, :url => app_problem_url(problem.app.to_param, problem.to_param)) do |entry| 6 feed.entry(problem, :url => app_problem_url(problem.app.to_param, problem.to_param)) do |entry|
config/initializers/inherited_resources.rb
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -InheritedResources.flash_keys = [:success, :error]  
2 -  
config/locales/en.yml
@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. 2 # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 3
4 en: 4 en:
5 -  
6 flash: 5 flash:
7 apps: 6 apps:
8 create: 7 create:
@@ -32,6 +31,18 @@ en: @@ -32,6 +31,18 @@ en:
32 edit_profile: 'Edit profile' 31 edit_profile: 'Edit profile'
33 32
34 controllers: 33 controllers:
  34 + apps:
  35 + flash:
  36 + create:
  37 + success: "Your app was successfully created."
  38 + error: "You app was successfully destroyed."
  39 + update:
  40 + success: "You app was successfully updated."
  41 + error: "You app was not updated"
  42 + destroy:
  43 + success: "You app was successfully destroyed."
  44 + error: "You app could not be destroyed."
  45 +
35 users: 46 users:
36 flash: 47 flash:
37 destroy: 48 destroy:
@@ -46,6 +57,7 @@ en: @@ -46,6 +57,7 @@ en:
46 merge_several: 57 merge_several:
47 success: "%{nb} errors have been merged." 58 success: "%{nb} errors have been merged."
48 59
  60 +
49 devise: 61 devise:
50 registrations: 62 registrations:
51 signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' 63 signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
spec/controllers/apps_controller_spec.rb
@@ -6,15 +6,13 @@ describe AppsController do @@ -6,15 +6,13 @@ describe AppsController do
6 it_requires_authentication 6 it_requires_authentication
7 it_requires_admin_privileges :for => {:new => :get, :edit => :get, :create => :post, :update => :put, :destroy => :delete} 7 it_requires_admin_privileges :for => {:new => :get, :edit => :get, :create => :post, :update => :put, :destroy => :delete}
8 8
9 -  
10 describe "GET /apps" do 9 describe "GET /apps" do
11 context 'when logged in as an admin' do 10 context 'when logged in as an admin' do
12 it 'finds all apps' do 11 it 'finds all apps' do
13 sign_in Fabricate(:admin) 12 sign_in Fabricate(:admin)
14 3.times { Fabricate(:app) } 13 3.times { Fabricate(:app) }
15 - apps = App.all  
16 get :index 14 get :index
17 - assigns(:apps).should == apps 15 + controller.apps.should == App.all.sort.entries
18 end 16 end
19 end 17 end
20 18
@@ -27,8 +25,8 @@ describe AppsController do @@ -27,8 +25,8 @@ describe AppsController do
27 Fabricate(:user_watcher, :user => user, :app => watched_app1) 25 Fabricate(:user_watcher, :user => user, :app => watched_app1)
28 Fabricate(:user_watcher, :user => user, :app => watched_app2) 26 Fabricate(:user_watcher, :user => user, :app => watched_app2)
29 get :index 27 get :index
30 - assigns(:apps).should include(watched_app1, watched_app2)  
31 - assigns(:apps).should_not include(unwatched_app) 28 + controller.apps.should include(watched_app1, watched_app2)
  29 + controller.apps.should_not include(unwatched_app)
32 end 30 end
33 end 31 end
34 end 32 end
@@ -44,7 +42,7 @@ describe AppsController do @@ -44,7 +42,7 @@ describe AppsController do
44 42
45 it 'finds the app' do 43 it 'finds the app' do
46 get :show, :id => @app.id 44 get :show, :id => @app.id
47 - assigns(:app).should == @app 45 + controller.app.should == @app
48 end 46 end
49 47
50 it "should not raise errors for app with err without notices" do 48 it "should not raise errors for app with err without notices" do
@@ -65,13 +63,13 @@ describe AppsController do @@ -65,13 +63,13 @@ describe AppsController do
65 63
66 it "should have default per_page value for user" do 64 it "should have default per_page value for user" do
67 get :show, :id => @app.id 65 get :show, :id => @app.id
68 - assigns(:problems).to_a.size.should == User::PER_PAGE 66 + controller.problems.to_a.size.should == User::PER_PAGE
69 end 67 end
70 68
71 it "should be able to override default per_page value" do 69 it "should be able to override default per_page value" do
72 @user.update_attribute :per_page, 10 70 @user.update_attribute :per_page, 10
73 get :show, :id => @app.id 71 get :show, :id => @app.id
74 - assigns(:problems).to_a.size.should == 10 72 + controller.problems.to_a.size.should == 10
75 end 73 end
76 end 74 end
77 75
@@ -85,14 +83,14 @@ describe AppsController do @@ -85,14 +83,14 @@ describe AppsController do
85 context 'and no params' do 83 context 'and no params' do
86 it 'shows only unresolved problems' do 84 it 'shows only unresolved problems' do
87 get :show, :id => @app.id 85 get :show, :id => @app.id
88 - assigns(:problems).size.should == 1 86 + controller.problems.size.should == 1
89 end 87 end
90 end 88 end
91 89
92 context 'and all_problems=true params' do 90 context 'and all_problems=true params' do
93 it 'shows all errors' do 91 it 'shows all errors' do
94 get :show, :id => @app.id, :all_errs => true 92 get :show, :id => @app.id, :all_errs => true
95 - assigns(:problems).size.should == 2 93 + controller.problems.size.should == 2
96 end 94 end
97 end 95 end
98 end 96 end
@@ -108,35 +106,35 @@ describe AppsController do @@ -108,35 +106,35 @@ describe AppsController do
108 context 'no params' do 106 context 'no params' do
109 it 'shows errs for all environments' do 107 it 'shows errs for all environments' do
110 get :show, :id => @app.id 108 get :show, :id => @app.id
111 - assigns(:problems).size.should == 21 109 + controller.problems.size.should == 21
112 end 110 end
113 end 111 end
114 112
115 context 'environment production' do 113 context 'environment production' do
116 it 'shows errs for just production' do 114 it 'shows errs for just production' do
117 get :show, :id => @app.id, :environment => 'production' 115 get :show, :id => @app.id, :environment => 'production'
118 - assigns(:problems).size.should == 6 116 + controller.problems.size.should == 6
119 end 117 end
120 end 118 end
121 119
122 context 'environment staging' do 120 context 'environment staging' do
123 it 'shows errs for just staging' do 121 it 'shows errs for just staging' do
124 get :show, :id => @app.id, :environment => 'staging' 122 get :show, :id => @app.id, :environment => 'staging'
125 - assigns(:problems).size.should == 5 123 + controller.problems.size.should == 5
126 end 124 end
127 end 125 end
128 126
129 context 'environment development' do 127 context 'environment development' do
130 it 'shows errs for just development' do 128 it 'shows errs for just development' do
131 get :show, :id => @app.id, :environment => 'development' 129 get :show, :id => @app.id, :environment => 'development'
132 - assigns(:problems).size.should == 5 130 + controller.problems.size.should == 5
133 end 131 end
134 end 132 end
135 133
136 context 'environment test' do 134 context 'environment test' do
137 it 'shows errs for just test' do 135 it 'shows errs for just test' do
138 get :show, :id => @app.id, :environment => 'test' 136 get :show, :id => @app.id, :environment => 'test'
139 - assigns(:problems).size.should == 5 137 + controller.problems.size.should == 5
140 end 138 end
141 end 139 end
142 end 140 end
@@ -149,7 +147,7 @@ describe AppsController do @@ -149,7 +147,7 @@ describe AppsController do
149 watcher = Fabricate(:user_watcher, :app => app, :user => user) 147 watcher = Fabricate(:user_watcher, :app => app, :user => user)
150 sign_in user 148 sign_in user
151 get :show, :id => app.id 149 get :show, :id => app.id
152 - assigns(:app).should == app 150 + controller.app.should == app
153 end 151 end
154 152
155 it 'does not find the app if the user is not watching it' do 153 it 'does not find the app if the user is not watching it' do
@@ -170,19 +168,19 @@ describe AppsController do @@ -170,19 +168,19 @@ describe AppsController do
170 describe "GET /apps/new" do 168 describe "GET /apps/new" do
171 it 'instantiates a new app with a prebuilt watcher' do 169 it 'instantiates a new app with a prebuilt watcher' do
172 get :new 170 get :new
173 - assigns(:app).should be_a(App)  
174 - assigns(:app).should be_new_record  
175 - assigns(:app).watchers.should_not be_empty 171 + controller.app.should be_a(App)
  172 + controller.app.should be_new_record
  173 + controller.app.watchers.should_not be_empty
176 end 174 end
177 175
178 it "should copy attributes from an existing app" do 176 it "should copy attributes from an existing app" do
179 @app = Fabricate(:app, :name => "do not copy", 177 @app = Fabricate(:app, :name => "do not copy",
180 :github_repo => "test/example") 178 :github_repo => "test/example")
181 get :new, :copy_attributes_from => @app.id 179 get :new, :copy_attributes_from => @app.id
182 - assigns(:app).should be_a(App)  
183 - assigns(:app).should be_new_record  
184 - assigns(:app).name.should be_blank  
185 - assigns(:app).github_repo.should == "test/example" 180 + controller.app.should be_a(App)
  181 + controller.app.should be_new_record
  182 + controller.app.name.should be_blank
  183 + controller.app.github_repo.should == "test/example"
186 end 184 end
187 end 185 end
188 186
@@ -190,7 +188,7 @@ describe AppsController do @@ -190,7 +188,7 @@ describe AppsController do
190 it 'finds the correct app' do 188 it 'finds the correct app' do
191 app = Fabricate(:app) 189 app = Fabricate(:app)
192 get :edit, :id => app.id 190 get :edit, :id => app.id
193 - assigns(:app).should == app 191 + controller.app.should == app
194 end 192 end
195 end 193 end
196 194
@@ -326,12 +324,11 @@ describe AppsController do @@ -326,12 +324,11 @@ describe AppsController do
326 describe "DELETE /apps/:id" do 324 describe "DELETE /apps/:id" do
327 before do 325 before do
328 @app = Fabricate(:app) 326 @app = Fabricate(:app)
329 - App.stub(:find).with(@app.id).and_return(@app)  
330 end 327 end
331 328
332 it "should find the app" do 329 it "should find the app" do
333 delete :destroy, :id => @app.id 330 delete :destroy, :id => @app.id
334 - assigns(:app).should == @app 331 + controller.app.should == @app
335 end 332 end
336 333
337 it "should destroy the app" do 334 it "should destroy the app" do
spec/views/apps/edit.html.haml_spec.rb
@@ -3,7 +3,7 @@ require &#39;spec_helper&#39; @@ -3,7 +3,7 @@ require &#39;spec_helper&#39;
3 describe "apps/edit.html.haml" do 3 describe "apps/edit.html.haml" do
4 before do 4 before do
5 app = stub_model(App) 5 app = stub_model(App)
6 - assign :app, app 6 + view.stub(:app).and_return(app)
7 controller.stub(:current_user) { stub_model(User) } 7 controller.stub(:current_user) { stub_model(User) }
8 end 8 end
9 9
spec/views/apps/index.html.haml_spec.rb
@@ -3,7 +3,7 @@ require &#39;spec_helper&#39; @@ -3,7 +3,7 @@ require &#39;spec_helper&#39;
3 describe "apps/index.html.haml" do 3 describe "apps/index.html.haml" do
4 before do 4 before do
5 app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")]) 5 app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")])
6 - assign :apps, [app] 6 + view.stub(:apps).and_return([app])
7 controller.stub(:current_user) { stub_model(User) } 7 controller.stub(:current_user) { stub_model(User) }
8 end 8 end
9 9
spec/views/problems/index.atom.builder_spec.rb
@@ -4,7 +4,7 @@ describe &quot;problems/index.atom.builder&quot; do @@ -4,7 +4,7 @@ describe &quot;problems/index.atom.builder&quot; do
4 4
5 it 'display problem message' do 5 it 'display problem message' do
6 app = App.new(:new_record => false) 6 app = App.new(:new_record => false)
7 - assign(:problems, [Problem.new( 7 + view.stub(:problems).and_return([Problem.new(
8 :message => 'foo', 8 :message => 'foo',
9 :new_record => false, :app => app), Problem.new(:new_record => false, :app => app)]) 9 :new_record => false, :app => app), Problem.new(:new_record => false, :app => app)])
10 render 10 render