record_collection 0.7.4 → 0.7.5
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/.travis.yml +5 -1
- data/Gemfile +4 -0
- data/README.md +11 -1
- data/lib/record_collection/rails/form_options_helper.rb +29 -28
- data/lib/record_collection/version.rb +1 -1
- data/record_collection.gemspec +1 -0
- data/spec/dummy/app/models/project/collection.rb +1 -0
- data/spec/dummy/app/views/projects/collection_edit.html.slim +2 -1
- data/spec/dummy/config/locales/record_collection.en.yml +1 -1
- data/spec/dummy/db/migrate/20150721122805_add_description_to_projects.rb +5 -0
- data/spec/dummy/db/schema.rb +4 -3
- data/spec/features/translations_spec.rb +1 -1
- data/spec/rails/form_builder_spec.rb +76 -4
- data/spec/record_selection/name_spec.rb +10 -0
- data/spec/spec_helper.rb +2 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3ab00ef1adc5b2fba1f11c6775bdb5cedf3d131
|
4
|
+
data.tar.gz: 466e4feeaf5bbbee5f62dddf126159834a131c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be027edc729b7fb5c1bf0059c7bd6e874c68a788deb6970e0f648b1311549791479022306ab116df3bd6ae34cb1ae4f3e98951f08fb03bc6486013fd5b629962
|
7
|
+
data.tar.gz: 56cee9b7123367bcd065c0edb1be3cd1d576e584574943f9f29283ac3153796f4ce08e6cd0f05e9f1f8078a58fbbdb253f01de0c2ce75ee476a13ba6a9d36c41
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# RecordCollection
|
2
|
-
[
|
2
|
+
[](http://badge.fury.io/rb/record_collection)
|
3
|
+
[](https://travis-ci.org/bterkuile/record_collection)
|
3
4
|
[](https://codeclimate.com/github/bterkuile/record_collection)
|
5
|
+
[](https://codeclimate.com/github/bterkuile/record_collection/coverage)
|
4
6
|
|
5
7
|
record\_collection is a gem that adds functionality to rails to work
|
6
8
|
with collections. This consists of a few components:
|
@@ -11,6 +13,14 @@ with collections. This consists of a few components:
|
|
11
13
|
* the optionals helpers for managing attributes on the collection of
|
12
14
|
records you may or may not want to edit in the collection form
|
13
15
|
|
16
|
+
This gem is created for a project where acting on collections of records
|
17
|
+
was a key feature of the application. If you require really heavy client
|
18
|
+
side logic on collections, a client side framework might be the way to go
|
19
|
+
treating all records CRUD individually. This gem add two 'resourceful'
|
20
|
+
actions to a resource controller to act on collections (a subset) of
|
21
|
+
your records. Advanced failure handling is missing. Normal active
|
22
|
+
model validation is implemented.
|
23
|
+
|
14
24
|
## Installation
|
15
25
|
|
16
26
|
Add this line to your application's Gemfile:
|
@@ -16,15 +16,13 @@ class ActionView::Helpers::FormBuilder
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def optional_boolean(attr, options = {})
|
19
|
-
classes = get_optional_classes(attr, options.merge(base_class: 'optional-boolean'))
|
20
|
-
label_tag = label(attr, options[:label])
|
21
|
-
check_box_tag = check_box(attr, options)
|
22
|
-
add_collection_ids @template.content_tag(:div, label_tag + check_box_tag , class: classes, data: get_data_attributes(attr, options))
|
23
|
-
|
24
|
-
|
25
|
-
def optional_check_box(attr, options = {})
|
26
|
-
optional_boolean(attr, options)
|
19
|
+
#classes = get_optional_classes(attr, options.merge(base_class: 'optional-boolean'))
|
20
|
+
#label_tag = label(attr, options[:label])
|
21
|
+
#check_box_tag = check_box(attr, options)
|
22
|
+
#add_collection_ids @template.content_tag(:div, label_tag + check_box_tag , class: classes, data: get_data_attributes(attr, options))
|
23
|
+
optional_form_element(:check_box, attr, options.reverse_merge(base_class: 'optional-boolean'))
|
27
24
|
end
|
25
|
+
alias_method :optional_check_box, :optional_boolean
|
28
26
|
|
29
27
|
def optional_input(attr, options = {})
|
30
28
|
classes = get_optional_classes(attr, options.reverse_merge(base_class: 'optional-input'))
|
@@ -32,42 +30,45 @@ class ActionView::Helpers::FormBuilder
|
|
32
30
|
end
|
33
31
|
|
34
32
|
def optional_text_field(attr, options={})
|
35
|
-
|
36
|
-
add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_field(attr, options), class: classes, data: get_data_attributes(attr))
|
33
|
+
optional_form_element(:text_area, attr, options.reverse_merge(base_class: 'optional-text-field'))
|
37
34
|
end
|
38
35
|
|
39
36
|
def optional_text_area(attr, options={})
|
37
|
+
optional_form_element(:text_area, attr, options.reverse_merge(base_class: 'optional-text-area'))
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_optional_classes(attr, options = {})
|
41
|
+
classes = [options[:base_class] || 'optional-input', 'optional-attribute-container', attr, active_class(attr)]
|
42
|
+
classes << 'disabled' if options[:disabled]
|
43
|
+
classes << 'one' if !object.is_a?(RecordCollection::Base) or object.one?
|
44
|
+
classes << 'error' if object.errors[attr].present?
|
45
|
+
classes
|
46
|
+
end
|
47
|
+
|
48
|
+
def optional_form_element(element, attr, options = {})
|
40
49
|
classes = get_optional_classes(attr, options.reverse_merge(base_class: 'optional-text-area'))
|
41
|
-
add_collection_ids @template.content_tag(:div, label(attr, options[:label]) +
|
50
|
+
add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + send(element, attr, options), class: classes, data: get_data_attributes(attr, options))
|
42
51
|
end
|
43
52
|
|
53
|
+
private
|
54
|
+
|
44
55
|
def get_data_attributes(attr, options = {})
|
45
|
-
one = true
|
46
|
-
one = object.one? if object.is_a? RecordCollection::Base
|
56
|
+
one = object.is_a?(RecordCollection::Base) ? object.one? : true
|
47
57
|
attrs = {attribute: attr, one: one}
|
48
58
|
attrs[:disabled] = true if options[:disabled]
|
49
59
|
attrs
|
50
60
|
end
|
51
61
|
|
52
|
-
def
|
53
|
-
active = false
|
62
|
+
def active_class(attr)
|
63
|
+
active = false # default
|
54
64
|
if object.respond_to?(:uniform_collection_attribute)
|
55
65
|
uniform_value = object.uniform_collection_attribute(attr, set_if_nil: true)
|
56
|
-
# The field is active when the uniform value is not nil
|
66
|
+
# The field is active when the uniform value is not nil,
|
67
|
+
# aka has a value
|
57
68
|
active = !uniform_value.nil?
|
58
69
|
end
|
59
|
-
active = true unless object.public_send(attr).nil? # Activate if collection attribute is not nil
|
60
|
-
|
61
|
-
classes << (active ? 'active' : 'inactive')
|
62
|
-
classes << 'disabled' if options[:disabled]
|
63
|
-
if object.is_a? RecordCollection::Base
|
64
|
-
classes << 'one' if object.one?
|
65
|
-
else
|
66
|
-
# Assume normal record, this always behaves like one
|
67
|
-
classes << 'one'
|
68
|
-
end
|
69
|
-
classes << 'error' if object.errors[attr].present?
|
70
|
-
classes
|
70
|
+
active = true unless object.public_send(attr).nil? # Activate if collection or record attribute is not nil
|
71
|
+
active ? 'active' : 'inactive'
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
data/record_collection.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
#spec.add_development_dependency "rspec", ">= 3.1.0"
|
24
24
|
spec.add_development_dependency "rspec-rails", "~> 3.1"
|
25
|
+
spec.add_development_dependency "rspec-its"
|
25
26
|
spec.add_development_dependency "pry", ">= 0.1"
|
26
27
|
spec.add_development_dependency "rails", "~> 4.1"
|
27
28
|
spec.add_development_dependency "sqlite3"
|
@@ -1,7 +1,8 @@
|
|
1
|
-
h1 Edit multiple
|
1
|
+
h1 Edit multiple projects
|
2
2
|
= form_for @collection, url: [:collection_update, @collection] do |f|
|
3
3
|
= render 'form_errors', target: @collection
|
4
4
|
.form-inputs= f.optional_boolean :finished, disabled: true
|
5
|
+
.form-inputs= f.optional_text_area :description
|
5
6
|
.form-actions= f.submit
|
6
7
|
.page-actions
|
7
8
|
= link_to 'Back', employees_path
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20150721122805) do
|
15
15
|
|
16
16
|
create_table "employees", force: :cascade do |t|
|
17
17
|
t.string "name"
|
@@ -26,8 +26,9 @@ ActiveRecord::Schema.define(version: 20150204125014) do
|
|
26
26
|
t.string "name"
|
27
27
|
t.boolean "finished"
|
28
28
|
t.string "state"
|
29
|
-
t.datetime "created_at",
|
30
|
-
t.datetime "updated_at",
|
29
|
+
t.datetime "created_at", null: false
|
30
|
+
t.datetime "updated_at", null: false
|
31
|
+
t.text "description"
|
31
32
|
end
|
32
33
|
|
33
34
|
end
|
@@ -4,6 +4,6 @@ RSpec.feature "Multi select", type: :feature do
|
|
4
4
|
scenario "Selecting all", js: true do
|
5
5
|
employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
6
6
|
visit collection_edit_employees_path(ids: [employee.id])
|
7
|
-
find('[name="commit"]').value.should eq "Update
|
7
|
+
find('[name="commit"]').value.should eq "Update Employees collection"
|
8
8
|
end
|
9
9
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe ActionView::Helpers::FormBuilder do
|
4
4
|
let(:employee){ Employee.create section: 'SE1' }
|
5
|
-
|
5
|
+
let(:arguments){ {form_object: Employee::Collection.new([employee])} }
|
6
|
+
subject{ described_class.new :collection, arguments[:form_object], @template, {}}
|
6
7
|
before do
|
7
8
|
# http://pivotallabs.com/testing-custom-form-builder/
|
8
9
|
@template = Object.new
|
@@ -17,8 +18,79 @@ RSpec.describe ActionView::Helpers::FormBuilder do
|
|
17
18
|
end
|
18
19
|
|
19
20
|
it "does not raise when the object is not a collection object" do
|
20
|
-
|
21
|
-
expect{
|
21
|
+
arguments[:form_object] = employee
|
22
|
+
expect{ subject.collection_ids }.not_to raise_error
|
22
23
|
end
|
23
24
|
end
|
25
|
+
|
26
|
+
describe '#get_optional_classes' do
|
27
|
+
|
28
|
+
describe 'active/inactive' do
|
29
|
+
it "does not include active when record has no value" do
|
30
|
+
employee.section = nil
|
31
|
+
subject.get_optional_classes(:section).should_not include'active'
|
32
|
+
subject.get_optional_classes(:section).should include'inactive'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "includes active when record has en empty value" do
|
36
|
+
employee.section = ''
|
37
|
+
subject.get_optional_classes(:section).should include'active'
|
38
|
+
subject.get_optional_classes(:section).should_not include'inactive'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'includes active when two records have the same value' do
|
42
|
+
employee_2 = Employee.create section: 'SE1'
|
43
|
+
arguments[:form_object] = Employee::Collection.new([employee, employee_2])
|
44
|
+
subject.get_optional_classes(:section).should include'active'
|
45
|
+
subject.get_optional_classes(:section).should_not include'inactive'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'does not include active when two records have different values' do
|
49
|
+
employee_2 = Employee.create section: 'SE2'
|
50
|
+
arguments[:form_object] = Employee::Collection.new([employee, employee_2])
|
51
|
+
subject.get_optional_classes(:section).should_not include'active'
|
52
|
+
subject.get_optional_classes(:section).should include'inactive'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'one' do
|
57
|
+
it "includes one if only one record is present" do
|
58
|
+
subject.get_optional_classes(:section).should include'one'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "includes one if the form record is not a collection but a normal record" do
|
62
|
+
arguments[:form_object] = employee
|
63
|
+
subject.get_optional_classes(:section).should include'one'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "does not include one for a collection having more than one records" do
|
67
|
+
employee_2 = Employee.create section: 'SE2'
|
68
|
+
arguments[:form_object] = Employee::Collection.new([employee, employee_2])
|
69
|
+
subject.get_optional_classes(:section).should_not include'one'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'error' do
|
74
|
+
it "has no error class without any arguments set" do
|
75
|
+
subject.get_optional_classes(:section).should_not include'error'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "has no error class with valid argument set" do
|
79
|
+
arguments[:form_object].update(section: 'Se9').should be_truthy
|
80
|
+
subject.get_optional_classes(:section).should_not include'error'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "has error class with invalid argument set" do
|
84
|
+
arguments[:form_object].update(section: 'INVALID NAME').should be false
|
85
|
+
subject.get_optional_classes(:section).should include'error'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'disabled' do
|
90
|
+
it "adds disabled when given as option" do
|
91
|
+
subject.get_optional_classes(:section, disabled: true).should include'disabled'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
24
96
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RecordCollection::Name do
|
4
|
+
let(:employee){ Employee.create section: 'SE1' }
|
5
|
+
subject{ Employee::Collection.new([employee]).model_name }
|
6
|
+
|
7
|
+
its(:singular_route_key){ should eq 'employee' }
|
8
|
+
its(:route_key){ should eq 'employees' }
|
9
|
+
its(:human){ should eq 'Employees collection' }
|
10
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
ENV["RAILS_ENV"] = "test"
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
2
4
|
|
3
5
|
require 'pry'
|
4
|
-
|
5
6
|
require File.expand_path("../../spec/dummy/config/environment.rb", __FILE__)
|
6
7
|
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../spec/dummy/db/migrate", __FILE__)]
|
7
8
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin ter Kuile
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: pry
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -452,6 +466,7 @@ files:
|
|
452
466
|
- spec/dummy/db/migrate/20150204103712_add_vegan_to_employees.rb
|
453
467
|
- spec/dummy/db/migrate/20150204103925_add_admin_to_employees.rb
|
454
468
|
- spec/dummy/db/migrate/20150204125014_create_projects.rb
|
469
|
+
- spec/dummy/db/migrate/20150721122805_add_description_to_projects.rb
|
455
470
|
- spec/dummy/db/schema.rb
|
456
471
|
- spec/dummy/lib/assets/.keep
|
457
472
|
- spec/dummy/log/.keep
|
@@ -468,6 +483,7 @@ files:
|
|
468
483
|
- spec/fixtures/collections.rb
|
469
484
|
- spec/rails/form_builder_spec.rb
|
470
485
|
- spec/record_selection/base_spec.rb
|
486
|
+
- spec/record_selection/name_spec.rb
|
471
487
|
- spec/spec_helper.rb
|
472
488
|
homepage: https://github.com/bterkuile/record_collection
|
473
489
|
licenses:
|
@@ -564,6 +580,7 @@ test_files:
|
|
564
580
|
- spec/dummy/db/migrate/20150204103712_add_vegan_to_employees.rb
|
565
581
|
- spec/dummy/db/migrate/20150204103925_add_admin_to_employees.rb
|
566
582
|
- spec/dummy/db/migrate/20150204125014_create_projects.rb
|
583
|
+
- spec/dummy/db/migrate/20150721122805_add_description_to_projects.rb
|
567
584
|
- spec/dummy/db/schema.rb
|
568
585
|
- spec/dummy/lib/assets/.keep
|
569
586
|
- spec/dummy/log/.keep
|
@@ -580,5 +597,6 @@ test_files:
|
|
580
597
|
- spec/fixtures/collections.rb
|
581
598
|
- spec/rails/form_builder_spec.rb
|
582
599
|
- spec/record_selection/base_spec.rb
|
600
|
+
- spec/record_selection/name_spec.rb
|
583
601
|
- spec/spec_helper.rb
|
584
602
|
has_rdoc:
|