Skip to content

Commit

Permalink
Merge pull request #1205 from mikz/integration-test
Browse files Browse the repository at this point in the history
formtastic integration test
  • Loading branch information
mikz committed Mar 27, 2016
2 parents 382091a + 9a99664 commit de8710f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,3 +15,4 @@ Gemfile.lock
doc/
tmp
gemfiles/*.lock
/dummy/
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -11,10 +11,12 @@ gemfile:
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_4.2.gemfile
- gemfiles/rails_edge.gemfile
env:
before_install:
- gem install bundler --version 1.11.2
script: "bundle exec rake spec"
- export BUNDLE_PATH="${TRAVIS_BUILD_DIR}/vendor/bundle"
script:
- bundle exec rake spec
- script/integration.sh
matrix:
exclude:
- rvm: 1.9.3
Expand Down
59 changes: 59 additions & 0 deletions script/integration-template.rb
@@ -0,0 +1,59 @@
gem 'formtastic', path: '..'
gem 'bcrypt', '~> 3.1.7'
gem 'rails-dom-testing', group: :test

# to speed up travis install, reuse the bundle path
def bundle_path
File.expand_path ENV.fetch('BUNDLE_PATH', 'vendor/bundle'), ENV['TRAVIS_BUILD_DIR']
end

if File.directory?(bundle_path) && bundle_install?
def run_bundle
bundle_command("install --jobs=3 --retry=3 --path=#{bundle_path}")
end
end

in_root do
ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile')
end

formtastic = -> do
generate(:scaffold, 'user name:string password_digest:string')
generate('formtastic:install')
generate('formtastic:form', 'user name password:password --force')

rake('db:migrate')

in_root do
inject_into_file 'app/models/user.rb', " has_secure_password\n", after: "< ActiveRecord::Base\n"
inject_into_file 'app/assets/stylesheets/application.css', " *= require formtastic\n", before: ' *= require_self'
inject_into_file 'test/controllers/users_controller_test.rb', <<-RUBY, before: ' test "should get edit" do'
test "should show form" do
get :edit, id: @user
assert_select "form" do
assert_select 'li.input.string' do
assert_select 'input#user_name[type=text]'
end
assert_select 'li.input.password' do
assert_select 'input#user_password[type=password]'
end
assert_select 'fieldset.actions' do
assert_select 'li.action.input_action' do
assert_select 'input[type=submit]'
end
end
end
end
RUBY
end
end

if respond_to?(:after_bundle) # Rails >= 4.2
after_bundle(&formtastic)
else # Rails 4.1
run_bundle
formtastic.call
end
17 changes: 17 additions & 0 deletions script/integration.sh
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

set -e
set -o verbose

test_app=dummy

rm -rf ${test_app}

bundle exec rails new ${test_app} \
--template=$(dirname "$0")/integration-template.rb \
--skip-spring \
--skip-turbolinks

cd ${test_app} && export BUNDLE_GEMFILE=Gemfile

bundle exec rake test

0 comments on commit de8710f

Please sign in to comment.