Commit a7c9f4a3ab45cf77bf28d5b1652ada0731e8ddda

Authored by darkodosenovic
2 parents 2861fd96 9d90543a
Exists in master and in 1 other branch production

Merge pull request #1 from amaabca/errbit_update

Errbit update
.travis.yml
  1 +language: ruby
1 2 rvm:
2 3 - 1.9.3
3 4 - 1.9.2
4 5 - 1.8.7
5 6  
6   -
7 7 # To stop Travis from running tests for a new commit,
8 8 # add the following to your commit message: [ci skip]
9 9 # You should add this when you edit documentation or comments, etc.
10   -
... ...
Gemfile
1 1 source 'http://rubygems.org'
2 2  
3   -gem 'rails', '3.2.5'
  3 +gem 'rails', '3.2.6'
4 4  
5 5 gem 'nokogiri'
6 6 gem 'mongoid', '~> 2.4.10'
... ...
Gemfile.lock
... ... @@ -2,16 +2,16 @@ GEM
2 2 remote: http://rubygems.org/
3 3 specs:
4 4 SystemTimer (1.2.3)
5   - actionmailer (3.2.5)
6   - actionpack (= 3.2.5)
  5 + actionmailer (3.2.6)
  6 + actionpack (= 3.2.6)
7 7 mail (~> 2.4.4)
8 8 actionmailer_inline_css (1.3.1)
9 9 actionmailer (>= 3.0.0)
10 10 nokogiri (>= 1.4.4)
11 11 premailer (>= 1.7.1)
12   - actionpack (3.2.5)
13   - activemodel (= 3.2.5)
14   - activesupport (= 3.2.5)
  12 + actionpack (3.2.6)
  13 + activemodel (= 3.2.6)
  14 + activesupport (= 3.2.6)
15 15 builder (~> 3.0.0)
16 16 erubis (~> 2.7.0)
17 17 journey (~> 1.0.1)
... ... @@ -19,18 +19,18 @@ GEM
19 19 rack-cache (~> 1.2)
20 20 rack-test (~> 0.6.1)
21 21 sprockets (~> 2.1.3)
22   - activemodel (3.2.5)
23   - activesupport (= 3.2.5)
  22 + activemodel (3.2.6)
  23 + activesupport (= 3.2.6)
24 24 builder (~> 3.0.0)
25   - activerecord (3.2.5)
26   - activemodel (= 3.2.5)
27   - activesupport (= 3.2.5)
  25 + activerecord (3.2.6)
  26 + activemodel (= 3.2.6)
  27 + activesupport (= 3.2.6)
28 28 arel (~> 3.0.2)
29 29 tzinfo (~> 0.3.29)
30   - activeresource (3.2.5)
31   - activemodel (= 3.2.5)
32   - activesupport (= 3.2.5)
33   - activesupport (3.2.5)
  30 + activeresource (3.2.6)
  31 + activemodel (= 3.2.6)
  32 + activesupport (= 3.2.6)
  33 + activesupport (3.2.6)
34 34 i18n (~> 0.6)
35 35 multi_json (~> 1.0)
36 36 addressable (2.2.8)
... ... @@ -88,7 +88,7 @@ GEM
88 88 inherited_resources (1.3.1)
89 89 has_scope (~> 0.5.0)
90 90 responders (~> 0.6)
91   - journey (1.0.3)
  91 + journey (1.0.4)
92 92 json (1.7.3)
93 93 kaminari (0.13.0)
94 94 actionpack (>= 3.0.0)
... ... @@ -106,7 +106,7 @@ GEM
106 106 activesupport (>= 3.0.0)
107 107 linecache (0.46)
108 108 rbx-require-relative (> 0.0.4)
109   - linecache19 (0.5.12)
  109 + linecache19 (0.5.13)
