Skip to content

Commit

Permalink
Add a version guard to generated feature spec
Browse files Browse the repository at this point in the history
The goal is to avoid using the deprecated Module#parent method in Rails 6 apps.
  • Loading branch information
Joel Lubrano committed Sep 6, 2019
1 parent 20d9152 commit 69f79cd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/stitches/generator_files/spec/features/api_spec.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,22 @@ feature "general API stuff" do
failure_message do
correct_code,_ = evaluate_response(response)
if correct_code
"Expected WWW-Authenticate header to be 'CustomKeyAuth realm=#{Rails.application.class.parent.to_s}', but was #{response['WWW-Authenticate']}"
"Expected WWW-Authenticate header to be 'CustomKeyAuth realm=#{realm}', but was #{response['WWW-Authenticate']}"
else
"Expected response to be 401, but was #{response.response_code}"
end
end

def realm
<% if ::Rails::VERSION::MAJOR >= 6 -%>
Rails.application.class.module_parent.to_s
<% else %>
Rails.application.class.parent.to_s
<% end %>
end

def evaluate_response(response)
[response.response_code == 401, response.headers["WWW-Authenticate"] == "CustomKeyAuth realm=#{Rails.application.class.parent.to_s}" ]
[response.response_code == 401, response.headers["WWW-Authenticate"] == "CustomKeyAuth realm=#{realm}"]
end
end
end

0 comments on commit 69f79cd

Please sign in to comment.