autoforme 1.11.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +16 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +8 -10
- data/autoforme.js +97 -56
- data/lib/autoforme/action.rb +21 -21
- data/lib/autoforme/frameworks/rails.rb +5 -1
- data/lib/autoforme/frameworks/roda.rb +10 -4
- data/lib/autoforme/frameworks/sinatra.rb +8 -3
- data/lib/autoforme/models/sequel.rb +12 -2
- data/lib/autoforme/version.rb +1 -1
- data/lib/roda/plugins/autoforme.rb +1 -1
- metadata +6 -18
- data/Rakefile +0 -69
- data/spec/all.rb +0 -2
- data/spec/associations_spec.rb +0 -802
- data/spec/basic_spec.rb +0 -1168
- data/spec/mtm_spec.rb +0 -621
- data/spec/rails_spec_helper.rb +0 -108
- data/spec/roda_spec.rb +0 -72
- data/spec/roda_spec_helper.rb +0 -86
- data/spec/sequel_spec_helper.rb +0 -42
- data/spec/sinatra_spec_helper.rb +0 -54
- data/spec/spec_helper.rb +0 -78
- data/spec/unit_spec.rb +0 -511
data/spec/rails_spec_helper.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
require 'rails'
|
2
|
-
require 'action_controller/railtie'
|
3
|
-
require_relative '../lib/autoforme'
|
4
|
-
|
5
|
-
class AutoFormeSpec::App
|
6
|
-
class << self
|
7
|
-
# Workaround for action_view railtie deleting the finalizer
|
8
|
-
attr_accessor :av_finalizer
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.autoforme(klass=nil, opts={}, &block)
|
12
|
-
sc = Class.new(Rails::Application)
|
13
|
-
def sc.name
|
14
|
-
"AutoForme Test"
|
15
|
-
end
|
16
|
-
framework = nil
|
17
|
-
sc.class_eval do
|
18
|
-
controller = Class.new(ActionController::Base)
|
19
|
-
Object.send(:const_set, :AutoformeController, controller)
|
20
|
-
|
21
|
-
resolver = Class.new(ActionView::Resolver)
|
22
|
-
resolver.class_eval do
|
23
|
-
template = ActionView::Template
|
24
|
-
code = (<<HTML)
|
25
|
-
<!DOCTYPE html>
|
26
|
-
<html>
|
27
|
-
<head><title><%= @autoforme_action.title if @autoforme_action %></title></head>
|
28
|
-
<body>
|
29
|
-
<% if flash[:notice] %>
|
30
|
-
<div class="alert alert-success"><p><%= flash[:notice] %></p></div>
|
31
|
-
<% end %>
|
32
|
-
<% if flash[:error] %>
|
33
|
-
<div class="alert alert-error"><p><%= flash[:error] %></p></div>
|
34
|
-
<% end %>
|
35
|
-
<%= yield %>
|
36
|
-
</body></html>"
|
37
|
-
HTML
|
38
|
-
if Rails.version > '6'
|
39
|
-
t = [template.new(code, "layout", template.handler_for_extension(:erb), :virtual_path=>'layout', :format=>'erb', :locals=>[])]
|
40
|
-
else
|
41
|
-
t = [template.new(code, "layout", template.handler_for_extension(:erb), :virtual_path=>'layout', :format=>'erb', :updated_at=>Time.now)]
|
42
|
-
end
|
43
|
-
|
44
|
-
define_method(:find_templates){|*args| t}
|
45
|
-
end
|
46
|
-
|
47
|
-
controller.class_eval do
|
48
|
-
self.view_paths = resolver.new
|
49
|
-
layout 'layout'
|
50
|
-
|
51
|
-
def session_set
|
52
|
-
params.each{|k,v| session[k] = v}
|
53
|
-
render :plain=>''
|
54
|
-
end
|
55
|
-
|
56
|
-
AutoForme.for(:rails, self, opts) do
|
57
|
-
framework = self
|
58
|
-
if klass
|
59
|
-
model(klass, &block)
|
60
|
-
elsif block
|
61
|
-
instance_eval(&block)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
st = routes.append do
|
67
|
-
get 'session/set', :controller=>'autoforme', :action=>'session_set'
|
68
|
-
end.inspect
|
69
|
-
config.secret_token = st if Rails.respond_to?(:version) && Rails.version < '5.2'
|
70
|
-
config.hosts << "www.example.com" if config.respond_to?(:hosts)
|
71
|
-
config.active_support.deprecation = :stderr
|
72
|
-
config.middleware.delete(ActionDispatch::ShowExceptions)
|
73
|
-
config.middleware.delete(Rack::Lock)
|
74
|
-
config.secret_key_base = st*15
|
75
|
-
config.eager_load = true
|
76
|
-
if Rails.version.start_with?('4')
|
77
|
-
# Work around issue in backported openssl environments where
|
78
|
-
# secret is 64 bytes intead of 32 bytes
|
79
|
-
require 'active_support/message_encryptor'
|
80
|
-
def (ActiveSupport::MessageEncryptor).new(secret, *signature_key_or_options)
|
81
|
-
obj = allocate
|
82
|
-
obj.send(:initialize, secret[0, 32], *signature_key_or_options)
|
83
|
-
obj
|
84
|
-
end
|
85
|
-
end
|
86
|
-
if Rails.version > '4.2'
|
87
|
-
config.action_dispatch.cookies_serializer = :json
|
88
|
-
end
|
89
|
-
if Rails.version > '5'
|
90
|
-
# Force Rails to dispatch to correct controller
|
91
|
-
ActionDispatch::Routing::RouteSet::Dispatcher.class_eval do
|
92
|
-
alias controller controller
|
93
|
-
define_method(:controller){|_| controller}
|
94
|
-
end
|
95
|
-
config.session_store :cookie_store, :key=>'_autoforme_test_session'
|
96
|
-
end
|
97
|
-
if Rails.version > '6'
|
98
|
-
if AutoFormeSpec::App.av_finalizer
|
99
|
-
config.action_view.finalize_compiled_template_methods = AutoFormeSpec::App.av_finalizer
|
100
|
-
else
|
101
|
-
AutoFormeSpec::App.av_finalizer = config.action_view.finalize_compiled_template_methods
|
102
|
-
end
|
103
|
-
end
|
104
|
-
initialize!
|
105
|
-
end
|
106
|
-
[sc, framework]
|
107
|
-
end
|
108
|
-
end
|
data/spec/roda_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
describe AutoForme do
|
4
|
-
before(:all) do
|
5
|
-
db_setup(:artists=>[[:name, :string]])
|
6
|
-
model_setup(:Artist=>[:artists])
|
7
|
-
end
|
8
|
-
after(:all) do
|
9
|
-
Object.send(:remove_const, :Artist)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have basic functionality working in Roda subclass" do
|
13
|
-
app_setup(Artist)
|
14
|
-
self.app = Class.new(app)
|
15
|
-
visit("/Artist/new")
|
16
|
-
page.title.must_equal 'Artist - New'
|
17
|
-
fill_in 'Name', :with=>'TestArtistNew'
|
18
|
-
click_button 'Create'
|
19
|
-
page.html.must_include 'Created Artist'
|
20
|
-
page.current_path.must_equal '/Artist/new'
|
21
|
-
|
22
|
-
click_link 'Show'
|
23
|
-
page.title.must_equal 'Artist - Show'
|
24
|
-
click_button 'Show'
|
25
|
-
select 'TestArtistNew'
|
26
|
-
click_button 'Show'
|
27
|
-
page.html.must_match(/Name.+TestArtistNew/m)
|
28
|
-
|
29
|
-
click_link 'Edit'
|
30
|
-
page.title.must_equal 'Artist - Edit'
|
31
|
-
click_button 'Edit'
|
32
|
-
select 'TestArtistNew'
|
33
|
-
click_button 'Edit'
|
34
|
-
fill_in 'Name', :with=>'TestArtistUpdate'
|
35
|
-
click_button 'Update'
|
36
|
-
page.html.must_include 'Updated Artist'
|
37
|
-
page.html.must_match(/Name.+TestArtistUpdate/m)
|
38
|
-
page.current_path.must_match %r{/Artist/edit/\d+}
|
39
|
-
|
40
|
-
click_link 'Search'
|
41
|
-
page.title.must_equal 'Artist - Search'
|
42
|
-
fill_in 'Name', :with=>'Upd'
|
43
|
-
click_button 'Search'
|
44
|
-
page.all('table').first['id'].must_equal 'autoforme_table'
|
45
|
-
page.all('th').map{|s| s.text}.must_equal ['Name', 'Show', 'Edit', 'Delete']
|
46
|
-
page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
47
|
-
click_link 'CSV Format'
|
48
|
-
page.body.must_equal "Name\nTestArtistUpdate\n"
|
49
|
-
|
50
|
-
visit("/Artist/browse")
|
51
|
-
click_link 'Search'
|
52
|
-
fill_in 'Name', :with=>'Foo'
|
53
|
-
click_button 'Search'
|
54
|
-
page.all('td').map{|s| s.text}.must_equal []
|
55
|
-
|
56
|
-
click_link 'Artist'
|
57
|
-
page.title.must_equal 'Artist - Browse'
|
58
|
-
page.all('td').map{|s| s.text}.must_equal ["TestArtistUpdate", "Show", "Edit", "Delete"]
|
59
|
-
click_link 'CSV Format'
|
60
|
-
page.body.must_equal "Name\nTestArtistUpdate\n"
|
61
|
-
|
62
|
-
visit("/Artist/browse")
|
63
|
-
page.all('td').last.find('a').click
|
64
|
-
click_button 'Delete'
|
65
|
-
page.title.must_equal 'Artist - Delete'
|
66
|
-
page.html.must_include 'Deleted Artist'
|
67
|
-
page.current_path.must_equal '/Artist/delete'
|
68
|
-
|
69
|
-
click_link 'Artist'
|
70
|
-
page.all('td').map{|s| s.text}.must_equal []
|
71
|
-
end
|
72
|
-
end if ENV['FRAMEWORK'] == 'roda'
|
data/spec/roda_spec_helper.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'roda'
|
2
|
-
require_relative '../lib/autoforme'
|
3
|
-
require 'rack/csrf'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'tilt/erubi'
|
7
|
-
rescue LoadError
|
8
|
-
require 'tilt/erb'
|
9
|
-
end
|
10
|
-
|
11
|
-
class AutoFormeSpec::App < Roda
|
12
|
-
opts[:unsupported_block_result] = :raise
|
13
|
-
opts[:unsupported_matcher] = :raise
|
14
|
-
opts[:verbatim_string_matcher] = true
|
15
|
-
opts[:check_dynamic_arity] = opts[:check_arity] = :warn
|
16
|
-
|
17
|
-
LAYOUT = <<HTML
|
18
|
-
<!DOCTYPE html>
|
19
|
-
<html>
|
20
|
-
<head><title><%= @autoforme_action.title if @autoforme_action %></title></head>
|
21
|
-
<body>
|
22
|
-
<% if notice = opts[:sessions_convert_symbols] ? flash['notice'] : flash[:notice] %>
|
23
|
-
<div class="alert alert-success"><p><%= notice %></p></div>
|
24
|
-
<% end %>
|
25
|
-
<% if error = opts[:sessions_convert_symbols] ? flash['error'] : flash[:error] %>
|
26
|
-
<div class="alert alert-error"><p><%= error %></p></div>
|
27
|
-
<% end %>
|
28
|
-
<%= yield %>
|
29
|
-
</body></html>"
|
30
|
-
HTML
|
31
|
-
|
32
|
-
plugin :flash
|
33
|
-
|
34
|
-
if defined?(Roda::RodaVersionNumber) && Roda::RodaVersionNumber >= 30100
|
35
|
-
if ENV['RODA_ROUTE_CSRF'] == '0'
|
36
|
-
require 'roda/session_middleware'
|
37
|
-
opts[:sessions_convert_symbols] = true
|
38
|
-
use RodaSessionMiddleware, :secret=>SecureRandom.random_bytes(64)
|
39
|
-
else
|
40
|
-
ENV['RODA_ROUTE_CSRF'] ||= '1'
|
41
|
-
plugin :sessions, :secret=>SecureRandom.random_bytes(64)
|
42
|
-
end
|
43
|
-
else
|
44
|
-
use Rack::Session::Cookie, :secret => '1'
|
45
|
-
end
|
46
|
-
|
47
|
-
if ENV['RODA_ROUTE_CSRF'].to_i > 0
|
48
|
-
plugin :route_csrf, :require_request_specific_tokens=>ENV['RODA_ROUTE_CSRF'] == '1'
|
49
|
-
else
|
50
|
-
use Rack::Csrf
|
51
|
-
end
|
52
|
-
|
53
|
-
template_opts = {:default_encoding=>nil}
|
54
|
-
plugin :render, :layout=>{:inline=>LAYOUT}, :template_opts=>template_opts, :opts=>template_opts
|
55
|
-
plugin :not_found do
|
56
|
-
'Unhandled Request'
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.autoforme(klass=nil, opts={}, &block)
|
60
|
-
sc = Class.new(self)
|
61
|
-
framework = nil
|
62
|
-
sc.class_eval do
|
63
|
-
plugin :autoforme, opts do
|
64
|
-
framework = self
|
65
|
-
if klass
|
66
|
-
model(klass, &block)
|
67
|
-
elsif block
|
68
|
-
instance_eval(&block)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
route do |r|
|
73
|
-
check_csrf! if ENV['RODA_ROUTE_CSRF'].to_i > 0
|
74
|
-
|
75
|
-
r.get 'session/set' do
|
76
|
-
session.merge!(r.params)
|
77
|
-
''
|
78
|
-
end
|
79
|
-
|
80
|
-
autoforme
|
81
|
-
end
|
82
|
-
end
|
83
|
-
[sc, framework]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
data/spec/sequel_spec_helper.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
module AutoFormeSpec
|
5
|
-
TYPE_MAP = {:string=>String, :integer=>Integer, :decimal=>Numeric, :boolean=>TrueClass}
|
6
|
-
def self.db_setup(tables)
|
7
|
-
db_url = ENV['DATABASE_URL']
|
8
|
-
db_url ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite::memory:' : 'sqlite:/'
|
9
|
-
db = Sequel.connect(db_url, :identifier_mangling=>false)
|
10
|
-
db.extension :freeze_datasets
|
11
|
-
#db.loggers << Logger.new($stdout)
|
12
|
-
tables.each do |table, table_spec|
|
13
|
-
db.create_table(table) do
|
14
|
-
if table_spec.kind_of? Enumerable
|
15
|
-
primary_key :id
|
16
|
-
table_spec.each do |name, type, opts|
|
17
|
-
column name, TYPE_MAP[type], opts||{}
|
18
|
-
end
|
19
|
-
elsif table_spec.respond_to? :call
|
20
|
-
self.instance_eval(&table_spec)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
db.freeze
|
26
|
-
db
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.model_setup(db, models)
|
30
|
-
models.each do |name, (table, associations)|
|
31
|
-
klass = Class.new(Sequel::Model(db[table]))
|
32
|
-
Object.const_set(name, klass)
|
33
|
-
klass.class_eval do
|
34
|
-
if associations
|
35
|
-
associations.each do |type, assoc, opts|
|
36
|
-
associate(type, assoc, opts||{})
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/spec/sinatra_spec_helper.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
require_relative '../lib/autoforme'
|
3
|
-
require 'sinatra/flash'
|
4
|
-
require 'rack/csrf'
|
5
|
-
|
6
|
-
class AutoFormeSpec::App < Sinatra::Base
|
7
|
-
disable :run
|
8
|
-
enable :sessions
|
9
|
-
enable :raise_errors
|
10
|
-
set :environment, "test"
|
11
|
-
register Sinatra::Flash
|
12
|
-
use Rack::Csrf
|
13
|
-
|
14
|
-
not_found do
|
15
|
-
'Unhandled Request'
|
16
|
-
end
|
17
|
-
get '/session/set' do
|
18
|
-
session.merge!(params)
|
19
|
-
''
|
20
|
-
end
|
21
|
-
|
22
|
-
template :layout do
|
23
|
-
<<HTML
|
24
|
-
<!DOCTYPE html>
|
25
|
-
<html>
|
26
|
-
<head><title><%= @autoforme_action.title if @autoforme_action %></title></head>
|
27
|
-
<body>
|
28
|
-
<% if flash[:notice] %>
|
29
|
-
<div class="alert alert-success"><p><%= flash[:notice] %></p></div>
|
30
|
-
<% end %>
|
31
|
-
<% if flash[:error] %>
|
32
|
-
<div class="alert alert-error"><p><%= flash[:error] %></p></div>
|
33
|
-
<% end %>
|
34
|
-
<%= yield %>
|
35
|
-
</body></html>"
|
36
|
-
HTML
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.autoforme(klass=nil, opts={}, &block)
|
40
|
-
sc = Class.new(self)
|
41
|
-
framework = nil
|
42
|
-
sc.class_eval do
|
43
|
-
AutoForme.for(:sinatra, self, opts) do
|
44
|
-
framework = self
|
45
|
-
if klass
|
46
|
-
model(klass, &block)
|
47
|
-
elsif block
|
48
|
-
instance_eval(&block)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
[sc, framework]
|
53
|
-
end
|
54
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
$: << File.expand_path(File.join(__FILE__, '../../lib'))
|
2
|
-
ENV['FRAMEWORK'] ||= 'roda'
|
3
|
-
|
4
|
-
module AutoFormeSpec
|
5
|
-
end
|
6
|
-
|
7
|
-
if ENV['COVERAGE']
|
8
|
-
ENV.delete('COVERAGE')
|
9
|
-
require 'coverage'
|
10
|
-
require 'simplecov'
|
11
|
-
|
12
|
-
SimpleCov.instance_eval do
|
13
|
-
start do
|
14
|
-
add_filter "/spec/"
|
15
|
-
add_group('Missing'){|src| src.covered_percent < 100}
|
16
|
-
add_group('Covered'){|src| src.covered_percent == 100}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
require_relative "#{ENV['FRAMEWORK']}_spec_helper"
|
22
|
-
|
23
|
-
require 'capybara'
|
24
|
-
require 'capybara/dsl'
|
25
|
-
require 'rack/test'
|
26
|
-
|
27
|
-
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
28
|
-
gem 'minitest'
|
29
|
-
require 'minitest/global_expectations/autorun'
|
30
|
-
require 'minitest/hooks/default'
|
31
|
-
|
32
|
-
if ENV['WARNING']
|
33
|
-
require 'warning'
|
34
|
-
Warning.ignore([:missing_ivar, :fixnum, :not_reached])
|
35
|
-
end
|
36
|
-
|
37
|
-
require_relative 'sequel_spec_helper'
|
38
|
-
|
39
|
-
class Minitest::HooksSpec
|
40
|
-
include Rack::Test::Methods
|
41
|
-
include Capybara::DSL
|
42
|
-
|
43
|
-
attr_reader :app
|
44
|
-
attr_reader :db
|
45
|
-
attr_reader :framework
|
46
|
-
attr_reader :model
|
47
|
-
|
48
|
-
def app=(app)
|
49
|
-
@app = Capybara.app = app
|
50
|
-
end
|
51
|
-
|
52
|
-
def db_setup(tables, &block)
|
53
|
-
@db = AutoFormeSpec.db_setup(tables)
|
54
|
-
end
|
55
|
-
|
56
|
-
def model_setup(models)
|
57
|
-
AutoFormeSpec.model_setup(db, models)
|
58
|
-
end
|
59
|
-
|
60
|
-
def app_setup(klass=nil, opts={}, &block)
|
61
|
-
app, @framework = AutoFormeSpec::App.autoforme(klass, opts, &block)
|
62
|
-
self.app = app
|
63
|
-
@model = @framework.models[klass.name] if klass
|
64
|
-
end
|
65
|
-
|
66
|
-
around do |&block|
|
67
|
-
db ? db.transaction(:rollback=>:always){super(&block)} : super(&block)
|
68
|
-
end
|
69
|
-
|
70
|
-
after do
|
71
|
-
Capybara.reset_sessions!
|
72
|
-
Capybara.use_default_driver
|
73
|
-
if Object.const_defined?(:AutoformeController)
|
74
|
-
Object.send(:remove_const, :AutoformeController)
|
75
|
-
Rails.application = nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|