110 110 ruby_core_source (>= 0.1.4)
111 111 mail (2.4.4)
112 112 i18n (>= 0.4.0)
... ... @@ -170,19 +170,19 @@ GEM
170 170 rack-ssl-enforcer (0.2.4)
171 171 rack-test (0.6.1)
172 172 rack (>= 1.0)
173   - rails (3.2.5)
174   - actionmailer (= 3.2.5)
175   - actionpack (= 3.2.5)
176   - activerecord (= 3.2.5)
177   - activeresource (= 3.2.5)
178   - activesupport (= 3.2.5)
  173 + rails (3.2.6)
  174 + actionmailer (= 3.2.6)
  175 + actionpack (= 3.2.6)
  176 + activerecord (= 3.2.6)
  177 + activeresource (= 3.2.6)
  178 + activesupport (= 3.2.6)
179 179 bundler (~> 1.0)
180   - railties (= 3.2.5)
  180 + railties (= 3.2.6)
181 181 rails_autolink (1.0.9)
182 182 rails (~> 3.1)
183   - railties (3.2.5)
184   - actionpack (= 3.2.5)
185   - activesupport (= 3.2.5)
  183 + railties (3.2.6)
  184 + actionpack (= 3.2.6)
  185 + activesupport (= 3.2.6)
186 186 rack-ssl (~> 1.3.2)
187 187 rake (>= 0.8.7)
188 188 rdoc (~> 3.4)
... ... @@ -299,7 +299,7 @@ DEPENDENCIES
299 299 pivotal-tracker
300 300 rack-ssl
301 301 rack-ssl-enforcer
302   - rails (= 3.2.5)
  302 + rails (= 3.2.6)
303 303 rails_autolink (~> 1.0.9)
304 304 ri_cal
305 305 rspec (~> 2.6)
... ...
README.md
... ... @@ -163,13 +163,30 @@ heroku run rake db:seed
163 163  
164 164 * If you are using a free database on Heroku, you may want to periodically clear resolved errors to free up space.
165 165  
166   -```bash
167   -# Install the heroku cron addon, to clear resolved errors daily:
168   -heroku addons:add cron:daily
169   -
170   -# Or, clear resolved errors manually:
171   -heroku rake errbit:db:clear_resolved
172   -```
  166 + * With the heroku-scheduler add-on (replacement for cron):
  167 +
  168 + ```bash
  169 + # Install the heroku scheduler add-on
  170 + heroku addons:add scheduler:standard
  171 +
  172 + # Go open the dashboard to schedule the job. You should use
  173 + # 'rake errbit:db:clear_resolved' as the task command, and schedule it
  174 + # at whatever frequency you like (once/day should work great).
  175 + heroku addons:open scheduler
  176 + ```
  177 +
  178 + * With the cron add-on:
  179 +
  180 + ```bash
  181 + # Install the heroku cron addon, to clear resolved errors daily:
  182 + heroku addons:add cron:daily
  183 + ```
  184 +
  185 + * Or clear resolved errors manually:
  186 +
  187 + ```bash
  188 + heroku rake errbit:db:clear_resolved
  189 + ```
173 190  
174 191 * You may want to enable the deployment hook for heroku :
175 192  
... ...
app/controllers/errs_controller.rb
... ... @@ -46,7 +46,7 @@ class ErrsController < ApplicationController
46 46 else
47 47 @tracker = GithubIssuesTracker.new(
48 48 :app => @app,
49   - :login => current_user.github_login,
  49 + :username => current_user.github_login,
50 50 :oauth_token => current_user.github_oauth_token
51 51 )
52 52 end
... ...
app/models/issue_trackers/github_issues_tracker.rb
... ... @@ -21,7 +21,7 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
21 21  
22 22 def check_params
23 23 if Fields.detect {|f| self[f[0]].blank? }
24   - errors.add :base, 'You must specify your GitHub repository, username and password'
  24 + errors.add :base, 'You must specify your GitHub username and password'
