Browse Source

Fix specs and deprecation warnings

Dominik Sander 7 years ago
parent
commit
201b784562

+ 1 - 0
.gitignore

@@ -28,3 +28,4 @@ manifest.yml
 config/unicorn.rb
 db/schema.rb
 .local/
+spec/examples.txt

+ 3 - 3
Gemfile

@@ -152,7 +152,7 @@ group :development do
 
   group :test do
     gem 'coveralls', '~> 0.8.12', require: false
-    gem 'capybara', '~> 2.13.0'
+    gem 'capybara', '~> 2.18'
     gem 'capybara-screenshot'
     gem 'capybara-select2', require: false
     gem 'delorean'
@@ -160,9 +160,9 @@ group :development do
     gem 'pry-rails'
     gem 'pry-byebug'
     gem 'rr'
-    gem 'rspec', '~> 3.5'
+    gem 'rspec', '~> 3.7'
     gem 'rspec-collection_matchers', '~> 1.1.0'
-    gem 'rspec-rails', '~> 3.5.2'
+    gem 'rspec-rails', '~> 3.7'
     gem 'rspec-html-matchers', '~> 0.8'
     gem 'rails-controller-testing'
     gem 'shoulda-matchers'

+ 27 - 27
Gemfile.lock

@@ -136,8 +136,8 @@ GEM
       i18n (>= 0.7, < 2)
       minitest (~> 5.1)
       tzinfo (~> 1.1)
-    addressable (2.5.1)
-      public_suffix (~> 2.0, >= 2.0.2)
+    addressable (2.5.2)
+      public_suffix (>= 2.0.2, < 4.0)
     arel (9.0.0)
     aws-sdk-core (2.2.15)
       jmespath (~> 1.0)
@@ -163,13 +163,13 @@ GEM
     capistrano-rails (1.1.3)
       capistrano (~> 3.1)
       capistrano-bundler (~> 1.1)
-    capybara (2.13.0)
+    capybara (2.18.0)
       addressable
-      mime-types (>= 1.16)
+      mini_mime (>= 0.1.3)
       nokogiri (>= 1.3.3)
       rack (>= 1.0.0)
       rack-test (>= 0.5.4)
-      xpath (~> 2.0)
+      xpath (>= 2.0, < 4.0)
     capybara-screenshot (1.0.17)
       capybara (>= 1.0, < 3)
       launchy
@@ -466,7 +466,7 @@ GEM
       pry (~> 0.10)
     pry-rails (0.3.4)
       pry (>= 0.9.10)
-    public_suffix (2.0.5)
+    public_suffix (3.0.2)
     rack (2.0.4)
     rack-livereload (0.3.16)
       rack
@@ -521,32 +521,32 @@ GEM
       netrc (~> 0.8)
     retriable (3.0.2)
     rr (1.1.2)
-    rspec (3.5.0)
-      rspec-core (~> 3.5.0)
-      rspec-expectations (~> 3.5.0)
-      rspec-mocks (~> 3.5.0)
+    rspec (3.7.0)
+      rspec-core (~> 3.7.0)
+      rspec-expectations (~> 3.7.0)
+      rspec-mocks (~> 3.7.0)
     rspec-collection_matchers (1.1.2)
       rspec-expectations (>= 2.99.0.beta1)
-    rspec-core (3.5.4)
-      rspec-support (~> 3.5.0)
-    rspec-expectations (3.5.0)
+    rspec-core (3.7.1)
+      rspec-support (~> 3.7.0)
+    rspec-expectations (3.7.0)
       diff-lcs (>= 1.2.0, < 2.0)
-      rspec-support (~> 3.5.0)
+      rspec-support (~> 3.7.0)
     rspec-html-matchers (0.9.1)
       nokogiri (~> 1)
       rspec (>= 3.0.0.a, < 4)
-    rspec-mocks (3.5.0)
+    rspec-mocks (3.7.0)
       diff-lcs (>= 1.2.0, < 2.0)
