diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
new file mode 100644
index 0000000..4b90004
--- /dev/null
+++ b/.github/workflows/tests.yml
@@ -0,0 +1,34 @@
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
+# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
+
+name: build
+
+on: [push, pull_request]
+
+jobs:
+ test:
+ runs-on: ubuntu-20.04
+ strategy:
+ fail-fast: false
+ matrix:
+ gemfile: ['rails_7.1', 'rails_7.0', 'rails_6.1']
+ ruby: [3.2, 3.1, '3.0', 2.7]
+ include:
+ - gemfile: rails_6.0
+ ruby: 2.7
+ - gemfile: rails_5.2
+ ruby: 2.7
+
+ env:
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
+ steps:
+ - uses: actions/checkout@v2
+ - uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: ${{ matrix.ruby }}
+ bundler-cache: true
+ - run: bundle exec rake test
diff --git a/.gitignore b/.gitignore
index 93f8653..5474e47 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
.bundle
-pkg
\ No newline at end of file
+pkg
+*emfile.lock
+*.gem
+*.swp
diff --git a/Gemfile b/Gemfile
index 50497f8..77316b1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,3 @@
source 'http://rubygems.org'
-gem 'rails', '3.0.0'
-gem 'mocha'
\ No newline at end of file
+gemspec path: '.'
diff --git a/Gemfile.lock b/Gemfile.lock
deleted file mode 100644
index f6b76cc..0000000
--- a/Gemfile.lock
+++ /dev/null
@@ -1,74 +0,0 @@
-GEM
- remote: http://rubygems.org/
- specs:
- abstract (1.0.0)
- actionmailer (3.0.0)
- actionpack (= 3.0.0)
- mail (~> 2.2.5)
- actionpack (3.0.0)
- activemodel (= 3.0.0)
- activesupport (= 3.0.0)
- builder (~> 2.1.2)
- erubis (~> 2.6.6)
- i18n (~> 0.4.1)
- rack (~> 1.2.1)
- rack-mount (~> 0.6.12)
- rack-test (~> 0.5.4)
- tzinfo (~> 0.3.23)
- activemodel (3.0.0)
- activesupport (= 3.0.0)
- builder (~> 2.1.2)
- i18n (~> 0.4.1)
- activerecord (3.0.0)
- activemodel (= 3.0.0)
- activesupport (= 3.0.0)
- arel (~> 1.0.0)
- tzinfo (~> 0.3.23)
- activeresource (3.0.0)
- activemodel (= 3.0.0)
- activesupport (= 3.0.0)
- activesupport (3.0.0)
- arel (1.0.1)
- activesupport (~> 3.0.0)
- builder (2.1.2)
- erubis (2.6.6)
- abstract (>= 1.0.0)
- i18n (0.4.1)
- mail (2.2.5)
- activesupport (>= 2.3.6)
- mime-types
- treetop (>= 1.4.5)
- mime-types (1.16)
- mocha (0.9.8)
- rake
- polyglot (0.3.1)
- rack (1.2.1)
- rack-mount (0.6.13)
- rack (>= 1.0.0)
- rack-test (0.5.4)
- rack (>= 1.0)
- rails (3.0.0)
- actionmailer (= 3.0.0)
- actionpack (= 3.0.0)
- activerecord (= 3.0.0)
- activeresource (= 3.0.0)
- activesupport (= 3.0.0)
- bundler (~> 1.0.0)
- railties (= 3.0.0)
- railties (3.0.0)
- actionpack (= 3.0.0)
- activesupport (= 3.0.0)
- rake (>= 0.8.4)
- thor (~> 0.14.0)
- rake (0.8.7)
- thor (0.14.0)
- treetop (1.4.8)
- polyglot (>= 0.3.1)
- tzinfo (0.3.23)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- mocha
- rails (= 3.0.0)
diff --git a/Rakefile b/Rakefile
index f9817bf..3cd2c44 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,23 +1,6 @@
require "rake"
require 'rake/testtask'
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "dynamic_form"
- gem.summary = %Q{DynamicForm holds a few helper methods to help you deal with your Rails3 models}
- gem.description = %Q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for. It also brings in the functionality of the custom-err-messages plugin, which provides more flexibility over your model error messages.}
- gem.email = "joel@developwithstyle.com"
- gem.homepage = "http://codaset.com/joelmoss/dynamic-form"
- gem.authors = ["Joel Moss"]
- gem.add_development_dependency "mocha", ">= 0"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
-
desc 'Default: run unit tests.'
task :default => :test
diff --git a/dynamic_form.gemspec b/dynamic_form.gemspec
index a537a26..31c4cbb 100644
--- a/dynamic_form.gemspec
+++ b/dynamic_form.gemspec
@@ -1,13 +1,9 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
-# -*- encoding: utf-8 -*-
-
Gem::Specification.new do |s|
s.name = %q{dynamic_form}
- s.version = "1.2.0"
+ s.version = "1.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.required_ruby_version = ">= 2.7.0", "< 3.3"
s.authors = ["Joel Moss"]
s.date = %q{2010-09-05}
s.description = %q{DynamicForm holds a few helper methods to help you deal with your Rails3 models. It includes the stripped out methods from Rails 2; error_message_on and error_messages_for. It also brings in the functionality of the custom-err-messages plugin, which provides more flexibility over your model error messages.}
@@ -45,16 +41,11 @@ Gem::Specification.new do |s|
"test/test_helper.rb"
]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q, [">= 0"])
- else
- s.add_dependency(%q, [">= 0"])
- end
- else
- s.add_dependency(%q, [">= 0"])
- end
+ s.add_runtime_dependency 'actionview', '> 5.2.0'
+ s.add_runtime_dependency 'activemodel', '> 5.2.0'
+ s.add_development_dependency(%q, [">= 0"])
+ s.add_development_dependency(%q, [">= 0"])
+ s.add_development_dependency(%q, [">= 0"])
+ s.add_development_dependency(%q, [">= 0"])
+ s.add_development_dependency(%q, [">= 0"])
end
diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile
new file mode 100644
index 0000000..3b10fc4
--- /dev/null
+++ b/gemfiles/rails_5.2.gemfile
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+gem "rails", "~> 5.2.6"
+gem "sqlite3", "~> 1.4.1"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile
new file mode 100644
index 0000000..2a3054b
--- /dev/null
+++ b/gemfiles/rails_6.0.gemfile
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+gem "rails", "~> 6.0.4"
+gem "sqlite3"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile
new file mode 100644
index 0000000..3edc6c9
--- /dev/null
+++ b/gemfiles/rails_6.1.gemfile
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+gem "rails", "~> 6.1.4"
+gem "sqlite3"
+gem "minitest"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile
new file mode 100644
index 0000000..f32a1ff
--- /dev/null
+++ b/gemfiles/rails_7.0.gemfile
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+gem "rails", "~> 7.0.2"
+gem "sqlite3"
+
+gemspec path: "../"
diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile
new file mode 100644
index 0000000..1b7beb0
--- /dev/null
+++ b/gemfiles/rails_7.1.gemfile
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+gem "rails", "~> 7.1.1"
+gem "sqlite3"
+
+gemspec path: "../"
diff --git a/lib/action_view/helpers/dynamic_form.rb b/lib/action_view/helpers/dynamic_form.rb
index f22bbc6..ecc171a 100644
--- a/lib/action_view/helpers/dynamic_form.rb
+++ b/lib/action_view/helpers/dynamic_form.rb
@@ -2,6 +2,7 @@
require 'active_support/i18n'
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/object/blank'
+class BrokenFeatureError < RuntimeError; end
module ActionView
module Helpers
@@ -16,6 +17,7 @@ module DynamicForm
# input("post", "title")
# # =>
def input(record_name, method, options = {})
+ raise_broken_code_error
InstanceTag.new(record_name, method, self).to_tag(options)
end
@@ -79,6 +81,7 @@ def form(record_name, options = {})
submit_value = options[:submit_value] || options[:action].gsub(/[^\w]/, '').capitalize
+ raise_broken_code_error
contents = form_tag({:action => action}, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil)
contents.safe_concat hidden_field(record_name, :id) if record.persisted?
contents.safe_concat all_input_tags(record, record_name, options)
@@ -87,6 +90,10 @@ def form(record_name, options = {})
contents.safe_concat('')
end
+ def convert_to_model(object)
+ object.respond_to?(:to_model) ? object.to_model : object
+ end
+
# Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
# This error message is wrapped in a DIV tag by default or with :html_tag if specified,
# which can be extended to include a :prepend_text and/or :append_text (to properly explain
@@ -241,6 +248,11 @@ def error_messages_for(*params)
private
+ def raise_broken_code_error
+ raise BrokenFeatureError,
+ "This feature is currently broken, please open a pull request at https://github.com/payrollhero/dynamic_form to have it reviewed and released."
+ end
+
def all_input_tags(record, record_name, options)
input_block = options[:input_block] || default_input_block
record.class.content_columns.collect{ |column| input_block.call(record_name, column) }.join("\n")
diff --git a/test/dynamic_form_i18n_test.rb b/test/dynamic_form_i18n_test.rb
index 5913c51..1303108 100644
--- a/test/dynamic_form_i18n_test.rb
+++ b/test/dynamic_form_i18n_test.rb
@@ -39,4 +39,4 @@ def test_error_messages_for_given_no_message_option_it_translates_message
I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activerecord, :errors, :template]).returns 'There were problems with the following fields:'
error_messages_for(:object => @object, :locale => 'en')
end
-end
\ No newline at end of file
+end
diff --git a/test/dynamic_form_test.rb b/test/dynamic_form_test.rb
index e3cc6b7..0a5ec72 100644
--- a/test/dynamic_form_test.rb
+++ b/test/dynamic_form_test.rb
@@ -1,5 +1,6 @@
require 'test_helper'
-require 'action_view/template/handlers/erb'
+# warning: loading in progress, circular require considered harmful
+#require 'action_view/template/handlers/erb'
class DynamicFormTest < ActionView::TestCase
tests ActionView::Helpers::DynamicForm
@@ -121,8 +122,6 @@ def setup
super
setup_post
setup_user
-
- @response = ActionController::TestResponse.new
end
def url_for(options)
@@ -131,23 +130,28 @@ def url_for(options)
end
def test_generic_input_tag
+ assert_raise(BrokenFeatureError) do
assert_dom_equal(
%(), input("post", "title")
)
+ end
end
def test_text_area_with_errors
- assert_dom_equal(
- %(),
- text_area("post", "body")
+ expected_dom = %(
+
)
+ assert_dom_equal(expected_dom, text_area("post", "body"))
end
def test_text_field_with_errors
- assert_dom_equal(
- %(),
- text_field("post", "author_name")
+ expected_dom = %(
+
+
+
)
+ assert_dom_equal(expected_dom, text_field("post", "author_name"))
end
def test_field_error_proc
@@ -157,7 +161,7 @@ def test_field_error_proc
end
assert_dom_equal(
- %( can't be empty
),
+ %( can't be empty
),
text_field("post", "author_name")
)
ensure
@@ -165,6 +169,12 @@ def test_field_error_proc
end
def test_form_with_string
+ assert_raise(BrokenFeatureError) do
+ inner_test_form_with_string
+ end
+ end
+
+ def inner_test_form_with_string
assert_dom_equal(
%(
),
form("post")
@@ -185,6 +195,12 @@ def id() 1 end
end
def test_form_with_protect_against_forgery
+ assert_raise(BrokenFeatureError) do
+ inner_test_form_with_protect_against_forgery
+ end
+ end
+
+ def inner_test_form_with_protect_against_forgery
@protect_against_forgery = true
@request_forgery_protection_token = 'authenticity_token'
@form_authenticity_token = '123'
@@ -195,6 +211,12 @@ def test_form_with_protect_against_forgery
end
def test_form_with_method_option
+ assert_raise(BrokenFeatureError) do
+ inner_test_form_with_method_option
+ end
+ end
+
+ def inner_test_form_with_method_option
assert_dom_equal(
%(),
form("post", :method=>'get')
@@ -202,13 +224,21 @@ def test_form_with_method_option
end
def test_form_with_action_option
+ assert_raise(BrokenFeatureError) do
output_buffer << form("post", :action => "sign")
assert_select "form[action=sign]" do |form|
assert_select "input[type=submit][value=Sign]"
end
+ end
end
def test_form_with_date
+ assert_raise(BrokenFeatureError) do
+ inner_test_form_with_date
+ end
+ end
+
+ def inner_test_form_with_date
silence_warnings do
def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
end
@@ -220,6 +250,12 @@ def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
end
def test_form_with_datetime
+ assert_raise(BrokenFeatureError) do
+ inner_test_form_with_datetime
+ end
+ end
+
+ def inner_test_form_with_datetime
silence_warnings do
def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
end
@@ -232,10 +268,10 @@ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ]
end
def test_error_for_block
- assert_dom_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post")
- assert_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
- assert_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
- assert_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
+ assert_dom_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post")
+ assert_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
+ assert_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
+ assert_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
end
def test_error_messages_for_escapes_html
@@ -331,10 +367,12 @@ def test_error_messages_for_model_objects
end
def test_form_with_string_multipart
+ assert_raise(BrokenFeatureError) do
assert_dom_equal(
- %(),
+ %(),
form("post", :multipart => true)
)
+ end
end
def test_default_form_builder_with_dynamic_form_helpers
@@ -343,8 +381,9 @@ def test_default_form_builder_with_dynamic_form_helpers
concat f.error_messages
end
- expected = %()
@@ -361,18 +400,19 @@ def test_default_form_builder_no_instance_variable
concat f.error_messages
end
- expected = %()
assert_dom_equal expected, output_buffer
end
-
+
def test_error_messages_without_prefixed_attribute_name
error = error_messages_for(@post)
assert_dom_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
),
error
end
-end
\ No newline at end of file
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index f62a43c..95d8fd0 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,5 +1,8 @@
require 'rubygems'
require 'test/unit'
+require 'test/unit/active_support'
+require "test/unit/notify"
+require 'mocha/test_unit'
require 'active_support'
require 'active_support/core_ext'
require 'action_view'