client_side_validations-formtastic 2.0.0.beta.1 → 2.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,136 +0,0 @@
1
- require 'sinatra'
2
- require 'json'
3
- require 'ruby-debug'
4
-
5
- def rails_validations_path
6
- File.expand_path('../', $:.grep(/client_side_validations-\d/).first)
7
- end
8
-
9
- class AssetPath
10
- def initialize(app, options={})
11
- @app = app
12
- @urls = options[:urls] || ["/favicon.ico"]
13
- @index = options[:index]
14
- root = options[:root] || Dir.pwd
15
- cache_control = options[:cache_control]
16
- @file_server = Rack::File.new(root, cache_control)
17
- end
18
-
19
- def overwrite_file_path(path)
20
- @urls.kind_of?(Hash) && @urls.key?(path) || @index && path == '/'
21
- end
22
-
23
- def route_file(path)
24
- @urls.kind_of?(Array) && @urls.any? { |url| path.index(url) == 0 }
25
- end
26
-
27
- def can_serve(path)
28
- route_file(path) || overwrite_file_path(path)
29
- end
30
-
31
- def call(env)
32
- path = env["PATH_INFO"]
33
-
34
- if can_serve(path)
35
- env["PATH_INFO"] = (path == '/' ? @index : @urls[path]) if overwrite_file_path(path)
36
- response = @file_server.call(env)
37
- if response.first == 404
38
- @app.call(env)
39
- else
40
- response
41
- end
42
- else
43
- @app.call(env)
44
- end
45
- end
46
- end
47
-
48
- use AssetPath, :urls => ['/vendor/assets/javascripts/'], :root => rails_validations_path
49
- use AssetPath, :urls => ['/vendor/assets/javascripts/'], :root => File.expand_path('../..', settings.root)
50
-
51
- JQUERY_VERSIONS = %w[ 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 ].freeze
52
-
53
- helpers do
54
- def jquery_link version
55
- if params[:version] == version
56
- "[#{version}]"
57
- else
58
- "<a href='/?version=#{version}'>#{version}</a>"
59
- end
60
- end
61
-
62
- def jquery_src
63
- if params[:version] == 'edge'
64
- '/vendor/jquery.js'
65
- else
66
- "http://code.jquery.com/jquery-#{params[:version]}.js"
67
- end
68
- end
69
-
70
- def test_base
71
- names = ['/vendor/qunit.js', 'settings']
72
- names.map { |name| script_tag name }.join("\n")
73
- end
74
-
75
- def test *types
76
- types.map do |type|
77
- Dir.glob(File.expand_path("public/test/#{type}", settings.root) + '/*.js').map { |file| File.basename(file) }.map do |file|
78
- script_tag "/test/#{type}/#{file}"
79
- end.join("\n")
80
- end.join("\n")
81
- end
82
-
83
- def script_tag src
84
- src = "/test/#{src}.js" unless src.index('/')
85
- %(<script src='#{src}' type='text/javascript'></script>)
86
- end
87
-
88
- def jquery_versions
89
- JQUERY_VERSIONS
90
- end
91
- end
92
-
93
- get '/' do
94
- params[:version] ||= '1.7.1'
95
- erb :index
96
- end
97
-
98
- get '/validators/uniqueness' do
99
- content_type 'application/json'
100
-
101
- if user = params[:user2]
102
- status 500
103
- 'error'
104
- elsif user = params['active_record_test_module/user2']
105
- status 200
106
- 'false'
107
- elsif scope = params[:scope]
108
- if scope[:name] == 'test name' || scope[:name] == 'taken name'
109
- status 200
110
- 'false'
111
- else
112
- status 404
113
- 'true'
114
- end
115
- elsif params[:case_sensitive] == 'false' && (params[:user][:email] || params[:users][:email]) == 'taken@test.com'
116
- status 200
117
- 'false'
118
- else
119
- status 404
120
- 'true'
121
- end
122
-
123
- end
124
-
125
- post '/users' do
126
- data = { :params => params }.update(request.env)
127
- payload = data.to_json.gsub('<', '&lt;').gsub('>', '&gt;')
128
- <<-HTML
129
- <script>
130
- if (window.top && window.top !== window)
131
- window.top.jQuery.event.trigger('iframe:loaded', #{payload})
132
- </script>
133
- <p id="response">Form submitted</p>
134
- HTML
135
- end
136
-
@@ -1,22 +0,0 @@
1
- <% @title = "client_side_validations-formtastic test" %>
2
-
3
- <%= test_base %>
4
- <%= test :form_builders %>
5
-
6
- <h1 id="qunit-header"><%= @title %></h1>
7
-
8
- <div id="jquery-version">
9
- jQuery version:
10
-
11
- <% jquery_versions.each do |v| %>
12
- <%= ' • ' if v != jquery_versions.first %>
13
- <%= jquery_link v %>
14
- <% end %>
15
- <%= (' • ' + jquery_link('edge')) if File.exist?(settings.root + '/public/vendor/jquery.js') %>
16
- </div>
17
- <h2 id="qunit-banner"></h2>
18
- <div id="qunit-testrunner-toolbar"></div>
19
- <h2 id="qunit-userAgent"></h2>
20
- <ol id="qunit-tests"></ol>
21
-
22
- <div id="qunit-fixture"></div>
@@ -1,22 +0,0 @@
1
- <!DOCTYPE html>
2
- <html id="html">
3
- <head>
4
- <title><%= @title %></title>
5
- <link href="/vendor/qunit.css" media="screen" rel="stylesheet" type="text/css" media="screen, projection" />
6
- <style>
7
- #jquery-version {
8
- color: #8699A4; text-align: right; font-family: sans-serif; line-height: 1;
9
- margin-top: -1.8em; padding: 0 2em .8em 0;
10
- }
11
- #jquery-version a { color: white; text-decoration: underline; }
12
- </style>
13
-
14
- <%= script_tag jquery_src %>
15
- <%= script_tag '/vendor/assets/javascripts/rails.validations.js' %>
16
- <%= script_tag '/vendor/assets/javascripts/rails.validations.formtastic.js' %>
17
- </head>
18
-
19
- <body id="body">
20
- <%= yield %>
21
- </body>
22
- </html>
data/test/test_loader.rb DELETED
@@ -1,4 +0,0 @@
1
- # Sanity check to make sure the entire library loads OK
2
-
3
- require 'base_helper'
4
- require 'client_side_validations'