autonumeric-rails 0.1.9.17 → 1.9.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -1
- data/.rspec +2 -0
- data/CHANGELOG.md +15 -0
- data/README.md +12 -2
- data/Rakefile +9 -1
- data/autonumeric-rails.gemspec +10 -0
- data/lib/autonumeric/rails/version.rb +1 -1
- data/spec/autonumeric-rails_spec.rb +113 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +14 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +15 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/forms_controller.rb +12 -0
- data/spec/dummy/app/controllers/records_controller.rb +17 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/record.rb +2 -0
- data/spec/dummy/app/views/forms/dynamic_field.html.erb +16 -0
- data/spec/dummy/app/views/forms/through_form_helper.html.erb +5 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +27 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20131227002328_create_records.rb +8 -0
- data/spec/dummy/db/schema.rb +21 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/spec_helper.rb +50 -0
- data/spec/support/general.rb +8 -0
- data/vendor/assets/javascripts/{autoNumeric-1.9.17.js → autoNumeric-1.9.18.js} +3 -3
- data/vendor/assets/javascripts/autonumeric.js +1 -1
- data/vendor/assets/javascripts/autonumeric_ujs.js +40 -16
- metadata +186 -3
data/.gitignore
CHANGED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# 1.9.18.0
|
2
|
+
|
3
|
+
- Update autoNumeric v 1.9.18
|
4
|
+
- Rewrite JS code using Javascript class, to keep things clean
|
5
|
+
- Add support for dynamically generated DOM elements, with limitations (see README)
|
6
|
+
- Write proper tests
|
7
|
+
- Fix bug when value of an existing record could be lost
|
8
|
+
|
9
|
+
# 0.1.9.17
|
10
|
+
|
11
|
+
- Update autoNumeric v 1.9.17
|
12
|
+
|
13
|
+
# 0.1.9.15
|
14
|
+
|
15
|
+
- Initial version, wrapping autoNumeric v 1.9.15
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
## autonumeric-rails
|
2
2
|
|
3
|
-
Wrap up the
|
3
|
+
Wrap up the excellent autoNumeric.js javascript library
|
4
4
|
|
5
5
|
autoNumeric is a jQuery plugin that automatically formats currency (money) and numbers as you type on form inputs.
|
6
6
|
It supports most International numeric formats and currency signs including those used in Europe, North and
|
@@ -43,6 +43,16 @@ You can also pass autoNumeric configuration parameters directly with a Hash in y
|
|
43
43
|
<% end %>
|
44
44
|
|
45
45
|
See autoNumeric pages (links above) for all details on configuration and options
|
46
|
+
|
47
|
+
## Internal and compatibility
|
48
|
+
|
49
|
+
Autonumeric-rails creates in the DOM an hidden input with the same name as the text field.
|
50
|
+
On each modification of the test field value, the hidden input is updated with the sanitized value.
|
51
|
+
When validating the form the hidden form value is naturally sent to the server as it is located after the text field.
|
52
|
+
|
53
|
+
I've tried to add support for dynamically generated fields (through AJAX or other JS functions)
|
54
|
+
and seems to works OK. But it relies on DOM event "DOMNodeInserted" which seems not to be
|
55
|
+
compatible with IE 8 and older.
|
46
56
|
|
47
57
|
## Contributing
|
48
58
|
|
data/Rakefile
CHANGED
data/autonumeric-rails.gemspec
CHANGED
@@ -14,10 +14,20 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = `git ls-files -- test/*`.split($/)
|
17
18
|
spec.require_paths = ['lib']
|
18
19
|
|
19
20
|
spec.add_dependency 'jquery-rails', '>= 2.0.2'
|
20
21
|
|
21
22
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
23
|
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rails', '~> 4.0.2'
|
25
|
+
spec.add_development_dependency 'sqlite3'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'rspec-rails'
|
28
|
+
spec.add_development_dependency 'rspec-html-matchers'
|
29
|
+
spec.add_development_dependency 'database_cleaner'
|
30
|
+
spec.add_development_dependency 'capybara'
|
31
|
+
spec.add_development_dependency 'selenium-webdriver'
|
32
|
+
spec.add_development_dependency 'headless'
|
23
33
|
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'all autonumeric-rails tests' do
|
4
|
+
context 'Without DB' do
|
5
|
+
let(:record_id) { '' }
|
6
|
+
|
7
|
+
it 'Input tag' do
|
8
|
+
assert_selector("input#record_field1[name='record[field1]'][data-autonumeric='true']")
|
9
|
+
assert_selector("input#record_field2[name='record[field2]'][data-autonumeric='#{params}']")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Hidden tags' do
|
13
|
+
assert_selector("input#record_field1_val[name='record[field1]'][type='hidden']")
|
14
|
+
assert_selector("input#record_field2_val[name='record[field2]'][type='hidden']")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'Hidden tag is located after Input tag' do
|
18
|
+
find(:xpath, ".//*[@id='record_field1']/following-sibling::*[1]")['id'].should eq('record_field1_val')
|
19
|
+
find(:xpath, ".//*[@id='record_field2']/following-sibling::*[1]")['id'].should eq('record_field2_val')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'Set empty default values' do
|
23
|
+
find('#record_field1').value.should eq('')
|
24
|
+
find('#record_field1_val').value.should eq('')
|
25
|
+
|
26
|
+
find('#record_field2').value.should eq('')
|
27
|
+
find('#record_field2_val').value.should eq('')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'Typing value updates hidden field value' do
|
31
|
+
find('#record_field1').set '12345'
|
32
|
+
find('#record_field2').set '54321.987'
|
33
|
+
|
34
|
+
find('#record_field1').value.should eq('12,345.00')
|
35
|
+
find('#record_field1_val').value.should eq('12345')
|
36
|
+
|
37
|
+
find('#record_field2').value.should eq('USD 54,321.9')
|
38
|
+
find('#record_field2_val').value.should eq('54321.9')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'Creates record without values' do
|
42
|
+
click_button 'Go'
|
43
|
+
|
44
|
+
from_db = Record.last
|
45
|
+
from_db.field1.should eq(nil)
|
46
|
+
from_db.field2.should eq(nil)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Creates record with values' do
|
50
|
+
find('#record_field1').set '122333'
|
51
|
+
find('#record_field2').set '4444.5'
|
52
|
+
click_button 'Go'
|
53
|
+
|
54
|
+
from_db = Record.last
|
55
|
+
from_db.field1.should eq(122333)
|
56
|
+
from_db.field2.should eq(4444.5)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'With DB record' do
|
61
|
+
let(:record) { Record.create field1: 112233, field2: 445566.7 }
|
62
|
+
let(:record_id) { "/#{record.id}" }
|
63
|
+
|
64
|
+
it 'Loads record and set values' do
|
65
|
+
find('#record_field1').value.should eq('112,233.00')
|
66
|
+
find('#record_field1_val').value.should eq('112233')
|
67
|
+
|
68
|
+
find('#record_field2').value.should eq('USD 445,566.7')
|
69
|
+
find('#record_field2_val').value.should eq('445566.7')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'Without modifying values' do
|
73
|
+
click_button 'Go'
|
74
|
+
|
75
|
+
from_db = Record.find record.id
|
76
|
+
from_db.field1.should eq(112233)
|
77
|
+
from_db.field2.should eq(445566.7)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'Updates record' do
|
81
|
+
find('#record_field1').set '332211'
|
82
|
+
find('#record_field2').set '776655.4'
|
83
|
+
click_button 'Go'
|
84
|
+
|
85
|
+
from_db = Record.find record.id
|
86
|
+
from_db.field1.should eq(332211)
|
87
|
+
from_db.field2.should eq(776655.4)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
describe 'Autonumeric-rails', type: :feature, js: true do
|
95
|
+
|
96
|
+
subject { page }
|
97
|
+
|
98
|
+
let(:params) { {aSign: 'USD ', mDec: 1}.to_json }
|
99
|
+
|
100
|
+
before { visit "/#{url}#{record_id}" }
|
101
|
+
before { wait_for_jquery }
|
102
|
+
|
103
|
+
context 'Through form helper' do
|
104
|
+
let(:url) { 'through_form_helper' }
|
105
|
+
it_behaves_like 'all autonumeric-rails tests'
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'With dynamically created fields' do
|
109
|
+
let(:url) { 'dynamic_field' }
|
110
|
+
it_behaves_like 'all autonumeric-rails tests'
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
data/spec/dummy/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require autonumeric
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery with: :exception
|
3
|
+
|
4
|
+
def self.create_action(name)
|
5
|
+
define_method(name) do
|
6
|
+
send :without_record
|
7
|
+
render action: name
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method("#{name}_with_record".to_sym) do
|
11
|
+
send :with_record
|
12
|
+
render action: name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class RecordsController < ApplicationController
|
2
|
+
def create
|
3
|
+
Record.create record_params
|
4
|
+
render nothing: true
|
5
|
+
end
|
6
|
+
|
7
|
+
def update
|
8
|
+
Record.find(params[:id]).update_attributes record_params
|
9
|
+
render nothing: true
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def record_params
|
15
|
+
params.require(:record).permit [:field1, :field2]
|
16
|
+
end
|
17
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%= form_for @record do |f| %>
|
2
|
+
<%= f.text_field :field2, data: {autonumeric: {aSign: 'USD ', mDec: 1}} %>
|
3
|
+
<%= f.submit 'Go' %>
|
4
|
+
<% end %>
|
5
|
+
|
6
|
+
<script>
|
7
|
+
jQuery(function() {
|
8
|
+
var hidden;
|
9
|
+
hidden = $('<input>').attr('id', 'record_field1').attr('name', 'record[field1]');
|
10
|
+
hidden.attr('data-autonumeric', 'true').data('autonumeric', 'true');
|
11
|
+
<% if @record.field1 %>
|
12
|
+
hidden.val('<%= @record.field1.to_s %>');
|
13
|
+
<% end %>
|
14
|
+
$('form').prepend(hidden);
|
15
|
+
});
|
16
|
+
</script>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'active_record/railtie'
|
4
|
+
require 'action_controller/railtie'
|
5
|
+
require 'action_mailer/railtie'
|
6
|
+
require 'sprockets/railtie'
|
7
|
+
require 'jquery-rails'
|
8
|
+
|
9
|
+
Bundler.require(*Rails.groups)
|
10
|
+
require 'autonumeric-rails'
|
11
|
+
|
12
|
+
module Dummy
|
13
|
+
class Application < Rails::Application
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
|
18
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
19
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
20
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
21
|
+
|
22
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
23
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
24
|
+
# config.i18n.default_locale = :de
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|