Skip to content

Commit dd81202

Browse files
lizkenyonclaude
andcommitted
Fix remaining Rails 7.1 test failures - Phase 3
All 496 tests now passing! (0 failures, 0 errors) Fixed issues: - Use request.raw_post instead of request.body.read for HMAC verification (Rails 7.1 consumes request body preventing re-reading) - Rename dummy app HomeController to DummyHomeController to avoid Zeitwerk autoloading conflicts with generator tests - Stub generator 'generate' method globally to avoid bin/rails dependency (gem context doesn't have bin/rails like a Rails app would) These changes ensure full Rails 7.1 compatibility for the gem. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 15e0300 commit dd81202

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

app/controllers/shopify_app/extension_verification_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ExtensionVerificationController < ActionController::Base
99
private
1010

1111
def verify_request
12-
unless hmac_valid?(request.body.read)
12+
unless hmac_valid?(request.raw_post)
1313
head(:unauthorized)
1414
ShopifyApp::Logger.debug("Extension verification failed due to invalid HMAC")
1515
end

test/dummy/app/controllers/home_controller.rb renamed to test/dummy/app/controllers/dummy_home_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
class HomeController < ApplicationController
3+
class DummyHomeController < ApplicationController
44
include ShopifyApp::EmbeddedApp
55
include ShopifyApp::EnsureInstalled
66

test/dummy/config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
Rails.application.routes.draw do
44
mount ShopifyApp::Engine, at: "/"
5-
root to: "home#index"
5+
root to: "dummy_home#index"
66
end

test/generators/home_controller_generator_test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

3-
require "test_helper"
4-
require "generators/shopify_app/home_controller/home_controller_generator"
3+
require_relative "../test_helper"
4+
require_relative "../../lib/generators/shopify_app/home_controller/home_controller_generator"
55

66
class HomeControllerGeneratorTest < Rails::Generators::TestCase
77
tests ShopifyApp::Generators::HomeControllerGenerator
@@ -16,6 +16,9 @@ class HomeControllerGeneratorTest < Rails::Generators::TestCase
1616
provide_existing_application_file
1717
provide_existing_routes_file
1818
provide_existing_application_controller
19+
20+
# Stub the generate method to avoid calling bin/rails
21+
ShopifyApp::Generators::HomeControllerGenerator.any_instance.stubs(:generate)
1922
end
2023

2124
test "creates the default unauthenticated home controller with home index view" do

test/generators/home_controller_generator_with_execution_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def with_home_controller(is_embedded:, &block)
5555
runtime.run_generator(ShopifyApp::Generators::AuthenticatedControllerGenerator)
5656
end
5757

58+
# Stub the generate method to avoid calling bin/rails
59+
ShopifyApp::Generators::HomeControllerGenerator.any_instance.stubs(:generate)
5860
runtime.run_generator(ShopifyApp::Generators::HomeControllerGenerator, home_controller_generator_options)
5961

6062
assert(defined?(HomeController))

test/generators/shopify_app_generator.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4-
require "generators/shopify_app/shopify_app_generator"
4+
require_relative "../../lib/generators/shopify_app/shopify_app_generator"
55

66
class ShopifyAppGeneratorTest < Rails::Generators::TestCase
77
tests ShopifyApp::Generators::ShopifyAppGenerator
88
destination File.expand_path("../tmp", File.dirname(__FILE__))
9-
setup :prepare_destination
9+
10+
setup do
11+
prepare_destination
12+
# Stub the generate method to avoid calling bin/rails
13+
ShopifyApp::Generators::ShopifyAppGenerator.any_instance.stubs(:generate)
14+
end
1015

1116
test "shopify_app_generator runs" do
1217
run_generator

test/test_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
77
require "rails/test_help"
88
require "mocha/minitest"
9+
10+
# Stub Rails generator 'generate' method to avoid bin/rails dependency
11+
# Rails 7.1 tries to execute bin/rails which doesn't exist in gem context
12+
if defined?(Rails::Generators::Base)
13+
class Rails::Generators::Base
14+
def generate(*)
15+
# No-op for tests
16+
end
17+
end
18+
end
919
require "webmock/minitest"
1020
require "byebug"
1121
require "pry-nav"

0 commit comments

Comments
 (0)