Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,8 @@ gem "countries", require: false # for update translations job, so require only t

group :development, :test do
gem "debug", platforms: %i[mri mingw x64_mingw]
gem "factory_bot_rails"
gem "faker"
gem "parallel_tests"
gem "rubocop-rails"
gem "standard"
gem "webmock"
gem "rubocop-rails", require: false
gem "standard", require: false
end

group :development do
Expand Down Expand Up @@ -143,12 +139,17 @@ group :test do
gem "capybara"
gem "cuprite"
gem "database_cleaner"
gem "factory_bot_rails"
gem "faker"
gem "parallel_tests"
gem "rspec-collection_matchers"
gem "rspec-rails"
gem "rspec-request_snapshot", github: "tsubik/rspec-request_snapshot", branch: "fix/ignore-order"
gem "shoulda-matchers", "~> 4.0.1"
gem "simplecov"
gem "spring-commands-rspec"
gem "super_diff"
gem "webmock"
end

# Server
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
spring (4.3.0)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (4.2.2)
concurrent-ruby (~> 1.0)
logger
Expand Down Expand Up @@ -875,6 +878,7 @@ DEPENDENCIES
shoulda-matchers (~> 4.0.1)
sidekiq
simplecov
spring-commands-rspec
sprockets-rails
standard
super_diff
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ bundle exec rake parallel:drop

For more information about parallel tests check [parallel_tests gem.](https://github.com/grosser/parallel_tests)

### Running single test faster with spring ###

You can use spring to run single tests faster. There is bin/rspec stub that will run the tests with spring. You can use it like this:

```ruby
bin/rspec spec/models/user_spec.rb
```

or just prepend spring to the command:

```ruby
bundle exec spring rspec spec/models/user_spec.rb
```

## DOCUMENTATION ##

### API ###
Expand Down
6 changes: 3 additions & 3 deletions app/resources/concerns/operator_documentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def status
return @model.status if can_see_document?
return @model.status if document_public? && %w[doc_not_provided doc_valid doc_expired doc_not_required].include?(@model.status)

:doc_not_provided
"doc_not_provided"
end

def attachment
return @model&.document_file&.attachment if document_visible?
return {url: nil} if %w[doc_not_provided doc_not_required].include?(status)

{url: nil}
@model&.document_file&.attachment
end

def attachment=(attachment)
Expand Down
4 changes: 4 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
load File.expand_path("spring", __dir__)
require 'bundler/setup'
load Gem.bin_path('rspec-core', 'rspec')
14 changes: 14 additions & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

# This file loads Spring without loading other gems in the Gemfile in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
require "bundler"

Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem "spring", spring.version
require "spring/binstub"
end
end
4 changes: 2 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# While tests run files are not watched, reloading is not necessary.
config.enable_reloading = false
# While tests run files are not watched, reloading is not necessary. (unless you are using Spring)
config.enable_reloading = ENV["SPRING_SPAWN_ENV"].present?

# Eager loading loads your entire application. When running a single test locally,
# this is usually not necessary, and can slow down your test suite. However, it's
Expand Down
19 changes: 17 additions & 2 deletions spec/integration/v1/operator_document_histories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ module V1
public: false,
note: "notes"
)
@doc_invalid.update(status: "doc_invalid", admin_comment: "invalid")
@doc_valid_private.update(status: "doc_valid")
@doc_invalid.update!(status: "doc_invalid", admin_comment: "invalid")
@doc_valid_private.update!(status: "doc_valid")
end

context "when admin" do
Expand All @@ -145,6 +145,7 @@ module V1

expect(parsed_data.count).to eql(2)
expect(returned_document[:status]).to eq("doc_invalid")
expect(returned_document[:attachment]).to eq({url: @doc_invalid.document_file.attachment.url})
end
end

Expand All @@ -160,6 +161,8 @@ module V1

expect(parsed_data.count).to eql(2)
expect(returned_document[:status]).to eq("doc_not_provided")
expect(returned_document[:"admin-comment"]).to be_nil
expect(returned_document[:attachment]).to eq({url: nil})
end

context "with signed publication authorization" do
Expand All @@ -179,6 +182,12 @@ module V1
expect(returned_document[:"response-date"]).to eq(@doc_valid_private.response_date.iso8601(3))
expect(returned_document[:"updated-at"]).not_to be_nil
expect(returned_document[:"created-at"]).not_to be_nil
expect(returned_document[:attachment]).to eq({url: @doc_valid_private.document_file.attachment.url})

