%global gem_name railties
%bcond_with  test
%{?_with_bootstrap: %global bootstrap 1}
%global bootstrap 1
Name:                rubygem-%{gem_name}
Version:             5.2.4.4
Release:             4
Summary:             Tools for creating, working with, and running Rails applications
License:             MIT
URL:                 http://rubyonrails.org
Source0:             https://rubygems.org/gems/%{gem_name}-%{version}.gem
Source1:             https://github.com/rails/rails/archive/v%{version}.tar.gz
# Check value of result.source_location in
# test_unit/reporter.rb#format_rerun_snippet
# https://github.com/rails/rails/pull/32297
Patch0:              rubygem-railties-5.1.5-check-value-of-result-source-location.patch
Suggests:            %{_bindir}/sqlite3
BuildRequires:       ruby(release) rubygems-devel ruby >= 2.2.2 rubygem(actioncable) = %{version}
BuildRequires:       rubygem(actionmailer) = %{version} rubygem(actionpack) = %{version}
BuildRequires:       rubygem(activerecord) = %{version} rubygem(activesupport) = %{version}
BuildRequires:       rubygem(activestorage) = %{version} rubygem(bundler) rubygem(method_source)
BuildRequires:       rubygem(rake) >= 0.8.7 rubygem(rack-cache) rubygem(sqlite3) rubygem(puma)
BuildRequires:       rubygem(bootsnap) rubygem(capybara) sqlite rubygem(sprockets-rails)
BuildRequires:       rubygem(thor) >= 0.18.1 rubygem(turbolinks) git
%if ! 0%{?bootstrap}
BuildRequires:       rubygem(jquery-rails) rubygem(uglifier) rubygem(rails) %{_bindir}/node
%endif
Requires:            rubygem(bundler) ruby-devel sqlite-devel
BuildArch:           noarch
%description
Rails internals: application bootup, plugins, generators, and rake tasks.
Railties is responsible to glue all frameworks together. Overall, it:
* handles all the bootstrapping process for a Rails application;
* manages rails command line interface;
* provides Rails generators core;

%package doc
Summary:             Documentation for %{name}
Requires:            %{name} = %{version}-%{release}
BuildArch:           noarch
%description doc
Documentation for %{name}.

%prep
%setup -q -c -T
%gem_install -n %{SOURCE0}
pushd .%{gem_instdir}
%patch0 -p2
popd

%build