25 25 end
26 26 end
27 27  
... ...
app/models/issue_trackers/pivotal_labs_tracker.rb
... ... @@ -17,11 +17,18 @@ class IssueTrackers::PivotalLabsTracker < IssueTracker
17 17 PivotalTracker::Client.token = api_token
18 18 PivotalTracker::Client.use_ssl = true
19 19 project = PivotalTracker::Project.find project_id.to_i
20   - story = project.stories.create :name => issue_title(problem), :story_type => 'bug', :description => body_template.result(binding)
21   - problem.update_attributes(
22   - :issue_link => "https://www.pivotaltracker.com/story/show/#{story.id}",
23   - :issue_type => Label
24   - )
  20 + story = project.stories.create :name => issue_title(problem),
  21 + :story_type => 'bug', :description => body_template.result(binding),
  22 + :requested_by => reported_by.name
  23 +
  24 + if story.errors.present?
  25 + raise IssueTrackers::IssueTrackerError, story.errors.first
  26 + else
  27 + problem.update_attributes(
  28 + :issue_link => "https://www.pivotaltracker.com/story/show/#{story.id}",
  29 + :issue_type => Label
  30 + )
  31 + end
25 32 end
26 33  
27 34 def body_template
... ...
app/models/notice.rb
... ... @@ -94,6 +94,14 @@ class Notice
94 94 backtrace.select { |l| l && l['file'] && l['file'].include?("[PROJECT_ROOT]") }
95 95 end
96 96  
  97 + def backtrace
  98 + # If gems are vendored into project, treat vendored gem dir as [GEM_ROOT]
  99 + (read_attribute(:backtrace) || []).map do |line|
  100 + # Changes "[PROJECT_ROOT]/rubygems/ruby/1.9.1/gems" to "[GEM_ROOT]/gems"
  101 + line.merge 'file' => line['file'].to_s.gsub(/\[PROJECT_ROOT\]\/.*\/ruby\/[0-9.]+\/gems/, '[GEM_ROOT]/gems')
  102 + end
  103 + end
  104 +
97 105 protected
98 106  
99 107 def increase_counter_cache
... ... @@ -121,7 +129,7 @@ class Notice
121 129 send("#{h}=",sanitize_hash(send(h)))
122 130 end
123 131 # Set unknown backtrace files
124   - backtrace.each{|line| line['file'] = "[unknown source]" if line['file'].blank? }
  132 + read_attribute(:backtrace).each{|line| line['file'] = "[unknown source]" if line['file'].blank? }
125 133 end
126 134  
127 135 def sanitize_hash(h)
... ...
app/models/problem.rb
... ... @@ -119,7 +119,7 @@ class Problem
119 119 end
120 120 collection.update({'_id' => self.id},
121 121 {'$set' => {'app_name' => self.app_name,
122   - 'last_deploy_at' => self.last_deploy_at}})
  122 + 'last_deploy_at' => self.last_deploy_at.try(:utc)}})
123 123 end
124 124 end
125 125  
... ...
app/views/apps/show.html.haml
... ... @@ -11,7 +11,7 @@
11 11 - content_for :action_bar do
12 12 - if current_user.admin?
13 13 = link_to 'edit', edit_app_path(@app), :class => 'button'
14   - = link_to 'destroy', app_path(@app), :method => :delete, :confirm => 'Seriously?', :class => 'button'
  14 + = link_to 'destroy', app_path(@app), :method => :delete, :data => { :confirm => 'Seriously?' }, :class => 'button'
15 15 - if @all_errs
16 16 = link_to 'unresolved errs', app_path(@app), :class => 'button'
17 17 - else
... ...
app/views/errs/_issue_tracker_links.html.haml
1 1 - if @app.issue_tracker_configured? || current_user.github_account?
2 2 - if @problem.issue_link.present?
3 3 %span= link_to 'go to issue', @problem.issue_link, :class => "#{@problem.issue_type}_goto goto-issue"
4   - = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue"
  4 + = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :data => { :confirm => "Unlink err issues?" }, :class => "unlink-issue"
