diff --git a/Appraisals b/Appraisals index 68e117469..ea0409e91 100644 --- a/Appraisals +++ b/Appraisals @@ -43,7 +43,6 @@ appraise "rails-4.2-sprockets_4" do gem 'rails', '~> 4.2.1' gem "sprockets", "~> 4.0.x" gem "turbolinks", "~> 2.5.0" - gem "webpacker", github: "rails/webpacker" # This ExecJS backend provides stateful context # which the default nodejs backend does not gem "mini_racer" @@ -51,22 +50,18 @@ end appraise "rails-5_no_sprockets_webpacker" do gem 'rails', '~> 5.0.0' - gem "webpacker", github: "rails/webpacker" + gem "webpacker", '< 3.0' # This ExecJS backend provides stateful context # which the default nodejs backend does not gem "therubyracer" end appraise "rails-5-no_sprockets" do - # Appraisal adds `turbolinks` to this gemfile because it is - # present in `./Gemfile`. - # But it causes this gemfile to break, so it must be removed - # from `./gemfiles/rails_5_no_sprockets.gemfile` manually. gem 'rails', '~> 5.0.0' end appraise "rails-5.1-sprockets_4" do - gem "rails", "5.1.0.rc1" + gem "rails", "~> 5.1.0" gem "sprockets", "~> 4.0.x" gem "turbolinks", "~> 5.0.0" end diff --git a/Gemfile b/Gemfile index f79b8769c..d65e2a669 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ source 'http://rubygems.org' gemspec -# This is an optional dev-dependency, required whenever sprockets is required -gem "turbolinks" diff --git a/gemfiles/rails_3.2.gemfile b/gemfiles/rails_3.2.gemfile index 72db331b6..f93296133 100644 --- a/gemfiles/rails_3.2.gemfile +++ b/gemfiles/rails_3.2.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.0" gem "rails", "~> 3.2.21" gem "rack-cache", "~> 1.6.1" +gem "turbolinks", "~> 2.0" gemspec :path => "../" diff --git a/gemfiles/rails_4.0.5.gemfile b/gemfiles/rails_4.0.5.gemfile index e9e0ccfcf..eeb73d957 100644 --- a/gemfiles/rails_4.0.5.gemfile +++ b/gemfiles/rails_4.0.5.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "turbolinks" gem "rails", "4.0.5" +gem "turbolinks" gemspec :path => "../" diff --git a/gemfiles/rails_4.0_with_therubyracer.gemfile b/gemfiles/rails_4.0_with_therubyracer.gemfile index de6505b1c..4c854cc34 100644 --- a/gemfiles/rails_4.0_with_therubyracer.gemfile +++ b/gemfiles/rails_4.0_with_therubyracer.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks" gem "rails", "~> 4.0.13" gem "therubyracer", "0.12.0", :platform => :mri +gem "turbolinks" gemspec :path => "../" diff --git a/gemfiles/rails_4.1.gemfile b/gemfiles/rails_4.1.gemfile index 976f20e9d..80206ebca 100644 --- a/gemfiles/rails_4.1.gemfile +++ b/gemfiles/rails_4.1.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.3.0" gem "rails", "~> 4.1.10" +gem "turbolinks", "~> 2.3.0" gemspec :path => "../" diff --git a/gemfiles/rails_4.2_sprockets_2.gemfile b/gemfiles/rails_4.2_sprockets_2.gemfile index 02aeb7502..d31127374 100644 --- a/gemfiles/rails_4.2_sprockets_2.gemfile +++ b/gemfiles/rails_4.2_sprockets_2.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks" gem "rails", "~> 4.2.1" gem "sprockets", "~> 2.12" +gem "turbolinks" gemspec :path => "../" diff --git a/gemfiles/rails_4.2_sprockets_3.gemfile b/gemfiles/rails_4.2_sprockets_3.gemfile index 6ac755f7d..7bb53f889 100644 --- a/gemfiles/rails_4.2_sprockets_3.gemfile +++ b/gemfiles/rails_4.2_sprockets_3.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.5.0" gem "rails", "~> 4.2.1" gem "sprockets", "~> 3.5" +gem "turbolinks", "~> 2.5.0" gemspec :path => "../" diff --git a/gemfiles/rails_4.2_sprockets_4.gemfile b/gemfiles/rails_4.2_sprockets_4.gemfile index 2f661f0c0..e5b8484a7 100644 --- a/gemfiles/rails_4.2_sprockets_4.gemfile +++ b/gemfiles/rails_4.2_sprockets_4.gemfile @@ -2,10 +2,9 @@ source "http://rubygems.org" -gem "turbolinks", "~> 2.5.0" gem "rails", "~> 4.2.1" gem "sprockets", "~> 4.0.x" -gem "webpacker", :github => "rails/webpacker" +gem "turbolinks", "~> 2.5.0" gem "mini_racer" gemspec :path => "../" diff --git a/gemfiles/rails_5.1_sprockets_4.gemfile b/gemfiles/rails_5.1_sprockets_4.gemfile index 30ea5c1c3..7588f0512 100644 --- a/gemfiles/rails_5.1_sprockets_4.gemfile +++ b/gemfiles/rails_5.1_sprockets_4.gemfile @@ -2,8 +2,8 @@ source "http://rubygems.org" -gem "turbolinks", "~> 5.0.0" -gem "rails", "5.1.0.rc1" +gem "rails", "~> 5.1.0" gem "sprockets", "~> 4.0.x" +gem "turbolinks", "~> 5.0.0" gemspec :path => "../" diff --git a/gemfiles/rails_5_no_sprockets.gemfile b/gemfiles/rails_5_no_sprockets.gemfile index 2d5f543d0..c2b8165cf 100644 --- a/gemfiles/rails_5_no_sprockets.gemfile +++ b/gemfiles/rails_5_no_sprockets.gemfile @@ -1,5 +1,4 @@ # This file was generated by Appraisal -# This shouldn't have turbolinks or sprockets source "http://rubygems.org" diff --git a/gemfiles/rails_5_no_sprockets_webpacker.gemfile b/gemfiles/rails_5_no_sprockets_webpacker.gemfile index a424771dc..fb14d2b3b 100644 --- a/gemfiles/rails_5_no_sprockets_webpacker.gemfile +++ b/gemfiles/rails_5_no_sprockets_webpacker.gemfile @@ -1,10 +1,9 @@ # This file was generated by Appraisal -# This file shouldn't have turbolinks or sprockets in it source "http://rubygems.org" gem "rails", "~> 5.0.0" -gem "webpacker", :github => "rails/webpacker" +gem "webpacker", "< 3.0" gem "therubyracer" gemspec :path => "../" diff --git a/test/generators/coffee_component_generator_test.rb b/test/generators/coffee_component_generator_test.rb index c64342b17..089240369 100644 --- a/test/generators/coffee_component_generator_test.rb +++ b/test/generators/coffee_component_generator_test.rb @@ -19,20 +19,20 @@ def class_name 'GeneratedComponent' end - test 'that it the uses CoffeeScript syntax' do + def test_that_it_the_uses_CoffeeScript_syntax run_generator %w(GeneratedComponent name --coffee) assert_file filename, /^class @#{class_name}\sextends\sReact\.Component/ end - test 'that propTypes get assigned' do + def test_that_propTypes_get_assigned run_generator %w(GeneratedComponent name --coffee) assert_file filename, /@propTypes\s=/ assert_file filename, /React.PropTypes/ end - test 'that it generates working jsx' do + def test_that_it_generates_working_jsx expected_name_div = /React\.createElement\(\s*"div",\s*null,\s*"Name:\s*",\s*this\.props\.name\s*\)/x expected_shape_div = /React\.createElement\(\s*"div",\s*null,\s*"Address:\s*",\s*this\.props\.address\s*\)/x diff --git a/test/generators/component_generator_test.rb b/test/generators/component_generator_test.rb index efa6bd64a..afc071b25 100644 --- a/test/generators/component_generator_test.rb +++ b/test/generators/component_generator_test.rb @@ -16,7 +16,7 @@ def filename end end - test "creates the component file" do + def test_creates_the_component_file run_generator %w(GeneratedComponent) assert_file filename do |contents| @@ -27,12 +27,12 @@ def filename end end - test "creates the component file with a node argument" do + def test_creates_the_component_file_with_a_node_argument run_generator %w(GeneratedComponent name) assert_file filename, %r{name: React.PropTypes.node} end - test "creates the component file with various standard proptypes" do + def test_creates_the_component_file_with_various_standard_proptypes proptypes = %w(string bool number array func number object any) run_generator %w(GeneratedComponent) + proptypes.map { |type| "my_#{type}:#{type}" } proptypes.each do |type| @@ -40,24 +40,24 @@ def filename end end - test "creates a component file with an instanceOf property" do + def test_creates_a_component_file_with_an_instanceOf_property run_generator %w(GeneratedComponent favorite_food:instanceOf{food}) assert_file filename, /favoriteFood: React.PropTypes.instanceOf\(Food\)/ end - test "creates a component file with a oneOf property" do + def test_creates_a_component_file_with_a_oneOf_property run_generator %w(GeneratedComponent favorite_food:oneOf{pizza,hamburgers}) assert_file filename, /favoriteFood: React.PropTypes.oneOf\(\['pizza','hamburgers'\]\)/ end - test "creates a component file with a oneOfType property" do + def test_creates_a_component_file_with_a_oneOfType_property run_generator %w(GeneratedComponent favorite_food:oneOfType{string,Food}) expected_property = "favoriteFood: React.PropTypes.oneOfType([React.PropTypes.string,React.PropTypes.instanceOf(Food)])" assert_file filename, Regexp.new(Regexp.quote(expected_property)) end - test "generates working jsx" do + def test_generates_working_jsx expected_name_div = /React\.createElement\(\s*"div",\s*null,\s*\"Name:\s*\",\s*this\.props\.name\s*\)/x expected_shape_div = /React\.createElement\(\s*"div",\s*null,\s*\"Address:\s*\",\s*this\.props\.address\s*\)/x diff --git a/test/generators/es6_component_generator_test.rb b/test/generators/es6_component_generator_test.rb index 3c53d905b..ccc131214 100644 --- a/test/generators/es6_component_generator_test.rb +++ b/test/generators/es6_component_generator_test.rb @@ -20,19 +20,19 @@ def class_name 'GeneratedComponent' end - test "uses es6 syntax" do + def test_uses_es6_syntax run_generator %w(GeneratedComponent name --es6) assert_file filename, /^class\s#{class_name}\sextends\sReact\.Component/ end - test "assigns defaultProps after class definintion" do + def test_assigns_defaultProps_after_class_definintion run_generator %w(GeneratedComponent name --es6) assert_file filename, /\s^#{class_name}\.propTypes/ end - test "generates working jsx" do + def test_generates_working_jsx expected_name_div = /React\.createElement\(\s*"div",\s*null,\s*\"Name:\s*\",\s*this\.props\.name\s*\)/x expected_shape_div = /React\.createElement\(\s*"div",\s*null,\s*\"Address:\s*\",\s*this\.props\.address\s*\)/x diff --git a/test/generators/install_generator_sprockets_test.rb b/test/generators/install_generator_sprockets_test.rb index cf3f0febe..efc259018 100644 --- a/test/generators/install_generator_sprockets_test.rb +++ b/test/generators/install_generator_sprockets_test.rb @@ -16,18 +16,18 @@ def copy_directory(dir) FileUtils.cp_r source, dest end - test "adds requires to `application.js`" do + def test_adds_requires_to_application_js run_generator assert_application_file_created end - test "it modifes an existing 'application.js'" do + def test_it_modifes_an_existing_application_js copy_directory('app/assets/javascripts/application.js') run_generator assert_application_file_modified end - test "creates `application.js` if it doesn't exist" do + def test_creates_application_js_if_it_doesnt_exist copy_directory('app/assets/javascripts/application.js') File.delete destination_root + '/app/assets/javascripts/application.js' @@ -35,14 +35,14 @@ def copy_directory(dir) assert_application_file_created end - test "modifies `application.js` if it's empty" do + def test_modifies_application_js_if_its_empty init_application_js '' run_generator assert_application_file_created end - test "updates `application.js` if require_tree is commented" do + def test_updates_application_js_if_require_tree_is_commented init_application_js <<-END // // require_tree . @@ -53,7 +53,7 @@ def copy_directory(dir) assert_application_file_modified end - test "updates `application.js` if require turbolinks has extra spaces" do + def test_updates_application_js_if_require_turbolinks_has_extra_spaces init_application_js <<-END // //#{"= require turbolinks "} @@ -64,20 +64,20 @@ def copy_directory(dir) assert_application_file_modified end - test "creates server_rendering.js with default requires" do + def test_creates_server_rendering_js_with_default_requires run_generator server_rendering_file_path = "app/assets/javascripts/server_rendering.js" assert_file server_rendering_file_path, %r{//= require react-server\n} assert_file server_rendering_file_path, %r{//= require ./components\n} end - test "creates server rendering initializer" do + def test_creates_server_rendering_initializer run_generator initializer_path = "config/initializers/react_server_rendering.rb" assert_file(initializer_path, %r{Rails.application.config.assets.precompile \+= \["server_rendering.js"\]}) end - test "skipping server rendering" do + def test_skipping_server_rendering run_generator %w(--skip-server-rendering) assert_no_file "config/initializers/react_server_rendering.rb" assert_no_file "app/assets/javascripts/server_rendering.js" diff --git a/test/generators/install_generator_webpacker_test.rb b/test/generators/install_generator_webpacker_test.rb index ab7b39b9f..7ea3dbd57 100644 --- a/test/generators/install_generator_webpacker_test.rb +++ b/test/generators/install_generator_webpacker_test.rb @@ -23,13 +23,13 @@ def copy_directory(dir) FileUtils.cp_r source, dest end - test "adds requires to `application.js`" do + def test_adds_requires_to_application_js run_generator assert_file "app/javascript/packs/application.js", EXPECTED_SETUP assert_file "app/javascript/components" end - test "creates server_rendering.js with default requires" do + def test_creates_server_rendering_js_with_default_requires run_generator assert_file DEFAULT_SERVER_RENDERING_PACK_PATH do |contents| assert_includes contents, "var componentRequireContext = require.context(\"components\", true)\n" @@ -38,7 +38,7 @@ def copy_directory(dir) end end - test "skipping server rendering" do + def test_skipping_server_rendering run_generator %w(--skip-server-rendering) assert_no_file DEFAULT_SERVER_RENDERING_PACK_PATH end diff --git a/test/react/jsx/jsx_prepocessor_test.rb b/test/react/jsx/jsx_prepocessor_test.rb index 321b08485..9e4b61efc 100644 --- a/test/react/jsx/jsx_prepocessor_test.rb +++ b/test/react/jsx/jsx_prepocessor_test.rb @@ -6,7 +6,7 @@ class JSXPreprocessorTest < ActiveSupport::TestCase REQUIRED_COFFEESCRIPT = "var requireCoffee; requireCoffee = true;" REQUIRED_JSX = "React.createElement(\"div\", { className: \"require-jsx\" });" OWN_JSX = "React.createElement(\"div\", { className: \"le-javascript\" });" - test 'executes //= require directives' do + def test_executes_require_directives require_parent = SprocketsHelpers.fetch_asset_body("require_test/jsx_preprocessor_test.js") assert_compiled_javascript_includes(require_parent, REQUIRED_JAVASCRIPT) diff --git a/test/react/jsx/jsx_transformer_test.rb b/test/react/jsx/jsx_transformer_test.rb index 757454d83..637a4f153 100644 --- a/test/react/jsx/jsx_transformer_test.rb +++ b/test/react/jsx/jsx_transformer_test.rb @@ -13,7 +13,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest SprocketsHelpers.manually_expire_asset('JSXTransformer.js') end - test 'can use dropped-in version of JSX transformer' do + def test_can_use_dropped_in_version_of_JSX_transformer hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js") replacing_path = Rails.root.join("vendor/assets/react/JSXTransformer.js") @@ -27,7 +27,7 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest assert_equal 'test_confirmation_token_jsx_transformed;', @response.body.strip end - test 'accepts harmony: true option' do + def test_accepts_harmony_true_option React::JSX.transform_options = {harmony: true} get '/assets/harmony_example.js' assert_response :success @@ -37,14 +37,14 @@ class JSXTransformerTest < ActionDispatch::IntegrationTest assert_match(/active=\$__0\.active/, @response.body, "destructuring assignment") end - test 'accepts strip_types: true option' do + def test_accepts_strip_types_true_option React::JSX.transform_options = {strip_types: true, harmony: true} get '/assets/flow_types_example.js' assert_response :success assert_match(/\(i\s*,\s*name\s*\)\s*\{/, @response.body, "type annotations are removed") end - test 'accepts asset_path: option' do + def test_accepts_asset_path_option hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js") custom_path = Rails.root.join("vendor/assets/react/custom") replacing_path = custom_path.join("CustomTransformer.js") diff --git a/test/react/jsx_test.rb b/test/react/jsx_test.rb index db6270be9..6962ef299 100644 --- a/test/react/jsx_test.rb +++ b/test/react/jsx_test.rb @@ -36,21 +36,21 @@ class JSXTransformTest < ActionDispatch::IntegrationTest reset_transformer end - test 'asset pipeline should transform JSX' do + def test_asset_pipeline_should_transform_JSX SprocketsHelpers.manually_expire_asset('example.js') get '/assets/example.js' assert_response :success assert_compiled_javascript_matches(EXPECTED_JS, @response.body) end - test 'asset pipeline should transform JSX + Coffeescript' do + def test_asset_pipeline_should_transform_JSX_and_Coffeescript SprocketsHelpers.manually_expire_asset('example2.js') get '/assets/example2.js' assert_response :success assert_compiled_javascript_matches(EXPECTED_JS_2, @response.body) end - test 'use a custom transformer' do + def test_use_a_custom_transformer React::JSX.transformer_class = NullTransformer SprocketsHelpers.manually_expire_asset('example2.js') get '/assets/example2.js' diff --git a/test/react/rails/asset_variant_test.rb b/test/react/rails/asset_variant_test.rb index 29e2e8bb8..f0b0b8f63 100644 --- a/test/react/rails/asset_variant_test.rb +++ b/test/react/rails/asset_variant_test.rb @@ -5,7 +5,7 @@ def build_variant(options) React::Rails::AssetVariant.new(options) end - test 'it points to different directories for react' do + def test_it_points_to_different_directories_for_react production_variant = build_variant(variant: :production) assert_match(%r{/lib/assets/react-source/production}, production_variant.react_directory) @@ -13,12 +13,12 @@ def build_variant(options) assert_match(%r{/lib/assets/react-source/development}, development_variant.react_directory) end - test 'points to jsx transformer' do + def test_points_to_jsx_transformer variant = build_variant({}) assert_match(%r{/lib/assets/javascripts/}, variant.jsx_directory) end - test 'it includes addons if requested' do + def test_it_includes_addons_if_requested asset_variant = build_variant(addons: true) assert_equal "development-with-addons", asset_variant.react_build end diff --git a/test/react/rails/component_mount_test.rb b/test/react/rails/component_mount_test.rb index e2da64482..6696ed2cd 100644 --- a/test/react/rails/component_mount_test.rb +++ b/test/react/rails/component_mount_test.rb @@ -11,7 +11,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest @helper = React::Rails::ComponentMount.new end - test '#react_component accepts React props' do + def test_react_component_accepts_React_props html = @helper.react_component('Foo', {bar: 'value'}) expected_props = %w(data-react-class="Foo" data-react-props="{"bar":"value"}") expected_props.each do |segment| @@ -19,7 +19,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts React props with camelize_props' do + def test_react_component_accepts_React_props_with_camelize_props React::Rails::ComponentMount.camelize_props_switch = true helper = React::Rails::ComponentMount.new html = helper.react_component('Foo', {foo_bar: 'value'}) @@ -29,7 +29,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component allows camelize_props to be passed in as an option' do + def test_react_component_allows_camelize_props_to_be_passed_in_as_an_option React::Rails::ComponentMount.camelize_props_switch = false helper = React::Rails::ComponentMount.new html = helper.react_component('Foo', {foo_bar: 'value'}, camelize_props: true) @@ -47,7 +47,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts React props with camelize_props containing nested arrays' do + def test_react_component_accepts_React_props_with_camelize_props_containing_nested_arrays React::Rails::ComponentMount.camelize_props_switch = true helper = React::Rails::ComponentMount.new html = helper.react_component('Foo', {foo_bar: [{user_name: 'Ryan'}, {user_name: 'Matt'}], bar_foo: 1}) @@ -57,7 +57,7 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts jbuilder-based strings as properties' do + def test_react_component_accepts_jbuilder_based_strings_as_properties jbuilder_json = Jbuilder.new do |json| json.bar 'value' end.target! @@ -69,25 +69,25 @@ class ComponentMountTest < ActionDispatch::IntegrationTest end end - test '#react_component accepts string props with prerender: true' do + def test_react_component_accepts_string_props_with_prerender_true html = @helper.react_component('Todo', {todo: 'render on the server'}.to_json, prerender: true) assert(html.include?('data-react-class="Todo"'), "it includes attrs for UJS") assert(html.include?('>render on the server'), "it includes rendered HTML") assert(html.include?('data-reactid'), "it includes React properties") end - test '#react_component passes :static to BundleRenderer' do + def test_react_component_passes_static_to_BundleRenderer html = @helper.react_component('Todo', {todo: 'render on the server'}.to_json, prerender: :static) assert(html.include?('>render on the server'), "it includes rendered HTML") assert(!html.include?('data-reactid'), "it DOESNT INCLUDE React properties") end - test '#react_component does not include HTML properties with a static render' do + def test_react_component_does_not_include_HTML_properties_with_a_static_render html = @helper.react_component('Todo', {todo: 'render on the server'}.to_json, prerender: :static) assert_equal('