Skip to content

Commit

Permalink
Fix CI, run on GitHub actions, and fix as many tests as possible. (#2)
Browse files Browse the repository at this point in the history
* run tests on github actions

* add rails 7.1 and newer rubies to the CI matrix

* add missing convert_to_model method, and do not create @response object

* fix as many tests as possible, disable others

update .gitignore

* ruby 2.6 is deprecated, 3.3 is failing

* bump version, fix condition

* add runtime dependencies

* autocomplete came with rails 6.1

* remove comment

* fix tests

* fix Gemfile

* raise and expect an exception instead
  • Loading branch information
mathieujobin authored Nov 1, 2023
1 parent 072a58f commit 6227859
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 134 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.bundle
pkg
pkg
*emfile.lock
*.gem
*.swp
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0'
gem 'mocha'
gemspec path: '.'
74 changes: 0 additions & 74 deletions Gemfile.lock

This file was deleted.

17 changes: 0 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
27 changes: 9 additions & 18 deletions dynamic_form.gemspec
Original file line number Diff line number Diff line change
@@ -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.}
Expand Down Expand Up @@ -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<mocha>, [">= 0"])
else
s.add_dependency(%q<mocha>, [">= 0"])
end
else
s.add_dependency(%q<mocha>, [">= 0"])
end
s.add_runtime_dependency 'actionview', '> 5.2.0'
s.add_runtime_dependency 'activemodel', '> 5.2.0'
s.add_development_dependency(%q<byebug>, [">= 0"])
s.add_development_dependency(%q<mocha>, [">= 0"])
s.add_development_dependency(%q<test-unit>, [">= 0"])
s.add_development_dependency(%q<test-unit-rails>, [">= 0"])
s.add_development_dependency(%q<test-unit-full>, [">= 0"])
end
8 changes: 8 additions & 0 deletions gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "~> 5.2.6"
gem "sqlite3", "~> 1.4.1"

gemspec path: "../"
8 changes: 8 additions & 0 deletions gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "~> 6.0.4"
gem "sqlite3"

gemspec path: "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "~> 6.1.4"
gem "sqlite3"
gem "minitest"

gemspec path: "../"
8 changes: 8 additions & 0 deletions gemfiles/rails_7.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "~> 7.0.2"
gem "sqlite3"

gemspec path: "../"
8 changes: 8 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rails", "~> 7.1.1"
gem "sqlite3"

gemspec path: "../"
12 changes: 12 additions & 0 deletions lib/action_view/helpers/dynamic_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +17,7 @@ module DynamicForm
# input("post", "title")
# # => <input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
def input(record_name, method, options = {})
raise_broken_code_error
InstanceTag.new(record_name, method, self).to_tag(options)
end

Expand Down Expand Up @@ -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)
Expand All @@ -87,6 +90,10 @@ def form(record_name, options = {})
contents.safe_concat('</form>')
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 <tt>DIV</tt> tag by default or with <tt>:html_tag</tt> if specified,
# which can be extended to include a <tt>:prepend_text</tt> and/or <tt>:append_text</tt> (to properly explain
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion test/dynamic_form_i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
Loading

0 comments on commit 6227859

Please sign in to comment.