-      rspec-support (~> 3.5.0)
-    rspec-rails (3.5.2)
+      rspec-support (~> 3.7.0)
+    rspec-rails (3.7.2)
       actionpack (>= 3.0)
       activesupport (>= 3.0)
       railties (>= 3.0)
-      rspec-core (~> 3.5.0)
-      rspec-expectations (~> 3.5.0)
-      rspec-mocks (~> 3.5.0)
-      rspec-support (~> 3.5.0)
-    rspec-support (3.5.0)
+      rspec-core (~> 3.7.0)
+      rspec-expectations (~> 3.7.0)
+      rspec-mocks (~> 3.7.0)
+      rspec-support (~> 3.7.0)
+    rspec-support (3.7.1)
     rturk (2.12.1)
       erector
       nokogiri
@@ -653,8 +653,8 @@ GEM
       httparty (> 0.6.0)
       json (> 1.4.0)
     xmpp4r (0.5.6)
-    xpath (2.0.0)
-      nokogiri (~> 1.3)
+    xpath (3.0.0)
+      nokogiri (~> 1.8)
 
 PLATFORMS
   ruby
@@ -669,7 +669,7 @@ DEPENDENCIES
   capistrano (~> 3.4.0)
   capistrano-bundler (~> 1.1.4)
   capistrano-rails (~> 1.1)
-  capybara (~> 2.13.0)
+  capybara (~> 2.18)
   capybara-screenshot
   capybara-select2
   coffee-rails (~> 4.2)
@@ -737,10 +737,10 @@ DEPENDENCIES
   rails-html-sanitizer (~> 1.0.4)
   rb-kqueue (>= 0.2)
   rr
-  rspec (~> 3.5)
+  rspec (~> 3.7)
   rspec-collection_matchers (~> 1.1.0)
   rspec-html-matchers (~> 0.8)
-  rspec-rails (~> 3.5.2)
+  rspec-rails (~> 3.7)
   rturk (~> 2.12.1)
   ruby-growl (~> 4.1.0)
   rufus-scheduler (~> 3.4.2)

+ 1 - 1
app/controllers/jobs_controller.rb

@@ -2,7 +2,7 @@ class JobsController < ApplicationController
   before_action :authenticate_admin!
 
   def index
-    @jobs = Delayed::Job.order("coalesce(failed_at,'1000-01-01'), run_at asc").page(params[:page])
+    @jobs = Delayed::Job.order(Arel.sql("coalesce(failed_at,'1000-01-01'), run_at asc")).page(params[:page])
 
     respond_to do |format|
       format.html { render layout: !request.xhr? }

+ 1 - 1
app/controllers/worker_status_controller.rb

@@ -8,7 +8,7 @@ class WorkerStatusController < ApplicationController
       events = events.where('id > ?', since_id)
     end
 
-    result = events.select('COUNT(id) AS count', 'MIN(id) AS min_id', 'MAX(id) AS max_id').reorder('min(created_at)').first
+    result = events.select('COUNT(id) AS count', 'MIN(id) AS min_id', 'MAX(id) AS max_id').reorder(Arel.sql('min(created_at)')).first
     count, min_id, max_id = result.count, result.min_id, result.max_id
 
     case max_id

+ 3 - 3
app/helpers/agent_helper.rb

@@ -104,13 +104,13 @@ module AgentHelper
       agent_ids = agents.map(&:id)
       cache[:links_as_receiver] = Hash[Link.where(receiver_id: agent_ids)
                                            .group(:receiver_id)
-                                           .pluck('receiver_id', 'count(receiver_id) as id')]
+                                           .pluck(:receiver_id, Arel.sql('count(receiver_id) as id'))]
       cache[:links_as_source]   = Hash[Link.where(source_id: agent_ids)
                                            .group(:source_id)
-                                           .pluck('source_id', 'count(source_id) as id')]
+                                           .pluck(:source_id, Arel.sql('count(source_id) as id'))]
       cache[:control_links_as_controller] = Hash[ControlLink.where(controller_id: agent_ids)
                                                             .group(:controller_id)
-                                                            .pluck('controller_id', 'count(controller_id) as id')]
+                                                            .pluck(:controller_id, Arel.sql('count(controller_id) as id'))]
     end
   end
 end

