Blob Blame History Raw
#!/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
[ -e /usr/bin/rhts-environment.sh ] && . /usr/bin/rhts-environment.sh
. /usr/share/beakerlib/beakerlib.sh

PACKAGES=${PACKAGES:-ruby rubygems rubypick}
REQUIRES=${REQUIRES:-}
RUBY=${RUBY:-ruby}
RAILS=0
bundle=""
ARCH=$(uname -m)
RAILSVER=""

# version of Ruby on RHEL7 needs older version of rails
if rlIsRHEL 7; then RAILSVER="-v 4.2.7"; NOKOVER="-v 1.6.8"; fi

rlJournalStart
    rlPhaseStartSetup
        rlAssertRpm --all
        rlAssertBinaryOrigin $RUBY
        rlAssertBinaryOrigin "gem"
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
        rlRun "pushd $TmpDir"

        # install rails and nokogiri from gem if not found in installation
        if ! gem list "^rails *$" -i
        then
            # nokogiri gem installed with rails needs to use system libraries
            # on arm and ppcle otherwise it fails with bundled libraries
            if [ "x$ARCH" = "xaarch64" ] || [ "x$ARCH" = "xppc64le" ]
            then
                export NOKOGIRI_USE_SYSTEM_LIBRARIES=yes
            fi
            rlRun "gem install nokogiri $NOKOVER --no-document" 0 "Installing nokogiri $NOKOVER without documentation"
            rlRun "gem install rails $RAILSVER --no-document" 0 "Installing rails $RAILSVER without documentation"
            RAILS=1
        fi
    rlPhaseEnd

    rlPhaseStartTest
        rlRun "rails new app | tee bundle.log" 0 "Creating new rails application"
        [ ! -z "$COLLECTIONS" ] && rlAssertGrep "bundle install --local" bundle.log || rlAssertNotGrep "bundle install --local" bundle.log
        rlRun "pushd app/"
        rlAssertExists "app"

        if [[ ! "$COLLECTIONS" =~ "rh-ror50" ]]
        then
            rlRun "echo \"gem 'therubyracer'\" >> Gemfile" 0 "Adding therubyracer gem into Gemfile"
            rlRun "bundle install"
        fi

        if [ -z "$COLLECTIONS" ] && rlIsRHEL '<=7'
        then
            rlRun "echo \"gem 'nokogiri', '1.6.8'\" >> Gemfile" 0 "Adding nokogiri gem into Gemfile"
            sed -i "s/gem 'spring'/#gem 'spring'/" Gemfile
            rlRun "gem pristine nokogiri" 0 "Restore installed nokogiri to pristine condition"
            rlRun "bundle config build.nokogiri --use-system-libraries" 0 "Build nokogiri with system libraries"
            rlRun "bundle install"
        fi
        rlRun "netstat -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"
        [ $RAILS == 1 ] && rlRun "gem uninstall rails nokogiri minitest -a -I -x" 0 "Removing rails and nokogiri gem"
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
    rlPhaseEnd
rlJournalPrintText
rlJournalEnd