5 5 - elsif @problem.issue_link == "pending"
6 6 %span.disabled= link_to 'creating...', '#', :class => "#{@problem.issue_type}_inactive create-issue"
7 7 = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post
8 8 - else
9   - - if current_user.can_create_github_issues? && @app.github_repo?
10   - %span= link_to 'create issue', create_issue_app_err_path(@app, @problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue"
  9 + - if @app.github_repo?
  10 + - if current_user.can_create_github_issues?
  11 + %span= link_to 'create issue', create_issue_app_err_path(@app, @problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue"
  12 + - elsif @app.issue_tracker_configured? && @app.issue_tracker.is_a?(GithubIssuesTracker)
  13 + %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "github_create create-issue"
11 14 - if @app.issue_tracker_configured? && !@app.issue_tracker.is_a?(GithubIssuesTracker)
12 15 %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "#{@app.issue_tracker.label}_create create-issue"
... ...
app/views/errs/_table.html.haml
... ... @@ -40,7 +40,7 @@
40 40 %td.issue_link
41 41 - if problem.app.issue_tracker_configured? && problem.issue_link.present? && problem.issue_link != 'pending'
42 42 = link_to image_tag("#{problem.issue_type}_goto.png"), problem.issue_link, :target => "_blank"
43   - %td.resolve= link_to image_tag("thumbs-up.png"), resolve_app_err_path(problem.app, problem), :title => "Resolve", :method => :put, :confirm => err_confirm, :class => 'resolve' if problem.unresolved?
  43 + %td.resolve= link_to image_tag("thumbs-up.png"), resolve_app_err_path(problem.app, problem), :title => "Resolve", :method => :put, :data => { :confirm => err_confirm }, :class => 'resolve' if problem.unresolved?
44 44 - if errs.none?
45 45 %tr
46 46 %td{:colspan => (any_issue_links ? 8 : 7)}
... ...
app/views/errs/show.html.haml
... ... @@ -13,7 +13,7 @@
13 13 = last_notice_at(@problem).to_s(:precise)
14 14 - content_for :action_bar do
15 15 - if @problem.unresolved?
16   - %span= link_to 'resolve', resolve_app_err_path(@app, @problem), :method => :put, :confirm => err_confirm, :class => 'resolve'
  16 + %span= link_to 'resolve', resolve_app_err_path(@app, @problem), :method => :put, :data => { :confirm => err_confirm }, :class => 'resolve'
17 17 - if current_user.authentication_token
18 18 %span= link_to 'iCal', app_err_path(:app_id => @app.id, :id => @problem.id, :format => "ics", :auth_token => current_user.authentication_token), :class => "calendar_link"
19 19 %span>= link_to 'up', (request.env['HTTP_REFERER'] ? :back : app_errs_path(@app)), :class => 'up'
... ... @@ -28,7 +28,7 @@
28 28 %table.comment
29 29 %tr
30 30 %th
31   - %span= link_to '✘'.html_safe, app_err_comment_path(@app, @problem, comment), :method => :delete, :confirm => "Are sure you don't need this comment?", :class => "destroy-comment"
  31 + %span= link_to '✘'.html_safe, app_err_comment_path(@app, @problem, comment), :method => :delete, :data => { :confirm => "Are sure you don't need this comment?" }, :class => "destroy-comment"
32 32 = time_ago_in_words(comment.created_at, true) << " ago by "
33 33 = link_to comment.user.email, user_path(comment.user)
34 34 %tr
... ...
app/views/notices/_user_attributes.html.haml
... ... @@ -6,4 +6,4 @@
6 6 - user.each do |user_key, user_value|
7 7 %tr
8 8 %th= user_key
9   - %td= auto_link(user_value).html_safe
  9 + %td= auto_link(user_value.to_s).html_safe
... ...
app/views/shared/_link_github_account.html.haml
1 1 - if Errbit::Config.github_authentication && user == current_user
2 2 - if user.github_account?
3   - %span.unlink_github= link_to "Unlink GitHub account", unlink_github_user_path(user), :method => :delete, :confirm => "Are you sure?"
  3 + %span.unlink_github= link_to "Unlink GitHub account", unlink_github_user_path(user), :method => :delete, :data => { :confirm => "Are you sure?" }
4 4 - else
5 5 %span.github= link_to "Link GitHub account", user_omniauth_authorize_path(:github)
... ...
app/views/users/_fields.html.haml
... ... @@ -18,7 +18,7 @@
18 18 = f.text_field :github_login
19 19  
20 20 .required
21   - = f.label 'Entries per page'
  21 + = f.label :per_page, 'Entries per page'
22 22 = f.select :per_page, [10, 20, 30, 50, 75, 100]
23 23  
24 24 .required
... ...
app/views/users/show.html.haml
... ... @@ -3,7 +3,7 @@
3 3 = render 'shared/link_github_account', :user => @user
4 4 %span= link_to('Add a New User', new_user_path, :class => 'add')
5 5 = link_to 'edit', edit_user_path(@user), :class => 'button'
6   - = link_to 'destroy', user_path(@user), :method => :delete, :confirm => 'Seriously?', :class => 'button'
  6 + = link_to 'destroy', user_path(@user), :method => :delete, :data => { :confirm => 'Seriously?' }, :class => 'button'
7 7  
8 8  
9 9 %table.single_user
... ...
db/migrate/20120603112130_change_github_url_to_github_repo.rb
... ... @@ -3,7 +3,7 @@ class ChangeGithubUrlToGithubRepo &lt; Mongoid::Migration
3 3 App.collection.update({}, {'$rename' => {'github_url' => 'github_repo'}}, multi: true, safe: true)
4 4 App.all.each do |app|
5 5 app.send :normalize_github_repo
6   - app.save!
  6 + app.save
7 7 end
8 8 end
9 9  
... ...
spec/models/issue_trackers/pivotal_labs_tracker_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe IssueTrackers::PivotalLabsTracker do
4   - it "should create an issue on Pivotal Tracker with problem params, and set issue link for problem" do
5   - notice = Fabricate :notice
6   - tracker = Fabricate :pivotal_labs_tracker, :app => notice.app, :project_id => 10
7   - problem = notice.problem
8 4  
9   - story_id = 5
10   - @issue_link = "https://www.pivotaltracker.com/story/show/#{story_id}"
  5 + let(:user) { Fabricate(:user) }
  6 + let(:notice) { Fabricate(:notice) }
  7 + let(:tracker) { Fabricate :pivotal_labs_tracker, :app => notice.app, :project_id => 10 }
  8 + let(:problem) { notice.problem }
  9 + let(:story_id) { 5 }
  10 + let(:issue_link) { "https://www.pivotaltracker.com/story/show/#{story_id}" }
  11 +
  12 + it "creates an issue on Pivotal Tracker with problem params, and set issue link for problem" do
11 13 project_body = "<project><id>#{tracker.project_id}</id><name>TestProject</name></project>"
12 14 stub_request(:get, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}").
13   - to_return(:status => 200, :headers => {'Location' => @issue_link}, :body => project_body )
  15 + to_return(:status => 200, :headers => {'Location' => issue_link}, :body => project_body )
14 16 story_body = "<story><name>Test Story</name><id>#{story_id}</id></story>"
15 17 stub_request(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories").
16   - to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => story_body )
  18 + to_return(:status => 201, :headers => {'Location' => issue_link}, :body => story_body )
17 19  
18   - problem.app.issue_tracker.create_issue(problem)
  20 + problem.app.issue_tracker.create_issue(problem, user)
19 21 problem.reload
20 22  
21 23 requested = have_requested(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories")
... ... @@ -24,7 +26,20 @@ describe IssueTrackers::PivotalLabsTracker do
24 26 WebMock.should requested.with(:body => /<name>\[#{ problem.environment }\]\[#{problem.where}\] #{problem.message.to_s.truncate(100)}<\/name>/)
25 27 WebMock.should requested.with(:body => /<description>.+<\/description>/m)
26 28  
27   - problem.issue_link.should == @issue_link
  29 + problem.issue_link.should == issue_link
  30 + end
  31 +
  32 + it "raises IssueTrackers::IssueTrackerError exception when invalid params and does not set issue link for problem" do
  33 + project_body = "<project><id>#{tracker.project_id}</id><name>TestProject</name></project>"
  34 + stub_request(:get, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}").
  35 + to_return(:status => 200, :body => project_body )
  36 + story_body = "<errors><error>Requested by can't be blank</error><error>Requested by can't be blank</error></errors>"
  37 + stub_request(:post, "https://www.pivotaltracker.com/services/v3/projects/#{tracker.project_id}/stories").
  38 + to_return(:status => 422, :body => story_body )
  39 +
  40 + lambda { problem.app.issue_tracker.create_issue(problem, user)
  41 + }.should raise_exception(IssueTrackers::IssueTrackerError, "Requested by can't be blank")
  42 + problem.issue_link.should be_nil
28 43 end
29 44 end
30 45  
... ...
spec/views/apps/index.html.haml_spec.rb
... ... @@ -2,11 +2,11 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe "apps/index.html.haml" do
4 4 before do
5   - app = Fabricate(:app, :deploys => [Fabricate(:deploy, :revision => "123456789abcdef")])
  5 + app = stub_model(App, :deploys => [stub_model(Deploy, :created_at => Time.now, :revision => "123456789abcdef")])
6 6 assign :apps, [app]
7 7 assign :problem_counts, {app.id => 0}
8 8 assign :unresolved_counts, {app.id => 0}
9   - controller.stub(:current_user) { Fabricate(:user) }
  9 + controller.stub(:current_user) { stub_model(User) }
10 10 end
11 11  
12 12 describe "deploy column" do
... ...
spec/views/errs/show.html.haml_spec.rb
... ... @@ -13,6 +13,12 @@ describe &quot;errs/show.html.haml&quot; do
13 13 controller.stub(:current_user) { Fabricate(:user) }
14 14 end
15 15  
  16 + def with_issue_tracker(tracker, problem)
  17 + problem.app.issue_tracker = tracker.new :api_token => "token token token", :project_id => "1234"
  18 + assign :problem, problem
  19 + assign :app, problem.app
  20 + end
  21 +
16 22 describe "content_for :action_bar" do
17 23 def action_bar
18 24 view.content_for(:action_bar)
... ... @@ -35,7 +41,7 @@ describe &quot;errs/show.html.haml&quot; do
35 41 Errbit::Config.stub(:confirm_resolve_err).and_return(false)
36 42 render
37 43  
38   - action_bar.should_not have_selector('a.resolve[data-confirm]')
  44 + action_bar.should have_selector('a.resolve[data-confirm="null"]')
39 45 end
40 46  
41 47 it "should link 'up' to HTTP_REFERER if is set" do
... ... @@ -68,6 +74,16 @@ describe &quot;errs/show.html.haml&quot; do
68 74  
69 75 action_bar.should have_selector("span a.github_create.create-issue", :text => 'create issue')
70 76 end
  77 +
  78 + it 'should allow creating issue for github if application has a github tracker' do
  79 + problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo"))
  80 + with_issue_tracker(GithubIssuesTracker, problem)
  81 + assign :problem, problem
  82 + assign :app, problem.app
  83 + render
  84 +
  85 + action_bar.should have_selector("span a.github_create.create-issue", :text => 'create issue')
  86 + end
71 87 end
72 88 end
73 89  
... ... @@ -87,15 +103,9 @@ describe &quot;errs/show.html.haml&quot; do
87 103 end
88 104  
89 105 context "with issue tracker" do
90   - def with_issue_tracker(problem)
91   - problem.app.issue_tracker = PivotalLabsTracker.new :api_token => "token token token", :project_id => "1234"
92   - assign :problem, problem
93   - assign :app, problem.app
94   - end
95   -
96 106 it 'should not display the comments section' do
97 107 problem = Fabricate(:problem)
98   - with_issue_tracker(problem)
  108 + with_issue_tracker(PivotalLabsTracker, problem)
99 109 render
100 110 view.view_flow.get(:comments).should be_blank
101 111 end
... ... @@ -103,7 +113,7 @@ describe &quot;errs/show.html.haml&quot; do
103 113 it 'should display existing comments' do
104 114 problem = Fabricate(:problem_with_comments)
105 115 problem.reload
106   - with_issue_tracker(problem)
  116 + with_issue_tracker(PivotalLabsTracker, problem)
107 117 render
108 118  
109 119 view.content_for(:comments).should include('Test comment')
... ...
spec/views/notices/_backtrace.html.haml_spec.rb
... ... @@ -2,17 +2,15 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe "notices/_backtrace.html.haml" do
4 4 describe 'missing file in backtrace' do
5   - before do
6   - @notice = Fabricate(:notice, :backtrace => [{
7   - 'number' => rand(999),
8   - 'file' => nil,
9   - 'method' => ActiveSupport.methods.shuffle.first
10   - }])
11   - assign :app, @notice.err.app
  5 + let(:notice) do
  6 + backtrace = { 'number' => rand(999), 'file' => nil, 'method' => ActiveSupport.methods.shuffle.first }
  7 + Fabricate(:notice, :backtrace => [backtrace])
12 8 end
13 9  
14 10 it "should replace nil file with [unknown source]" do
15   - render "notices/backtrace", :lines => @notice.backtrace
  11 + assign :app, notice.err.app
  12 +
  13 + render "notices/backtrace", :lines => notice.backtrace
16 14 rendered.should match(/\[unknown source\]/)
17 15 end
18 16 end
... ...
spec/views/notices/_user_attributes.html.haml_spec.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "notices/_user_attributes.html.haml" do
  4 + describe 'autolink' do
  5 + let(:notice) do
  6 + user_attributes = { 'foo' => {'bar' => 'http://example.com'} }
  7 + Fabricate(:notice, :user_attributes => user_attributes)
  8 + end
  9 +
  10 + it "renders table with user attributes" do
  11 + assign :app, notice.err.app
  12 +
  13 + render "notices/user_attributes", :user => notice.user_attributes
  14 + rendered.should have_link('http://example.com')
  15 + end
  16 + end
  17 +end
  18 +
... ...
spec/views/users/show.html.haml_spec.rb
... ... @@ -2,12 +2,12 @@ require &#39;spec_helper&#39;
2 2  
3 3 describe 'users/show.html.haml' do
4 4 let(:user) do
5   - user = stub_model(User, :created_at => Time.now)
  5 + stub_model(User, :created_at => Time.now)
6 6 end
7 7  
8 8 before do
9 9 Errbit::Config.stub(:github_authentication) { true }
10   - controller.stub(:current_user) { Fabricate(:user) }
  10 + controller.stub(:current_user) { stub_model(User) }
11 11 end
12 12  
13 13 context 'with GitHub authentication' do
... ... @@ -39,9 +39,8 @@ describe &#39;users/show.html.haml&#39; do
39 39  
40 40 context 'viewing own user page' do
41 41 before do
42   - @user = Fabricate(:user)
43   - controller.stub!(:current_user).and_return(@user)
44   - assign :user, @user
  42 + controller.stub(:current_user) { user }
  43 + assign :user, user
45 44 end
46 45  
47 46 it 'shows link github button when no login or token' do
... ... @@ -50,8 +49,9 @@ describe &#39;users/show.html.haml&#39; do
50 49 end
51 50  
52 51 it 'shows unlink github button when login and token' do
53   - @user.github_login = 'test_user'
54   - @user.github_oauth_token = 'abcdef'
  52 + user.github_login = 'test_user'
  53 + user.github_oauth_token = 'abcdef'
  54 +
55 55 render
56 56 view.content_for(:action_bar).should include('Unlink GitHub account')
57 57 end
... ...