active_scaffold 3.4.0.1 → 3.4.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/app/views/active_scaffold_overrides/_search.html.erb +1 -1
- data/lib/active_scaffold/actions/list.rb +5 -5
- data/lib/active_scaffold/actions/nested.rb +1 -1
- data/lib/active_scaffold/attribute_params.rb +1 -1
- data/lib/active_scaffold/data_structures/action_columns.rb +1 -1
- data/lib/active_scaffold/helpers/list_column_helpers.rb +2 -1
- data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
- data/lib/active_scaffold/version.rb +1 -1
- data/test/misc/active_record_permissions_test.rb +1 -3
- data/test/misc/attribute_params_test.rb +10 -1
- data/test/misc/convert_numbers_format_test.rb +1 -2
- data/test/mock_app/app/models/building.rb +10 -1
- data/test/mock_app/app/models/floor.rb +1 -1
- data/test/mock_app/db/schema.rb +2 -0
- 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: c53462e9f8376026d9967b86c6e853504641002e
|
4
|
+
data.tar.gz: c7f5e3fdf9da980b02791d0d99d50f6377095070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f31c9d71a8ef33e63eae3987cd37a6bbd0327746db8af9f9c241e959be1a765fbd28da7edf25a41785add40a532f9963995052becf89c31870b65eac90cc3db4
|
7
|
+
data.tar.gz: af95b26715e8eaa8808dea19c2ea4b88650893892d1cd863f34e64f3c9db168570313d194cb1166b0e4c2bc1d2843261733672060f7a432a3ff45d520db58b1e
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
= 3.4.1
|
2
|
+
- fix search value when both field_search and search are enabled and a search with field_search is active
|
3
|
+
- fix cancan permissions check on subform
|
4
|
+
- fix has_one/belongs_to nested with :primary_key option
|
5
|
+
- fix display of virtual number columns
|
6
|
+
- fix display of serialized columns on list
|
7
|
+
- improve tests
|
8
|
+
|
1
9
|
= 3.4.0.1
|
2
10
|
- Fix record_select on field_search
|
3
11
|
|
@@ -7,7 +7,7 @@ options = {:id => element_form_id(:action => 'search'),
|
|
7
7
|
:'data-loading' => true,
|
8
8
|
:method => :get}
|
9
9
|
form_tag url_options, options %>
|
10
|
-
<%= search_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocomplete => :off, :placeholder => as_(live_search ? :live_search : :search_terms) %>
|
10
|
+
<%= search_field_tag :search, (search_params if search_params.is_a? String), :class => 'text-input', :id => search_input_id, :size => 50, :autocomplete => :off, :placeholder => as_(live_search ? :live_search : :search_terms) %>
|
11
11
|
<%= submit_tag as_(:search), :class => "submit", :style => ('display:none;' if live_search) %>
|
12
12
|
<%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel reset', :remote => true, :data => {:refresh => true} %>
|
13
13
|
<%= loading_indicator_tag(:action => :search) %>
|
@@ -77,10 +77,10 @@ module ActiveScaffold::Actions
|
|
77
77
|
self.active_scaffold_references.concat columns_for_joins.map(&:includes).flatten.uniq
|
78
78
|
end
|
79
79
|
|
80
|
-
def get_row(
|
80
|
+
def get_row(crud_type_or_security_options = :read)
|
81
81
|
set_includes_for_columns
|
82
82
|
klass = beginning_of_chain.preload(active_scaffold_preload)
|
83
|
-
@record = find_if_allowed(params[:id],
|
83
|
+
@record = find_if_allowed(params[:id], crud_type_or_security_options, klass)
|
84
84
|
end
|
85
85
|
|
86
86
|
# The actual algorithm to prepare for the list view
|
@@ -148,7 +148,7 @@ module ActiveScaffold::Actions
|
|
148
148
|
# self.successful = true
|
149
149
|
# flash[:info] = 'Player fired'
|
150
150
|
# end
|
151
|
-
def process_action_link_action(render_action = :action_update,
|
151
|
+
def process_action_link_action(render_action = :action_update, crud_type_or_security_options = nil)
|
152
152
|
if request.get?
|
153
153
|
# someone has disabled javascript, we have to show confirmation form first
|
154
154
|
@record = find_if_allowed(params[:id], :read) if params[:id] && params[:id].to_i > 0
|
@@ -156,8 +156,8 @@ module ActiveScaffold::Actions
|
|
156
156
|
else
|
157
157
|
@action_link = active_scaffold_config.action_links[action_name]
|
158
158
|
if params[:id] && params[:id].to_i > 0
|
159
|
-
|
160
|
-
get_row(
|
159
|
+
crud_type_or_security_options ||= (request.post? || request.put?) ? :update : :delete
|
160
|
+
get_row(crud_type_or_security_options)
|
161
161
|
unless @record.nil?
|
162
162
|
yield @record
|
163
163
|
else
|
@@ -82,7 +82,7 @@ module ActiveScaffold::Actions
|
|
82
82
|
elsif nested.child_association.nil? # without child_association is not possible to add conditions
|
83
83
|
active_scaffold_config.model
|
84
84
|
elsif nested.child_association.belongs_to?
|
85
|
-
active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record)
|
85
|
+
active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record.send(nested.association.association_primary_key))
|
86
86
|
elsif nested.association.belongs_to?
|
87
87
|
chain = active_scaffold_config.model.joins(nested.child_association.name)
|
88
88
|
table_name = if active_scaffold_config.model == nested.association.active_record
|
@@ -66,7 +66,7 @@ module ActiveScaffold
|
|
66
66
|
begin
|
67
67
|
parent_record.send "#{column.name}=", value
|
68
68
|
rescue ActiveRecord::RecordNotSaved
|
69
|
-
parent_record.association(column.name).target = value
|
69
|
+
parent_record.association(column.name).target = value if column.association
|
70
70
|
end
|
71
71
|
end
|
72
72
|
if column.association && [:has_one, :has_many].include?(column.association.macro) && column.association.reverse
|
@@ -111,7 +111,7 @@ module ActiveScaffold::DataStructures
|
|
111
111
|
# skip if this matches a constrained column
|
112
112
|
result = true if constraint_columns.include?(column.name.to_sym)
|
113
113
|
# skip this field if it's not authorized
|
114
|
-
unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.try(:crud_type), :column => column.name)
|
114
|
+
unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.try(:crud_type) || :read, :column => column.name)
|
115
115
|
self.unauthorized_columns << column.name.to_sym
|
116
116
|
result = true
|
117
117
|
end
|
@@ -74,7 +74,8 @@ module ActiveScaffold
|
|
74
74
|
## Overrides
|
75
75
|
##
|
76
76
|
def active_scaffold_column_text(record, column)
|
77
|
-
|
77
|
+
# `to_s` is necessary to convert objects in serialized columns to string before truncation.
|
78
|
+
clean_column_value(truncate(record.send(column.name).to_s, :length => column.options[:truncate] || 50))
|
78
79
|
end
|
79
80
|
|
80
81
|
def active_scaffold_column_fulltext(record, column)
|
@@ -484,7 +484,7 @@ module ActiveScaffold
|
|
484
484
|
@_column_classes[column.name] ||= begin
|
485
485
|
classes = "#{column.name}-column "
|
486
486
|
classes << 'sorted ' if active_scaffold_config.list.user.sorting.sorts_on?(column)
|
487
|
-
classes << 'numeric ' if column.
|
487
|
+
classes << 'numeric ' if column.number?
|
488
488
|
classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
|
489
489
|
end
|
490
490
|
classes = "#{@_column_classes[column.name]} "
|
@@ -2,9 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class PermissionModel < ActiveRecord::Base
|
4
4
|
include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model
|
5
|
-
def self.columns; [] end
|
6
|
-
def self.column_types; [] end
|
7
|
-
def self.columns_hash; {} end
|
5
|
+
def self.columns; @columns ||= [ColumnMock.new('id', '', 'int(11)')] + %w(a1 a2 a3 b1 b2 b3 c1 c2 c3).map {|c| ColumnMock.new(c, '', 'varchar(255)')}; end
|
8
6
|
|
9
7
|
def authorized_for_read?; true; end
|
10
8
|
def authorized_for_update?; false; end
|
@@ -13,11 +13,13 @@ class AttributeParamsTest < MiniTest::Test
|
|
13
13
|
assert model.save
|
14
14
|
|
15
15
|
model.buildings.create(:name => '1st building')
|
16
|
+
model.reload
|
16
17
|
model = update_record_from_params(model, :update, :first_name, :last_name, :first_name => 'Name', :last_name => 'Last')
|
17
18
|
assert_equal 'Name', model.first_name
|
18
19
|
assert_equal 'Last', model.last_name
|
19
20
|
assert model.buildings.present?, 'buildings should not be cleared'
|
20
21
|
assert model.save
|
22
|
+
assert_equal 1, model.buildings_count
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_saving_unexpected_column_is_ignored
|
@@ -46,6 +48,7 @@ class AttributeParamsTest < MiniTest::Test
|
|
46
48
|
assert_equal buildings.map(&:id), model.building_ids
|
47
49
|
assert_equal buildings, model.buildings
|
48
50
|
assert model.save
|
51
|
+
assert_equal 2, model.reload.buildings_count
|
49
52
|
|
50
53
|
model = update_record_from_params(model, :update, :first_name, :last_name, :buildings, :first_name => 'Name', :last_name => 'Last', :buildings => ['']) { raise ActiveRecord::Rollback }
|
51
54
|
assert_equal 'Name', model.first_name
|
@@ -53,8 +56,9 @@ class AttributeParamsTest < MiniTest::Test
|
|
53
56
|
assert_equal [model.id]*2, buildings.map{|b| b.reload.owner_id}, 'owners should not be saved'
|
54
57
|
assert model.building_ids.blank?, 'buildings should be cleared'
|
55
58
|
assert model.buildings.blank?, 'buildings should be cleared'
|
59
|
+
assert_equal 0, model.buildings.size
|
60
|
+
assert_equal 2, model.reload.buildings_count
|
56
61
|
|
57
|
-
model.reload
|
58
62
|
model = update_record_from_params(model, :update, :first_name, :last_name, :buildings, :first_name => 'Name', :last_name => 'Last', :buildings => [''])
|
59
63
|
assert_equal 'Name', model.first_name
|
60
64
|
assert_equal 'Last', model.last_name
|
@@ -62,17 +66,20 @@ class AttributeParamsTest < MiniTest::Test
|
|
62
66
|
assert model.buildings.blank?, 'buildings should be cleared'
|
63
67
|
assert_equal [nil]*2, buildings.map{|b| b.reload.owner_id}, 'buildings should be saved'
|
64
68
|
assert model.save
|
69
|
+
assert_equal 0, model.reload.buildings_count
|
65
70
|
end
|
66
71
|
|
67
72
|
def test_saving_belongs_to_select
|
68
73
|
person = Person.create
|
69
74
|
assert person.persisted?
|
75
|
+
assert_equal 0, person.floors_count
|
70
76
|
|
71
77
|
model = update_record_from_params(Floor.new, :create, :number, :tenant, :number => '1', :tenant => person.id.to_s)
|
72
78
|
assert_equal 1, model.number
|
73
79
|
assert_equal person.id, model.tenant_id
|
74
80
|
assert_equal person, model.tenant
|
75
81
|
assert model.save
|
82
|
+
assert_equal 1, person.reload.floors_count
|
76
83
|
|
77
84
|
model = update_record_from_params(model, :update, :number, :tenant, :number => '1', :tenant => '')
|
78
85
|
assert_equal 1, model.number
|
@@ -81,6 +88,7 @@ class AttributeParamsTest < MiniTest::Test
|
|
81
88
|
assert_equal person.id, Floor.find(model.id).tenant_id, 'floor should not be saved yet'
|
82
89
|
assert model.save
|
83
90
|
assert_nil Floor.find(model.id).tenant_id, 'floor should not be saved'
|
91
|
+
assert_equal 0, person.reload.floors_count
|
84
92
|
end
|
85
93
|
|
86
94
|
def test_saving_has_one_select
|
@@ -182,6 +190,7 @@ class AttributeParamsTest < MiniTest::Test
|
|
182
190
|
assert_equal floor.id, model.floors.first.id
|
183
191
|
assert_equal [nil, *people.map(&:id)], model.floors.map(&:tenant_id)
|
184
192
|
assert model.save
|
193
|
+
assert_equal [1, 1], people.map(&:reload).map(&:floors_count)
|
185
194
|
|
186
195
|
model = update_record_from_params(model, :update, :name, :floors, :name => 'Tower', :floors => {'0' => ''})
|
187
196
|
assert_equal 'Tower', model.name
|
@@ -2,9 +2,8 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class NumberModel < ActiveRecord::Base
|
4
4
|
include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model
|
5
|
-
abstract_class = true
|
6
5
|
def self.columns
|
7
|
-
@columns ||= [ColumnMock.new('number', '', 'double(10,2)')]
|
6
|
+
@columns ||= [ColumnMock.new('id', '', 'int(11)'), ColumnMock.new('number', '', 'double(10,2)')]
|
8
7
|
end
|
9
8
|
def self.columns_hash
|
10
9
|
@hash ||= Hash[@columns.map{|c| [c.name, c]}]
|
@@ -1,8 +1,17 @@
|
|
1
1
|
class Building < ActiveRecord::Base
|
2
|
-
belongs_to :owner, :class_name => 'Person'
|
2
|
+
belongs_to :owner, :class_name => 'Person', :counter_cache => true
|
3
3
|
has_many :floors, :dependent => :delete_all
|
4
4
|
|
5
5
|
has_one :address, :as => :addressable
|
6
6
|
|
7
7
|
has_many :tenants, :through => :floors, :class_name => 'Person'
|
8
|
+
|
9
|
+
if Rails.version < '4.1'
|
10
|
+
after_update :update_buildings_count, :if => :owner_id_changed?
|
11
|
+
|
12
|
+
def update_buildings_count
|
13
|
+
Person.decrement_counter(:buildings_count, owner_id_was) if owner_id_was
|
14
|
+
Person.increment_counter(:buildings_count, owner_id) if owner_id
|
15
|
+
end
|
16
|
+
end
|
8
17
|
end
|
data/test/mock_app/db/schema.rb
CHANGED
@@ -44,6 +44,8 @@ ActiveRecord::Schema.define do
|
|
44
44
|
create_table 'people' do |t|
|
45
45
|
t.string 'first_name'
|
46
46
|
t.string 'last_name'
|
47
|
+
t.integer 'buildings_count', :null => false, :default => 0
|
48
|
+
t.integer 'floors_count', :null => false, :default => 0
|
47
49
|
t.datetime "created_at"
|
48
50
|
t.datetime "updated_at"
|
49
51
|
end
|
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.1
|
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: 2014-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|