ruby/run-basic-rails-application/runtest.sh
Jun Aruga 77206c7b41 run-basic-rails-application: Use Rails RPM to run Rails application server
When running `rails new app` running the `bundle install` internally on the
rubygem-rails RPM version 7.0.8, the command tries to install the upstream
rails gem version 7.0.8.7, and that triggers the following error.

This commit fixes the error by using the rubygem-rails RPM version 7.0.8 rather
than installing the upstream rails 7.0.8.7.

```
$ tmt -c distro=fedora-rawhide run --all provision -h virtual -i fedora-rawhide tests -n '^/run-basic-rails-application$'
/var/tmp/tmt/run-039
...

$ tmt run --id run-039 report -vvv
...
                    :: [ 13:37:43 ] :: [  BEGIN   ] :: Creating new rails application :: actually running 'rails new app | tee bundle.log'
...
                    Bundle complete! 14 Gemfile dependencies, 78 gems now installed.
                    Use `bundle info [gemname]` to see where a bundled gem is installed.
                    1 installed gem you directly depend on is looking for funding.
                      Run `bundle fund` for details
                             run  bundle binstubs bundler
                           rails  importmap:install
                    /usr/local/share/gems/gems/activesupport-7.0.8.7/lib/active_support/logger_thread_safe_level.rb:12:in '<module:LoggerThreadSafeLevel>': uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)

                        Logger::Severity.constants.each do |severity|
                        ^^^^^^
...
```
2025-02-20 14:48:22 +01:00

69 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/rubygem-rails/run-basic-rails-application
# Description: Test creates new rails application and runs it
# Author: Iveta Senfeldova <isenfeld@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2012 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh
PACKAGES=${PACKAGES:-ruby rubygems rubypick}
REQUIRES=${REQUIRES:-}
RUBY=${RUBY:-ruby}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlAssertBinaryOrigin $RUBY
rlAssertBinaryOrigin "gem"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
rlRun "rails new app --skip-bundle" 0 "Creating new rails application"
rlRun "pushd app/"
rlAssertExists "app"
rlRun "sed -i.orig -E -e '/^gem \"rails\"/ s/~> //' Gemfile" 0 \
"Updating Gemfile to ensure Rails RPM version is used"
rlRun -t "diff Gemfile.orig Gemfile" 1 \
"Printing the Gemfile modifications"
rlRun "bundle install" 0 "Installing dependencies specified in Gemfile"
rlRun "rails -v > /dev/null" "0" "Printing rails version"
rlRun "test $(rails -v | cut -d' ' -f 2) = $(rpm -q --qf '%{VERSION}' rubygem-rails)" \
0 "Ensuring rails command version is same with Rails RPM version"
rlRun "ss -tulpn | grep 3000" 1 "Check if port 3000 isn't engaged"
rlRun "rails server &" 0 "Running rails server"
sleep 10
rlRun "wget http://0.0.0.0:3000" 0 "Wgetting running rails application"
rlRun "pkill ruby" 0 "Killing rails server"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd; popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd