autoforme 1.9.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,87 +0,0 @@
1
- require 'rubygems'
2
- require 'roda'
3
- require 'autoforme'
4
- require 'rack/csrf'
5
-
6
- begin
7
- require 'tilt/erubi'
8
- rescue LoadError
9
- require 'tilt/erb'
10
- end
11
-
12
- class AutoFormeSpec::App < Roda
13
- opts[:unsupported_block_result] = :raise
14
- opts[:unsupported_matcher] = :raise
15
- opts[:verbatim_string_matcher] = true
16
- opts[:check_dynamic_arity] = opts[:check_arity] = :warn
17
-
18
- LAYOUT = <<HTML
19
- <!DOCTYPE html>
20
- <html>
21
- <head><title><%= @autoforme_action.title if @autoforme_action %></title></head>
22
- <body>
23
- <% if notice = opts[:sessions_convert_symbols] ? flash['notice'] : flash[:notice] %>
24
- <div class="alert alert-success"><p><%= notice %></p></div>
25
- <% end %>
26
- <% if error = opts[:sessions_convert_symbols] ? flash['error'] : flash[:error] %>
27
- <div class="alert alert-error"><p><%= error %></p></div>
28
- <% end %>
29
- <%= yield %>
30
- </body></html>"
31
- HTML
32
-
33
- plugin :flash
34
-
35
- if defined?(Roda::RodaVersionNumber) && Roda::RodaVersionNumber >= 30100
36
- if ENV['RODA_ROUTE_CSRF'] == '0'
37
- require 'roda/session_middleware'
38
- opts[:sessions_convert_symbols] = true
39
- use RodaSessionMiddleware, :secret=>SecureRandom.random_bytes(64)
40
- else
41
- ENV['RODA_ROUTE_CSRF'] ||= '1'
42
- plugin :sessions, :secret=>SecureRandom.random_bytes(64)
43
- end
44
- else
45
- use Rack::Session::Cookie, :secret => '1'
46
- end
47
-
48
- if ENV['RODA_ROUTE_CSRF'].to_i > 0
49
- plugin :route_csrf, :require_request_specific_tokens=>ENV['RODA_ROUTE_CSRF'] == '1'
50
- else
51
- use Rack::Csrf
52
- end
53
-
54
- template_opts = {:default_encoding=>nil}
55
- plugin :render, :layout=>{:inline=>LAYOUT}, :template_opts=>template_opts, :opts=>template_opts
56
- plugin :not_found do
57
- 'Unhandled Request'
58
- end
59
-
60
- def self.autoforme(klass=nil, opts={}, &block)
61
- sc = Class.new(self)
62
- framework = nil
63
- sc.class_eval do
64
- plugin :autoforme, opts do
65
- framework = self
66
- if klass
67
- model(klass, &block)
68
- elsif block
69
- instance_eval(&block)
70
- end
71
- end
72
-
73
- route do |r|
74
- check_csrf! if ENV['RODA_ROUTE_CSRF'].to_i > 0
75
-
76
- r.get 'session/set' do
77
- session.merge!(r.params)
78
- ''
79
- end
80
-
81
- autoforme
82
- end
83
- end
84
- [sc, framework]
85
- end
86
- end
87
-
@@ -1,43 +0,0 @@
1
- require 'rubygems'
2
- require 'sequel'
3
- require 'logger'
4
-
5
- module AutoFormeSpec
6
- TYPE_MAP = {:string=>String, :integer=>Integer, :decimal=>Numeric, :boolean=>TrueClass}
7
- def self.db_setup(tables)
8
- db_url = ENV['DATABASE_URL']
9
- db_url ||= defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite::memory:' : 'sqlite:/'
10
- db = Sequel.connect(db_url, :identifier_mangling=>false)
11
- db.extension :freeze_datasets
12
- #db.loggers << Logger.new($stdout)
13
- tables.each do |table, table_spec|
14
- db.create_table(table) do
15
- if table_spec.kind_of? Enumerable
16
- primary_key :id
17
- table_spec.each do |name, type, opts|
18
- column name, TYPE_MAP[type], opts||{}
19
- end
20
- elsif table_spec.respond_to? :call
21
- self.instance_eval(&table_spec)
22
- end
23
- end
24
- end
25
-
26
- db.freeze
27
- db
28
- end
29
-
30
- def self.model_setup(db, models)
31
- models.each do |name, (table, associations)|
32
- klass = Class.new(Sequel::Model(db[table]))
33
- Object.const_set(name, klass)
34
- klass.class_eval do
35
- if associations
36
- associations.each do |type, assoc, opts|
37
- associate(type, assoc, opts||{})
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,55 +0,0 @@
1
- require 'rubygems'
2
- require 'sinatra/base'
3
- require 'autoforme'
4
- require 'sinatra/flash'
5
- require 'rack/csrf'
6
-
7
- class AutoFormeSpec::App < Sinatra::Base
8
- disable :run
9
- enable :sessions
10
- enable :raise_errors
11
- set :environment, "test"
12
- register Sinatra::Flash
13
- use Rack::Csrf
14
-
15
- not_found do
16
- 'Unhandled Request'
17
- end
18
- get '/session/set' do
19
- session.merge!(params)
20
- ''
21
- end
22
-
23
- template :layout do
24
- <<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
- end
39
-
40
- def self.autoforme(klass=nil, opts={}, &block)
41
- sc = Class.new(self)
42
- framework = nil
43
- sc.class_eval do
44
- AutoForme.for(:sinatra, self, opts) do
45
- framework = self
46
- if klass
47
- model(klass, &block)
48
- elsif block
49
- instance_eval(&block)
50
- end
51
- end
52
- end
53
- [sc, framework]
54
- end
55
- end
data/spec/spec_helper.rb DELETED
@@ -1,79 +0,0 @@
1
- require 'rubygems'
2
- $: << File.expand_path(File.join(__FILE__, '../../lib'))
3
- ENV['FRAMEWORK'] ||= 'roda'
4
-
5
- module AutoFormeSpec
6
- end
7
-
8
- if ENV['COVERAGE']
9
- ENV.delete('COVERAGE')
10
- require 'coverage'
11
- require 'simplecov'
12
-
13
- SimpleCov.instance_eval do
14
- start do
15
- add_filter "/spec/"
16
- add_group('Missing'){|src| src.covered_percent < 100}
17
- add_group('Covered'){|src| src.covered_percent == 100}
18
- end
19
- end
20
- end
21
-
22
- require "./spec/#{ENV['FRAMEWORK']}_spec_helper"
23
-
24
- require 'capybara'
25
- require 'capybara/dsl'
26
- require 'rack/test'
27
-
28
- ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
29
- gem 'minitest'
30
- require 'minitest/autorun'
31
- require 'minitest/hooks/default'
32
-
33
- if ENV['WARNING']
34
- require 'warning'
35
- Warning.ignore([:missing_ivar, :fixnum, :not_reached])
36
- end
37
-
38
- require './spec/sequel_spec_helper'
39
-
40
- class Minitest::HooksSpec
41
- include Rack::Test::Methods
42
- include Capybara::DSL
43
-
44
- attr_reader :app
45
- attr_reader :db
46
- attr_reader :framework
47
- attr_reader :model
48
-
49
- def app=(app)
50
- @app = Capybara.app = app
51
- end
52
-
53
- def db_setup(tables, &block)
54
- @db = AutoFormeSpec.db_setup(tables)
55
- end
56
-
57
- def model_setup(models)
58
- AutoFormeSpec.model_setup(db, models)
59
- end
60
-
61
- def app_setup(klass=nil, opts={}, &block)
62
- app, @framework = AutoFormeSpec::App.autoforme(klass, opts, &block)
63
- self.app = app
64
- @model = @framework.models[klass.name] if klass
65
- end
66
-
67
- around do |&block|
68
- db ? db.transaction(:rollback=>:always){super(&block)} : super(&block)
69
- end
70
-
71
- after do
72
- Capybara.reset_sessions!
73
- Capybara.use_default_driver
74
- if Object.const_defined?(:AutoformeController)
75
- Object.send(:remove_const, :AutoformeController)
76
- Rails.application = nil
77
- end
78
- end
79
- end