Skip to content

Commit 2eb024b

Browse files
committed
Merge branch 'fix/operator-document-api' into staging
2 parents b010f99 + dcfaa0e commit 2eb024b

File tree

10 files changed

+70
-10
lines changed

10 files changed

+70
-10
lines changed

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ group :development, :test do
114114
gem "faker"
115115
gem "parallel_tests"
116116
gem "rails-erd"
117-
gem "rubocop-rails"
118-
gem "standard"
117+
gem "rubocop-rails", require: false
118+
gem "standard", require: false
119119
gem "webmock"
120120
end
121121

@@ -149,6 +149,7 @@ group :test do
149149
gem "rspec-request_snapshot", github: "tsubik/rspec-request_snapshot", branch: "fix/ignore-order"
150150
gem "shoulda-matchers", "~> 4.0.1"
151151
gem "simplecov"
152+
gem "spring-commands-rspec"
152153
gem "super_diff"
153154
end
154155

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ GEM
724724
simplecov_json_formatter (~> 0.1)
725725
simplecov-html (0.13.1)
726726
simplecov_json_formatter (0.1.4)
727+
spring (4.3.0)
728+
spring-commands-rspec (1.0.4)
729+
spring (>= 0.9.1)
727730
sprockets (4.2.2)
728731
concurrent-ruby (~> 1.0)
729732
logger
@@ -884,6 +887,7 @@ DEPENDENCIES
884887
shoulda-matchers (~> 4.0.1)
885888
sidekiq
886889
simplecov
890+
spring-commands-rspec
887891
sprockets-rails
888892
standard
889893
super_diff

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ bundle exec rake parallel:drop
171171

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

174+
### Running single test faster with spring ###
175+
176+
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:
177+
178+
```ruby
179+
bin/rspec spec/models/user_spec.rb
180+
```
181+
182+
or just prepend spring to the command:
183+
184+
```ruby
185+
bundle exec spring rspec spec/models/user_spec.rb
186+
```
187+
174188
## DOCUMENTATION ##
175189

176190
### API ###

app/resources/concerns/operator_documentable.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ def status
4141
return @model.status if can_see_document?
4242
return @model.status if document_public? && %w[doc_not_provided doc_valid doc_expired doc_not_required].include?(@model.status)
4343

44-
:doc_not_provided
44+
"doc_not_provided"
4545
end
4646

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

50-
{url: nil}
50+
@model&.document_file&.attachment
5151
end
5252

5353
def attachment=(attachment)

bin/rspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env ruby
2+
load File.expand_path("spring", __dir__)
3+
require 'bundler/setup'
4+
load Gem.bin_path('rspec-core', 'rspec')

bin/spring

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
# This file loads Spring without loading other gems in the Gemfile in order to be fast.
4+
# It gets overwritten when you run the `spring binstub` command.
5+
6+
if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
7+
require "bundler"
8+
9+
Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
10+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
11+
gem "spring", spring.version
12+
require "spring/binstub"
13+
end
14+
end

config/environments/test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
Rails.application.configure do
1010
# Settings specified here will take precedence over those in config/application.rb.
1111

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

1515
# Eager loading loads your entire application. When running a single test locally,
1616
# this is usually not necessary, and can slow down your test suite. However, it's

spec/integration/v1/operator_document_histories_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ module V1
129129
public: false,
130130
note: "notes"
131131
)
132-
@doc_invalid.update(status: "doc_invalid", admin_comment: "invalid")
133-
@doc_valid_private.update(status: "doc_valid")
132+
@doc_invalid.update!(status: "doc_invalid", admin_comment: "invalid")
133+
@doc_valid_private.update!(status: "doc_valid")
134134
end
135135

136136
context "when admin" do
@@ -145,6 +145,7 @@ module V1
145145

146146
expect(parsed_data.count).to eql(2)
147147
expect(returned_document[:status]).to eq("doc_invalid")
148+
expect(returned_document[:attachment]).to eq({url: @doc_invalid.document_file.attachment.url})
148149
end
149150
end
150151