invalid_doc = parsed_data.find { |d| d[:attributes][:"operator-document-id"] == @doc_invalid.id }[:attributes]
expect(invalid_doc[:status]).to eq("doc_not_provided")
expect(invalid_doc[:"admin-comment"]).to be_nil
expect(invalid_doc[:attachment]).to eq({url: nil})
end
end

Expand All @@ -192,12 +201,18 @@ module V1
returned_document = parsed_data.find { |d| d[:attributes][:"operator-document-id"] == @doc_valid_private.id }[:attributes]
expect(parsed_data.count).to eql(2)
expect(returned_document[:status]).to eq("doc_not_provided")
expect(returned_document[:attachment]).to eq({url: nil})
expect(returned_document[:"start-date"]).to be_nil
expect(returned_document[:"expire-date"]).to be_nil
expect(returned_document[:"response-date"]).to be_nil
expect(returned_document[:note]).to be_nil
expect(returned_document[:"updated-at"]).to be_nil
expect(returned_document[:"created-at"]).to be_nil

invalid_doc = parsed_data.find { |d| d[:attributes][:"operator-document-id"] == @doc_invalid.id }[:attributes]
expect(invalid_doc[:status]).to eq("doc_not_provided")
expect(invalid_doc[:"admin-comment"]).to be_nil
expect(invalid_doc[:attachment]).to eq({url: nil})
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/integration/v1/operator_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def sign_publication_authorization!
expect(parsed_data.count).to eql(10)
expect(returned_document[:status]).to eq("doc_invalid")
expect(returned_document[:"admin-comment"]).to eq("invalid")
expect(returned_document[:attachment]).to eq({url: @doc_invalid.document_file.attachment.url})
end

it "returns publication authorization" do
Expand Down Expand Up @@ -91,6 +92,7 @@ def sign_publication_authorization!
expect(parsed_data.count).to eql(9)
expect(returned_document[:status]).to eq("doc_not_provided")
expect(returned_document[:"admin-comment"]).to be_nil
expect(returned_document[:attachment]).to eq({url: nil})
end

context "with signed publication authorization" do
Expand All @@ -110,10 +112,12 @@ def sign_publication_authorization!
expect(returned_document[:"response-date"]).to eq(@doc_valid_private.response_date.iso8601(3))
expect(returned_document[:"updated-at"]).not_to be_nil
expect(returned_document[:"created-at"]).not_to be_nil
expect(returned_document[:attachment]).to eq({url: @doc_valid_private.document_file.attachment.url})

invalid_doc = parsed_data.find { |d| d[:id] == @doc_invalid.id.to_s }[:attributes]
expect(invalid_doc[:status]).to eq("doc_not_provided")
expect(invalid_doc[:"admin-comment"]).to be_nil
expect(invalid_doc[:attachment]).to eq({url: nil})
end
end

Expand All @@ -124,6 +128,7 @@ def sign_publication_authorization!
returned_document = parsed_data.find { |d| d[:id] == @doc_valid_private.id.to_s }[:attributes]
expect(parsed_data.count).to eql(9)
expect(returned_document[:status]).to eq("doc_not_provided")
expect(returned_document[:attachment]).to eq({url: nil})
expect(returned_document[:"start-date"]).to be_nil
expect(returned_document[:"expire-date"]).to be_nil
expect(returned_document[:"response-date"]).to be_nil
Expand All @@ -134,6 +139,7 @@ def sign_publication_authorization!
invalid_doc = parsed_data.find { |d| d[:id] == @doc_invalid.id.to_s }[:attributes]
expect(invalid_doc[:status]).to eq("doc_not_provided")
expect(invalid_doc[:"admin-comment"]).to be_nil
expect(invalid_doc[:attachment]).to eq({url: nil})
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

# TODO: try to remove the line below the comment after some time, not sure why this still not working
# see https://github.com/rails/rails/issues/49958
RSpec::Matchers::AliasedNegatedMatcher.undef_method(:with)
# somehow this does not work with spring. I have no time to debug this, only one test is failing without this line
# and mostly using spring to run single tests so this is not a problem for me
RSpec::Matchers::AliasedNegatedMatcher.undef_method(:with) unless ENV["SPRING_SPAWN_ENV"]
RSpec::Matchers.define_negated_matcher :have_not_enqueued_mail, :have_enqueued_mail

# Configuration for Shoulda::Matchers
Expand Down
Loading