%install
mkdir -p %{buildroot}%{gem_dir}
cp -a .%{gem_dir}/* \
        %{buildroot}%{gem_dir}/
mkdir -p %{buildroot}%{_bindir}
cp -p .%{_bindir}/* \
        %{buildroot}%{_bindir}/
find %{buildroot}%{gem_instdir}/exe -type f | xargs chmod a+x

%if %{with test}
%check
ln -s %{gem_dir}/specifications/rails-%{version}.gemspec .%{gem_dir}/gems/rails.gemspec
ln -s %{gem_dir}/gems/activesupport-%{version}/ .%{gem_dir}/gems/activesupport
ln -s %{gem_dir}/gems/activestorage-%{version}/ .%{gem_dir}/gems/activestorage
ln -s %{gem_dir}/gems/actionmailer-%{version}/ .%{gem_dir}/gems/actionmailer
ln -s %{gem_dir}/gems/activerecord-%{version}/ .%{gem_dir}/gems/activerecord
ln -s %{gem_dir}/gems/actionview-%{version}/ .%{gem_dir}/gems/actionview
ln -s %{gem_dir}/gems/actioncable-%{version}/ .%{gem_dir}/gems/actioncable
ln -s ${PWD}%{gem_instdir} .%{gem_dir}/gems/railties
pushd .%{gem_dir}/gems/railties
tar xzf %{SOURCE1}
ln -s rails-%{version}/railties/test test
echo '%{version}' > ../RAILS_VERSION
touch ../Gemfile
echo 'gem "actioncable"' >> ../Gemfile
echo 'gem "actionmailer"' >> ../Gemfile
echo 'gem "actionpack"' >> ../Gemfile
echo 'gem "activerecord"' >> ../Gemfile
echo 'gem "activesupport"' >> ../Gemfile
echo 'gem "activestorage"' >> ../Gemfile
echo 'gem "method_source"' >> ../Gemfile
echo 'gem "rack-test"' >> ../Gemfile
echo 'gem "rack-cache"' >> ../Gemfile
echo 'gem "rake"' >> ../Gemfile
echo 'gem "rdoc"' >> ../Gemfile
echo 'gem "sqlite3"' >> ../Gemfile
echo 'gem "thor"' >> ../Gemfile
echo 'gem "turbolinks"' >> ../Gemfile
echo 'gem "sprockets-rails"' >> ../Gemfile
echo 'gem "puma"' >> ../Gemfile
echo 'gem "bootsnap"' >> ../Gemfile
echo 'gem "capybara"' >> ../Gemfile
echo 'gem "irb"' >> ../Gemfile
%if ! 0%{?bootstrap}
echo 'gem "jquery-rails"' >> ../Gemfile
echo 'gem "rails"' >> ../Gemfile
echo 'gem "uglifier", require: false' >> ../Gemfile
%else
mv test/application/assets_test.rb{,.disable}
mv test/application/asset_debugging_test.rb{,.disable}
sed -i '/def test_scaffold_.*tests_pass_by_default$/,/^    end$/ s/^/#/' test/application/rake_test.rb
sed -i '/def test_rake_routes_with_rake_options$/,/^    end$/ s/^/#/' test/application/rake_test.rb
sed -i '/def test_rails_routes_displays_message_when_no_routes_are_defined$/,/^    end$/ s/^/#/' test/application/rake_test.rb
sed -i '/def test_rails_routes_calls_the_route_inspector$/,/^    end$/ s/^/#/' test/application/rake_test.rb
sed -i '/def test_generated_controller_works_with_rails_test$/,/^    end$/ s/^/#/' test/application/test_runner_test.rb
sed -i '/def test_generated_scaffold_works_with_rails_test$/,/^    end$/ s/^/#/' test/application/test_runner_test.rb
mv test/application/bin_setup_test.rb{,.disable}
mv test/test_unit/reporter_test.rb{,.disable}
mv test/application/configuration/custom_test.rb{,.disable}
sed -i '/def test_generation_runs_bundle_install_with_full_and_mountable$/,/^  end$/ s/^/#/' test/generators/plugin_generator_test.rb
sed -i '/def test_generate_application_.*_when_does_not_exist_in_mountable_engine$/,/^  end$/ s/^/#/' test/generators/plugin_generator_test.rb
sed -i '/def test_controller_tests_pass_by_default_inside_mountable_engine$/,/^  end$/ s/^/#/' test/generators/scaffold_controller_generator_test.rb
sed -i '/def test_controller_tests_pass_by_default_inside_full_engine$/,/^  end$/ s/^/#/' test/generators/scaffold_controller_generator_test.rb
sed -i '/def test_application_new_exits_with_message_and_non_zero_code_when_generating_inside_existing_rails_directory$/,/^  end$/ s/^/#/' test/generators/app_generator_test.rb
sed -i '/def test_application_new_show_help_message_inside_existing_rails_directory$/,/^  end$/ s/^/#/' test/generators/app_generator_test.rb
%endif
sed -i '/^  def test_sqlite3_db_without_defined_rails_root$/,/^  end$/ s/^/#/' test/commands/dbconsole_test.rb
sed -i '/test "database middleware doesn.t initialize when activerecord is not in frameworks" do$/,/^    end$/ s/^/#/' \
  test/application/initializers/frameworks_test.rb
sed -i '/test "i18n files have lower priority than application ones" do$/,/^    end$/ s/^/#/' \
  test/railties/engine_test.rb
sed -i '/def test_system_tests_are_run_through_rake_test_when_given_in_TEST$/,/^    end$/ s/^/#/' \
  test/application/test_runner_test.rb
sed -i '/def test_reset_sessions_before_rollback_on_system_tests$/,/^    end$/ s/^/#/' \
  test/application/test_runner_test.rb
sed -i '/def test_output_inline_by_default$/,/^  end$/ s/^/#/' \
  test/generators/plugin_test_runner_test.rb
mv test/application/rake/dbs_test.rb{,.disable}
mv test/commands/dbconsole_test.rb{,.disable}
sed -i '/^  def test_new_application_load_defaults$/,/^  end$/ s/^/#/' \
  test/generators/app_generator_test.rb
sed -i 's/^\(\s*secrets\.secret_\)token/\1key_base/' \
  test/path_generation_test.rb
export RUBYOPT="-I${PWD}/../railties/lib"
export PATH="${PWD}/../railties/exe:$PATH"
export BUNDLE_GEMFILE=${PWD}/../Gemfile
find test -type f -name '*_test.rb' -print0 | \
  sort -z | \
  xargs -0 -n1 -i sh -c "echo '* Test file: {}'; ruby -Itest -- '{}' || exit 255"
popd
%endif

%files
%dir %{gem_instdir}
%{_bindir}/rails
%license %{gem_instdir}/MIT-LICENSE
%{gem_instdir}/exe
%{gem_libdir}
%exclude %{gem_cache}
%{gem_spec}

%files doc
%doc %{gem_docdir}
%doc %{gem_instdir}/CHANGELOG.md
%doc %{gem_instdir}/RDOC_MAIN.rdoc
%doc %{gem_instdir}/README.rdoc

%changelog
* Tue Apr  6 2021 lingsheng <lingsheng@huawei.com> - 5.2.4.4-4
- Add requires ruby-devel sqlite-devel

* Tue Apr  6 2021 lingsheng <lingsheng@huawei.com> - 5.2.4.4-3
- Add requires rubygem(bundler)

* Mon Feb  8 2021 sunguoshuai <sunguoshuai@huawei.com> - 5.2.4.4-1
- Upgrade to 5.2.4.4

* Sat Sep 5 2020 liyanan <liyanan32@huawei.com> - 5.2.3-2
- fix build fail

* Tue Aug 18 2020 huangyangke <huangyangke@huawei.com> - 5.2.3-1
- package init
