enumerated_attribute 0.2.13 → 0.2.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/Rakefile +11 -1
- data/lib/enumerated_attribute/rails_helpers.rb +12 -10
- data/spec/rails/config/environment.rb +1 -1
- data/spec/rails/spec/integrations/enum_select_spec.rb +1 -1
- data/spec/rails3/Gemfile +30 -0
- data/spec/rails3/README +244 -0
- data/spec/rails3/Rakefile +10 -0
- data/spec/rails3/app/controllers/application_controller.rb +10 -0
- data/spec/rails3/app/controllers/form_test_controller.rb +38 -0
- data/spec/rails3/app/helpers/application_helper.rb +3 -0
- data/spec/rails3/app/helpers/form_test_helper.rb +2 -0
- data/spec/rails3/app/models/user.rb +9 -0
- data/spec/rails3/app/views/form_test/form.html.erb +1 -0
- data/spec/rails3/app/views/form_test/form_for.html.erb +10 -0
- data/spec/rails3/app/views/form_test/form_tag.html.erb +9 -0
- data/spec/rails3/app/views/form_test/index.html.erb +6 -0
- data/spec/rails3/app/views/layouts/application.html.erb +11 -0
- data/spec/rails3/config.ru +4 -0
- data/spec/rails3/config/application.rb +46 -0
- data/spec/rails3/config/boot.rb +6 -0
- data/spec/rails3/config/database.yml +22 -0
- data/spec/rails3/config/environment.rb +5 -0
- data/spec/rails3/config/environments/development.rb +19 -0
- data/spec/rails3/config/environments/production.rb +42 -0
- data/spec/rails3/config/environments/test.rb +32 -0
- data/spec/rails3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3/config/initializers/inflections.rb +10 -0
- data/spec/rails3/config/initializers/mime_types.rb +5 -0
- data/spec/rails3/config/initializers/secret_token.rb +7 -0
- data/spec/rails3/config/initializers/session_store.rb +8 -0
- data/spec/rails3/config/locales/en.yml +5 -0
- data/spec/rails3/config/routes.rb +58 -0
- data/spec/rails3/db/seeds.rb +7 -0
- data/spec/rails3/public/404.html +26 -0
- data/spec/rails3/public/422.html +26 -0
- data/spec/rails3/public/500.html +26 -0
- data/spec/rails3/public/favicon.ico +0 -0
- data/spec/rails3/public/images/rails.png +0 -0
- data/spec/rails3/public/index.html +279 -0
- data/spec/rails3/public/javascripts/application.js +2 -0
- data/spec/rails3/public/javascripts/controls.js +965 -0
- data/spec/rails3/public/javascripts/dragdrop.js +974 -0
- data/spec/rails3/public/javascripts/effects.js +1123 -0
- data/spec/rails3/public/javascripts/prototype.js +4874 -0
- data/spec/rails3/public/javascripts/rails.js +118 -0
- data/spec/rails3/public/robots.txt +5 -0
- data/spec/rails3/script/rails +9 -0
- data/spec/rails3/spec/integrations/enum_select_spec.rb +75 -0
- data/spec/rails3/spec/matchers.rb +12 -0
- data/spec/rails3/spec/rcov.opts +2 -0
- data/spec/rails3/spec/spec.opts +4 -0
- data/spec/rails3/spec/spec_helper.rb +41 -0
- data/spec/rails3/test/performance/browsing_test.rb +9 -0
- data/spec/rails3/test/test_helper.rb +13 -0
- metadata +62 -4
@@ -0,0 +1,118 @@
|
|
1
|
+
document.observe("dom:loaded", function() {
|
2
|
+
function handleRemote(element) {
|
3
|
+
var method, url, params;
|
4
|
+
|
5
|
+
if (element.tagName.toLowerCase() === 'form') {
|
6
|
+
method = element.readAttribute('method') || 'post';
|
7
|
+
url = element.readAttribute('action');
|
8
|
+
params = element.serialize(true);
|
9
|
+
} else {
|
10
|
+
method = element.readAttribute('data-method') || 'get';
|
11
|
+
url = element.readAttribute('href');
|
12
|
+
params = {};
|
13
|
+
}
|
14
|
+
|
15
|
+
var event = element.fire("ajax:before");
|
16
|
+
if (event.stopped) return false;
|
17
|
+
|
18
|
+
new Ajax.Request(url, {
|
19
|
+
method: method,
|
20
|
+
parameters: params,
|
21
|
+
asynchronous: true,
|
22
|
+
evalScripts: true,
|
23
|
+
|
24
|
+
onLoading: function(request) { element.fire("ajax:loading", {request: request}); },
|
25
|
+
onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); },
|
26
|
+
onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); },
|
27
|
+
onComplete: function(request) { element.fire("ajax:complete", {request: request}); },
|
28
|
+
onSuccess: function(request) { element.fire("ajax:success", {request: request}); },
|
29
|
+
onFailure: function(request) { element.fire("ajax:failure", {request: request}); }
|
30
|
+
});
|
31
|
+
|
32
|
+
element.fire("ajax:after");
|
33
|
+
}
|
34
|
+
|
35
|
+
function handleMethod(element) {
|
36
|
+
var method, url, token_name, token;
|
37
|
+
|
38
|
+
method = element.readAttribute('data-method');
|
39
|
+
url = element.readAttribute('href');
|
40
|
+
csrf_param = $$('meta[name=csrf-param]').first();
|
41
|
+
csrf_token = $$('meta[name=csrf-token]').first();
|
42
|
+
|
43
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
44
|
+
element.parentNode.appendChild(form);
|
45
|
+
|
46
|
+
if (method != 'post') {
|
47
|
+
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
48
|
+
form.appendChild(field);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (csrf_param) {
|
52
|
+
var param = csrf_param.readAttribute('content');
|
53
|
+
var token = csrf_token.readAttribute('content');
|
54
|
+
var field = new Element('input', { type: 'hidden', name: param, value: token });
|
55
|
+
form.appendChild(field);
|
56
|
+
}
|
57
|
+
|
58
|
+
form.submit();
|
59
|
+
}
|
60
|
+
|
61
|
+
$(document.body).observe("click", function(event) {
|
62
|
+
var message = event.findElement().readAttribute('data-confirm');
|
63
|
+
if (message && !confirm(message)) {
|
64
|
+
event.stop();
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
|
68
|
+
var element = event.findElement("a[data-remote]");
|
69
|
+
if (element) {
|
70
|
+
handleRemote(element);
|
71
|
+
event.stop();
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
|
75
|
+
var element = event.findElement("a[data-method]");
|
76
|
+
if (element) {
|
77
|
+
handleMethod(element);
|
78
|
+
event.stop();
|
79
|
+
return true;
|
80
|
+
}
|
81
|
+
});
|
82
|
+
|
83
|
+
// TODO: I don't think submit bubbles in IE
|
84
|
+
$(document.body).observe("submit", function(event) {
|
85
|
+
var element = event.findElement(),
|
86
|
+
message = element.readAttribute('data-confirm');
|
87
|
+
if (message && !confirm(message)) {
|
88
|
+
event.stop();
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
|
92
|
+
var inputs = element.select("input[type=submit][data-disable-with]");
|
93
|
+
inputs.each(function(input) {
|
94
|
+
input.disabled = true;
|
95
|
+
input.writeAttribute('data-original-value', input.value);
|
96
|
+
input.value = input.readAttribute('data-disable-with');
|
97
|
+
});
|
98
|
+
|
99
|
+
var element = event.findElement("form[data-remote]");
|
100
|
+
if (element) {
|
101
|
+
handleRemote(element);
|
102
|
+
event.stop();
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
$(document.body).observe("ajax:after", function(event) {
|
107
|
+
var element = event.findElement();
|
108
|
+
|
109
|
+
if (element.tagName.toLowerCase() === 'form') {
|
110
|
+
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
111
|
+
inputs.each(function(input) {
|
112
|
+
input.value = input.readAttribute('data-original-value');
|
113
|
+
input.writeAttribute('data-original-value', null);
|
114
|
+
input.disabled = false;
|
115
|
+
});
|
116
|
+
}
|
117
|
+
});
|
118
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENV_PATH = File.expand_path('../../config/environment', __FILE__)
|
5
|
+
BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
|
6
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
7
|
+
|
8
|
+
require BOOT_PATH
|
9
|
+
require 'rails/commands'
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper.rb'))
|
2
|
+
|
3
|
+
shared_examples_for "enum_select form" do
|
4
|
+
it "should have select boxes for gender, status and degree initially set blank" do
|
5
|
+
visit form_page
|
6
|
+
select_option('', /gender/)
|
7
|
+
select_option('', /status/)
|
8
|
+
select_option('None', /degree/)
|
9
|
+
end
|
10
|
+
it "should verify all options for each enumeration" do
|
11
|
+
visit form_page
|
12
|
+
%w(Male Female).each {|e| select e, :from=>/gender/}
|
13
|
+
%w(Single Married Widowed Divorced).each {|e| select e, :from=>/status/}
|
14
|
+
["None", "High school", "College", "Graduate"].each {|e| select e, :from=>/degree/}
|
15
|
+
end
|
16
|
+
it "should submit and keep values when form is invalid" do
|
17
|
+
visit form_page
|
18
|
+
select 'Male', :from=>/gender/
|
19
|
+
select 'Single', :from=>/status/
|
20
|
+
select 'College', :from=>/degree/
|
21
|
+
click_button 'Save'
|
22
|
+
select_option('Male', /gender/)
|
23
|
+
select_option('Single', /status/)
|
24
|
+
select_option('College', /degree/)
|
25
|
+
end
|
26
|
+
it "should select values and submit without validation errors and create an object with those values" do
|
27
|
+
User.delete_all
|
28
|
+
visit form_page
|
29
|
+
select 'Male', :from=>/gender/
|
30
|
+
select 'Single', :from=>/status/
|
31
|
+
select 'College', :from=>/degree/
|
32
|
+
fill_in(/first_name/, :with=>'john')
|
33
|
+
fill_in(/age/, :with=>'30')
|
34
|
+
click_button 'Save'
|
35
|
+
#response.code.should be_success
|
36
|
+
u = User.find(:first)
|
37
|
+
u.first_name.should == 'john'
|
38
|
+
u.age.should == 30
|
39
|
+
u.gender.should == :male
|
40
|
+
u.status.should == :single
|
41
|
+
u.degree.should == :college
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "Form using form_for and FormBuilder" do
|
46
|
+
def form_page; '/form_test/form_for'; end
|
47
|
+
|
48
|
+
it_should_behave_like "enum_select form"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "Form using option_helper_tags" do
|
53
|
+
def form_page; '/form_test/form_tag'; end
|
54
|
+
|
55
|
+
it_should_behave_like "enum_select form"
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
=begin
|
60
|
+
describe "Form using ActiveRecord helpers" do
|
61
|
+
def form_page; '/form_test/form'; end
|
62
|
+
puts
|
63
|
+
puts "*****************************************************"
|
64
|
+
puts "warning: there's a bug in ActionView::Helpers::ActiveRecord 'form' method"
|
65
|
+
puts "must change in active_record_helper.rb 'form' method"
|
66
|
+
puts "contents = form_tag(:action=>action, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil)"
|
67
|
+
puts "to"
|
68
|
+
puts "contents = form_tag(action, :method =>(options[:method] || 'post'), :enctype => options[:multipart] ? 'multipart/form-data': nil)"
|
69
|
+
puts "*****************************************************"
|
70
|
+
puts
|
71
|
+
|
72
|
+
it_should_behave_like "enum_select form"
|
73
|
+
|
74
|
+
end
|
75
|
+
=end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
ENV["RAILS_ENV"] ||= 'test'
|
4
|
+
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
|
5
|
+
#require 'enumerated_attribute'
|
6
|
+
|
7
|
+
require 'spec/autorun'
|
8
|
+
gem 'rspec-rails', '>= 1.3.2'
|
9
|
+
require 'spec/rails'
|
10
|
+
gem 'webrat', '>= 0.7.1'
|
11
|
+
require 'webrat'
|
12
|
+
require 'matchers'
|
13
|
+
|
14
|
+
# Requires supporting files with custom matchers and macros, etc,
|
15
|
+
# in ./support/ and its subdirectories.
|
16
|
+
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
17
|
+
|
18
|
+
Webrat.configure do |config|
|
19
|
+
config.mode = :rails
|
20
|
+
end
|
21
|
+
|
22
|
+
Spec::Runner.configure do |config|
|
23
|
+
end
|
24
|
+
|
25
|
+
#setup for integrating webrat with rspec
|
26
|
+
module Spec::Rails::Example
|
27
|
+
class IntegrationExampleGroup < ActionController::IntegrationTest
|
28
|
+
|
29
|
+
def initialize(defined_description, options={}, &implementation)
|
30
|
+
defined_description.instance_eval do
|
31
|
+
def to_s
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
super(defined_description)
|
36
|
+
end
|
37
|
+
|
38
|
+
Spec::Example::ExampleGroupFactory.register(:integration, self)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
+
# -- they do not yet inherit this setting
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerated_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 55
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 16
|
10
|
+
version: 0.2.16
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jeff Patmon
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-11 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: meta_programming
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 21
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 2
|
@@ -139,6 +142,57 @@ files:
|
|
139
142
|
- spec/rails/spec/matchers.rb
|
140
143
|
- spec/rails/spec/spec.opts
|
141
144
|
- spec/new_and_method_missing_spec.rb
|
145
|
+
- spec/rails3/db/seeds.rb
|
146
|
+
- spec/rails3/app/helpers/application_helper.rb
|
147
|
+
- spec/rails3/app/helpers/form_test_helper.rb
|
148
|
+
- spec/rails3/app/views/form_test/form.html.erb
|
149
|
+
- spec/rails3/app/views/form_test/form_tag.html.erb
|
150
|
+
- spec/rails3/app/views/form_test/index.html.erb
|
151
|
+
- spec/rails3/app/views/form_test/form_for.html.erb
|
152
|
+
- spec/rails3/app/views/layouts/application.html.erb
|
153
|
+
- spec/rails3/app/controllers/form_test_controller.rb
|
154
|
+
- spec/rails3/app/controllers/application_controller.rb
|
155
|
+
- spec/rails3/app/models/user.rb
|
156
|
+
- spec/rails3/config/initializers/mime_types.rb
|
157
|
+
- spec/rails3/config/initializers/backtrace_silencers.rb
|
158
|
+
- spec/rails3/config/initializers/secret_token.rb
|
159
|
+
- spec/rails3/config/initializers/inflections.rb
|
160
|
+
- spec/rails3/config/initializers/session_store.rb
|
161
|
+
- spec/rails3/config/locales/en.yml
|
162
|
+
- spec/rails3/config/application.rb
|
163
|
+
- spec/rails3/config/boot.rb
|
164
|
+
- spec/rails3/config/environments/production.rb
|
165
|
+
- spec/rails3/config/environments/development.rb
|
166
|
+
- spec/rails3/config/environments/test.rb
|
167
|
+
- spec/rails3/config/database.yml
|
168
|
+
- spec/rails3/config/environment.rb
|
169
|
+
- spec/rails3/config/routes.rb
|
170
|
+
- spec/rails3/public/images/rails.png
|
171
|
+
- spec/rails3/public/500.html
|
172
|
+
- spec/rails3/public/javascripts/controls.js
|
173
|
+
- spec/rails3/public/javascripts/rails.js
|
174
|
+
- spec/rails3/public/javascripts/application.js
|
175
|
+
- spec/rails3/public/javascripts/dragdrop.js
|
176
|
+
- spec/rails3/public/javascripts/effects.js
|
177
|
+
- spec/rails3/public/javascripts/prototype.js
|
178
|
+
- spec/rails3/public/404.html
|
179
|
+
- spec/rails3/public/422.html
|
180
|
+
- spec/rails3/public/favicon.ico
|
181
|
+
- spec/rails3/public/robots.txt
|
182
|
+
- spec/rails3/public/index.html
|
183
|
+
- spec/rails3/Gemfile
|
184
|
+
- spec/rails3/README
|
185
|
+
- spec/rails3/Rakefile
|
186
|
+
- spec/rails3/script/rails
|
187
|
+
- spec/rails3/config.ru
|
188
|
+
- spec/rails3/test/performance/browsing_test.rb
|
189
|
+
- spec/rails3/test/test_helper.rb
|
190
|
+
- spec/rails3/spec/rcov.opts
|
191
|
+
- spec/rails3/spec/integrations/enum_select_spec.rb
|
192
|
+
- spec/rails3/spec/spec_helper.rb
|
193
|
+
- spec/rails3/spec/matchers.rb
|
194
|
+
- spec/rails3/spec/spec.opts
|
195
|
+
- spec/rails3/doc/README_FOR_APP
|
142
196
|
- spec/inheritance_spec.rb
|
143
197
|
- CHANGELOG.rdoc
|
144
198
|
- init.rb
|
@@ -156,23 +210,27 @@ rdoc_options: []
|
|
156
210
|
require_paths:
|
157
211
|
- lib
|
158
212
|
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
none: false
|
159
214
|
requirements:
|
160
215
|
- - ">="
|
161
216
|
- !ruby/object:Gem::Version
|
217
|
+
hash: 3
|
162
218
|
segments:
|
163
219
|
- 0
|
164
220
|
version: "0"
|
165
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
|
+
none: false
|
166
223
|
requirements:
|
167
224
|
- - ">="
|
168
225
|
- !ruby/object:Gem::Version
|
226
|
+
hash: 3
|
169
227
|
segments:
|
170
228
|
- 0
|
171
229
|
version: "0"
|
172
230
|
requirements: []
|
173
231
|
|
174
232
|
rubyforge_project:
|
175
|
-
rubygems_version: 1.3.
|
233
|
+
rubygems_version: 1.3.7
|
176
234
|
signing_key:
|
177
235
|
specification_version: 3
|
178
236
|
summary: Add enumerated attributes to your models and expose them in drop-down lists in your views
|