Skip to content

Commit

Permalink
rails 5 integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Mar 28, 2016
1 parent 4f54536 commit 6c5a48e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/formtastic/helpers/input_helper.rb
Expand Up @@ -299,6 +299,8 @@ def default_input_type(method, options = {}) # @private
end

# Get a column object for a specified attribute method - if possible.
# @return [ActiveModel::Type::Value, #type] in case of rails 5 attributes api
# @return [ActiveRecord::ConnectionAdapters::Column] in case of rails 4
def column_for(method) # @private
case
when @object.class.respond_to?(:type_for_attribute)
Expand Down
10 changes: 5 additions & 5 deletions script/integration-template.rb
Expand Up @@ -18,21 +18,21 @@ def run_bundle
end

formtastic = -> do
generate(:scaffold, 'user name:string password_digest:string')
generate(:scaffold, 'user name:string password:digest')
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_class 'app/models/user.rb', 'User', " has_secure_password\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'
inject_into_class 'test/controllers/users_controller_test.rb', 'UsersControllerTest', <<-RUBY
test "should show form" do
get :edit, id: @user
assert_select "form" do
assert_select 'form' do
assert_select 'li.input.string' do
assert_select 'input#user_name[type=text]'
end
Expand All @@ -46,7 +46,7 @@ def run_bundle
end
end
end
end
end # test "should show form"
RUBY
end

Expand Down
22 changes: 22 additions & 0 deletions script/integration/rails-5-0.rb
@@ -0,0 +1,22 @@
gsub_file 'test/controllers/users_controller_test.rb', 'get :edit, id: @user', 'get edit_user_url(@user)'

inject_into_class 'app/models/user.rb', 'User', <<-RUBY
class TokenType < ActiveRecord::Type::String
def type; :password; end
end
attribute :token, TokenType.new
RUBY

inject_into_file 'app/views/users/_form.html.erb', <<-HTML, after: '<%= f.input :password %>'
<%= f.input :token %>
HTML

inject_into_file 'test/controllers/users_controller_test.rb', <<-RUBY, before: 'end # test "should show form"'
assert_select 'li#user_token_input.password' do
assert_select 'input#user_token[type=password]'
end
RUBY

generate 'migration', 'AddTokenToUsers token:string'
rake 'db:migrate'

0 comments on commit 6c5a48e

Please sign in to comment.