+ 1 - 1
spec/controllers/agents_controller_spec.rb

@@ -258,7 +258,7 @@ describe AgentsController do
       post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name")}, :format => :json
       expect(agents(:bob_website_agent).reload.name).to eq("New name")
       expect(JSON.parse(response.body)['name']).to eq("New name")
-      expect(response).to be_success
+      expect(response).to be_successful
     end
 
     it "will not accept Agent sources owned by other users" do

+ 7 - 7
spec/controllers/web_requests_controller_spec.rb

@@ -29,7 +29,7 @@ describe WebRequestsController do
     post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}
     expect(@agent.reload.last_web_request_at).to be_within(2).of(Time.now)
     expect(response.body).to eq("success")
-    expect(response).to be_success
+    expect(response).to be_successful
   end
 
   it "should call receive_web_request" do
@@ -40,12 +40,12 @@ describe WebRequestsController do
     expect(@agent.memory[:web_request_method]).to eq("post")
     expect(response.body).to eq("success")
     expect(response.headers['Content-Type']).to eq('text/plain; charset=utf-8')
-    expect(response).to be_success
+    expect(response).to be_successful
 
     post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "not_my_secret", :no => "go"}
     expect(@agent.reload.memory[:web_request_values]).not_to eq({ 'no' => "go" })
     expect(response.body).to eq("failure")
-    expect(response).to be_missing
+    expect(response.status).to eq(404)
   end
 
   it "should accept gets" do
@@ -55,7 +55,7 @@ describe WebRequestsController do
     expect(@agent.memory[:web_request_format]).to eq("text/html")
     expect(@agent.memory[:web_request_method]).to eq("get")
     expect(response.body).to eq("success")
-    expect(response).to be_success
+    expect(response).to be_successful
   end
 
   it "should pass through the received format" do
@@ -109,12 +109,12 @@ describe WebRequestsController do
 
   it "should fail on incorrect users" do
     post :handle_request, params: {:user_id => users(:jane).to_param, :agent_id => @agent.id, :secret => "my_secret", :no => "go"}
-    expect(response).to be_missing
+    expect(response.status).to eq(404)
   end
 
   it "should fail on incorrect agents" do
     post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => 454545, :secret => "my_secret", :no => "go"}
-    expect(response).to be_missing
+    expect(response.status).to eq(404)
   end
 
   describe "legacy update_location endpoint" do
@@ -141,7 +141,7 @@ describe WebRequestsController do
 
     it "should raise a 404 error when given an invalid user id" do
       post :update_location, params: {user_id: "123", secret: "not_my_secret", longitude: 123, latitude: 45, something: "else"}
-      expect(response).to be_missing
+      expect(response.status).to eq(404)
     end
 
     it "should only look at agents with the given secret" do

+ 1 - 1
spec/models/agents/imap_folder_agent_spec.rb

@@ -215,7 +215,7 @@ describe Agents::ImapFolderAgent do
         })
 
         expect(Event.last.payload).to eq(expected_payloads.last.update(
-          'body' => "<div dir=\"ltr\">Some HTML reply<br></div>\n",
+          'body' => "<div dir=\"ltr\">Some HTML reply<br></div>\r\n",
           'matches' => { 'a' => 'some subject', 'b' => 'HTML' },
           'mime_type' => 'text/html',
         ))

+ 2 - 0
spec/rails_helper.rb

@@ -66,6 +66,8 @@ RSpec.configure do |config|
 
   config.render_views
 
+  config.example_status_persistence_file_path = "./spec/examples.txt"
+
   config.include Devise::Test::ControllerHelpers, type: :controller
   config.include SpecHelpers
   config.include Delorean