active_scaffold 3.4.21.1 → 3.4.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/app/assets/javascripts/jquery/active_scaffold.js +1 -1
- data/lib/active_scaffold/attribute_params.rb +19 -12
- data/lib/active_scaffold/core.rb +1 -1
- data/lib/active_scaffold/tableless.rb +1 -1
- data/lib/active_scaffold/version.rb +1 -1
- data/test/bridges/tiny_mce_test.rb +2 -2
- data/test/company.rb +1 -0
- data/test/misc/attribute_params_test.rb +16 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e3c5d2bad80f3ddbf5610ba433594ce55fc3373
|
4
|
+
data.tar.gz: a37268b8a8c4633e5324154e9c764ace3feecb94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05685d5fbbe603c317c6b01f5d2b6af1ba7fb44b8e246d6b2ac54675699d08f4263c529ed36042ba8135990b377b340b98371040bb3ebbde270db7f70651650
|
7
|
+
data.tar.gz: 838826402a406aada754ab436857ba53b3c4026a00466417d64970f9a52057154083bf006643d7e302b8db6f7891e0c101aba7b7fc477778c89b709a067ac9f1
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
= 3.4.22
|
2
|
+
- fix has_one/many tableless model through association
|
3
|
+
- fix check default value for checkboxes, so if record in subform, with checkbox, is left as default, is not saved, but setting checkbox would save record
|
4
|
+
- singular associations on subform are not always created, so you can leave default values on fields and skip creation, in other case some validations could fail and force to create singular associations
|
5
|
+
- fix counter cache on polymorphic for rails 4.2.1
|
6
|
+
- fix set cursor at end when focusing first element of form
|
7
|
+
|
1
8
|
= 3.4.21.1
|
2
9
|
- Fix field_search when contains is used on rails 4.2
|
3
10
|
|
@@ -613,7 +613,7 @@ var ActiveScaffold = {
|
|
613
613
|
if (typeof(form_element) == 'string') form_element = '#' + form_element;
|
614
614
|
if (typeof(form_selector) == 'undefined') form_selector = jQuery(form_element).is('form') ? '' : 'form ';
|
615
615
|
var input = jQuery(form_selector + ":input:visible:first", jQuery(form_element)).focus();
|
616
|
-
if (input[0].value) input[0].selectionStart = input[0].selectionEnd = input[0].value.length;
|
616
|
+
try { if (input[0] && input[0].value) input[0].selectionStart = input[0].selectionEnd = input[0].value.length; } catch(e) {}
|
617
617
|
},
|
618
618
|
|
619
619
|
create_record_row: function(active_scaffold_id, html, options) {
|
@@ -35,19 +35,19 @@ module ActiveScaffold
|
|
35
35
|
|
36
36
|
# workaround to update counters when belongs_to changes on persisted record on Rails 3
|
37
37
|
# workaround to update counters when polymorphic has_many changes on persisted record
|
38
|
-
# TODO: remove when rails3 support is removed and counter cache for polymorphic has_many association works on rails4
|
38
|
+
# TODO: remove when rails3 support is removed and counter cache for polymorphic has_many association works on rails4
|
39
39
|
def hack_for_has_many_counter_cache(parent_record, column, value)
|
40
40
|
association = parent_record.association(column.name)
|
41
41
|
counter_attr = association.send(:cached_counter_attribute_name)
|
42
42
|
difference = value.select(&:persisted?).size - parent_record.send(counter_attr)
|
43
43
|
|
44
44
|
if parent_record.new_record?
|
45
|
-
if Rails.version
|
46
|
-
parent_record.send "#{counter_attr}=", difference
|
47
|
-
parent_record.send "#{column.name}=", value
|
48
|
-
else
|
45
|
+
if Rails.version == '4.2.0'
|
49
46
|
parent_record.send "#{column.name}=", value
|
50
47
|
parent_record.send "#{counter_attr}_will_change!"
|
48
|
+
else # < 4.2 or > 4.2.0
|
49
|
+
parent_record.send "#{counter_attr}=", difference
|
50
|
+
parent_record.send "#{column.name}=", value
|
51
51
|
end
|
52
52
|
else
|
53
53
|
# don't decrement counter for deleted records, on destroy they will update counter
|
@@ -232,7 +232,7 @@ module ActiveScaffold
|
|
232
232
|
def build_record_from_params(params, column, record)
|
233
233
|
current = record.send(column.name)
|
234
234
|
klass = column.association.klass
|
235
|
-
|
235
|
+
(column.plural_association? && !column.show_blank_record?(current)) || !attributes_hash_is_empty?(params, klass)
|
236
236
|
end
|
237
237
|
|
238
238
|
# Attempts to create or find an instance of the klass of the association in parent_column from the
|
@@ -274,21 +274,23 @@ module ActiveScaffold
|
|
274
274
|
# Determines whether the given attributes hash is "empty".
|
275
275
|
# This isn't a literal emptiness - it's an attempt to discern whether the user intended it to be empty or not.
|
276
276
|
def attributes_hash_is_empty?(hash, klass)
|
277
|
-
|
277
|
+
# old style date form management... ignore them too
|
278
|
+
part_ignore_column_types = [:datetime, :date, :time]
|
279
|
+
|
278
280
|
hash.all? do |key, value|
|
279
281
|
# convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at'
|
280
282
|
parts = key.to_s.split('(')
|
281
|
-
# old style date form management... ignore them too
|
282
|
-
ignore_column_types = [:boolean, :datetime, :date, :time] if parts.length > 1
|
283
283
|
column_name = parts.first
|
284
284
|
column = klass.columns_hash[column_name]
|
285
285
|
|
286
286
|
# booleans and datetimes will always have a value. so we ignore them when checking whether the hash is empty.
|
287
287
|
# this could be a bad idea. but the current situation (excess record entry) seems worse.
|
288
|
-
next true if column &&
|
288
|
+
next true if column && parts.length > 1 && part_ignore_column_types.include?(column.type)
|
289
289
|
|
290
290
|
# defaults are pre-filled on the form. we can't use them to determine if the user intends a new row.
|
291
|
-
|
291
|
+
default_value = column_default_value(column_name, klass, column)
|
292
|
+
casted_value = column ? ActiveScaffold::Core.column_type_cast(value, column) : value
|
293
|
+
next true if casted_value == default_value
|
292
294
|
|
293
295
|
if value.is_a?(Hash)
|
294
296
|
attributes_hash_is_empty?(value, klass)
|
@@ -301,7 +303,12 @@ module ActiveScaffold
|
|
301
303
|
end
|
302
304
|
|
303
305
|
def column_default_value(column_name, klass, column)
|
304
|
-
|
306
|
+
return unless column
|
307
|
+
if Rails.version < '4.2'
|
308
|
+
column.default
|
309
|
+
else
|
310
|
+
column.type_cast_from_database(column.default)
|
311
|
+
end
|
305
312
|
end
|
306
313
|
end
|
307
314
|
end
|
data/lib/active_scaffold/core.rb
CHANGED
@@ -12,10 +12,10 @@ class TinyMceTest < ActionView::TestCase
|
|
12
12
|
|
13
13
|
def test_form_ui
|
14
14
|
config = ActiveScaffold::Config::Core.new(:company)
|
15
|
-
|
15
|
+
record = Company.new
|
16
16
|
expects(:request).returns(stub(:xhr? => true))
|
17
17
|
|
18
|
-
assert_dom_equal %{<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script#{' type="text/javascript"' if Rails::VERSION::MAJOR < 4}>\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"modern\"};tinyMCE.execCommand('mceAddEditor', false, 'record_name');\n//]]>\n</script>}, active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object =>
|
18
|
+
assert_dom_equal %{<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script#{' type="text/javascript"' if Rails::VERSION::MAJOR < 4}>\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"modern\"};tinyMCE.execCommand('mceAddEditor', false, 'record_name');\n//]]>\n</script>}, active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => record)
|
19
19
|
end
|
20
20
|
|
21
21
|
protected
|
data/test/company.rb
CHANGED
@@ -218,7 +218,7 @@ class AttributeParamsTest < MiniTest::Test
|
|
218
218
|
floor = Floor.create
|
219
219
|
people = 2.times.map { Person.create }
|
220
220
|
key = Time.now.to_i.to_s
|
221
|
-
floors = {'0' => '', floor.id.to_s => {:number => '1', :tenant => '', :id => floor.id.to_s}, key => {:number => '2', 'tenant' => people.first.id.to_s}, key.succ => {:number => '4', 'tenant' => people.last.id.to_s}}
|
221
|
+
floors = {'0' => '', floor.id.to_s => {:number => '1', :tenant => '', :id => floor.id.to_s}, key => {:number => '2', 'tenant' => people.first.id.to_s}, key.succ => {:number => '4', 'tenant' => people.last.id.to_s}, key.succ.succ => {:number => '', 'tenant' => ''}}
|
222
222
|
model = update_record_from_params(Building.new, :create, :name, :floors, :name => 'First', :floors => floors)
|
223
223
|
assert_equal 'First', model.name
|
224
224
|
assert_equal 3, model.floors.size
|
@@ -274,10 +274,23 @@ class AttributeParamsTest < MiniTest::Test
|
|
274
274
|
|
275
275
|
model = update_record_from_params(model, :update, :brand, :person, :brand => 'Mercedes', :person => {:first_name => ''})
|
276
276
|
assert_equal 'Mercedes', model.brand
|
277
|
-
|
277
|
+
assert_nil model.person
|
278
278
|
assert model.save
|
279
279
|
end
|
280
280
|
|
281
|
+
def test_saving_belongs_to_crud_with_boolean
|
282
|
+
model = update_record_from_params(Car.new, :create, :brand, :person, :brand => 'Ford', :person => {:first_name => '', :adult => '0'})
|
283
|
+
assert_equal 'Ford', model.brand
|
284
|
+
assert model.save
|
285
|
+
assert_nil model.person
|
286
|
+
|
287
|
+
model = update_record_from_params(model, :update, :brand, :person, :brand => 'Mercedes', :person => {:first_name => '', :adult => '1'})
|
288
|
+
assert_equal 'Mercedes', model.brand
|
289
|
+
assert model.person.present?
|
290
|
+
assert model.save
|
291
|
+
assert model.person.persisted?
|
292
|
+
end
|
293
|
+
|
281
294
|
def test_saving_has_one_crud
|
282
295
|
car = Car.create :brand => 'Renault'
|
283
296
|
assert car.persisted?
|
@@ -318,7 +331,7 @@ class AttributeParamsTest < MiniTest::Test
|
|
318
331
|
model = update_record_from_params(model, :update, :first_name, :car, :first_name => 'Name', :car => {:brand => ''})
|
319
332
|
assert_equal 'Name', model.first_name
|
320
333
|
assert_nil Car.where(:id => car.id).first, 'previous car should be deleted'
|
321
|
-
|
334
|
+
assert_nil model.car
|
322
335
|
assert model.save
|
323
336
|
end
|
324
337
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Many, see README
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brakeman
|