@@ -160,6 +161,8 @@ module V1
160161

161162
expect(parsed_data.count).to eql(2)
162163
expect(returned_document[:status]).to eq("doc_not_provided")
164+
expect(returned_document[:"admin-comment"]).to be_nil
165+
expect(returned_document[:attachment]).to eq({url: nil})
163166
end
164167

165168
context "with signed publication authorization" do
@@ -179,6 +182,12 @@ module V1
179182
expect(returned_document[:"response-date"]).to eq(@doc_valid_private.response_date.iso8601(3))
180183
expect(returned_document[:"updated-at"]).not_to be_nil
181184
expect(returned_document[:"created-at"]).not_to be_nil
185+
expect(returned_document[:attachment]).to eq({url: @doc_valid_private.document_file.attachment.url})
186+
187+
invalid_doc = parsed_data.find { |d| d[:attributes][:"operator-document-id"] == @doc_invalid.id }[:attributes]
188+
expect(invalid_doc[:status]).to eq("doc_not_provided")
189+
expect(invalid_doc[:"admin-comment"]).to be_nil
190+
expect(invalid_doc[:attachment]).to eq({url: nil})
182191
end
183192
end
184193

@@ -192,12 +201,18 @@ module V1
192201
returned_document = parsed_data.find { |d| d[:attributes][:"operator-document-id"] == @doc_valid_private.id }[:attributes]
193202
expect(parsed_data.count).to eql(2)
194203
expect(returned_document[:status]).to eq("doc_not_provided")
204+
expect(returned_document[:attachment]).to eq({url: nil})
195205
expect(returned_document[:"start-date"]).to be_nil
196206
expect(returned_document[:"expire-date"]).to be_nil
197207
expect(returned_document[:"response-date"]).to be_nil
198208
expect(returned_document[:note]).to be_nil
199209
expect(returned_document[:"updated-at"]).to be_nil
200210
expect(returned_document[:"created-at"]).to be_nil
211+
212+
invalid_doc = parsed_data.find { |d| d[:attributes][:"operator-document-id"] == @doc_invalid.id }[:attributes]
213+
expect(invalid_doc[:status]).to eq("doc_not_provided")
214+
expect(invalid_doc[:"admin-comment"]).to be_nil
215+
expect(invalid_doc[:attachment]).to eq({url: nil})
201216
end
202217
end
203218
end

spec/integration/v1/operator_documents_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def sign_publication_authorization!
6363
expect(parsed_data.count).to eql(10)
6464
expect(returned_document[:status]).to eq("doc_invalid")
6565
expect(returned_document[:"admin-comment"]).to eq("invalid")
66+
expect(returned_document[:attachment]).to eq({url: @doc_invalid.document_file.attachment.url})
6667
end
6768

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

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

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

@@ -124,6 +128,7 @@ def sign_publication_authorization!
124128
returned_document = parsed_data.find { |d| d[:id] == @doc_valid_private.id.to_s }[:attributes]
125129
expect(parsed_data.count).to eql(9)
126130
expect(returned_document[:status]).to eq("doc_not_provided")
131+
expect(returned_document[:attachment]).to eq({url: nil})
127132
expect(returned_document[:"start-date"]).to be_nil
128133
expect(returned_document[:"expire-date"]).to be_nil
129134
expect(returned_document[:"response-date"]).to be_nil
@@ -134,6 +139,7 @@ def sign_publication_authorization!
134139
invalid_doc = parsed_data.find { |d| d[:id] == @doc_invalid.id.to_s }[:attributes]
135140
expect(invalid_doc[:status]).to eq("doc_not_provided")
136141
expect(invalid_doc[:"admin-comment"]).to be_nil
142+
expect(invalid_doc[:attachment]).to eq({url: nil})
137143
end
138144
end
139145
end

spec/rails_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

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

3032
# Configuration for Shoulda::Matchers

0 commit comments

Comments
 (0)