record_collection 0.10.4 → 1.0.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 +5 -5
- data/config/environment.rb +1 -0
- data/lib/record_collection/rails/form_helper.rb +7 -5
- data/lib/record_collection/version.rb +1 -1
- metadata +13 -269
- data/.gitignore +0 -24
- data/.rspec +0 -1
- data/.travis.yml +0 -11
- data/CHANGELOG.md +0 -83
- data/Gemfile +0 -21
- data/LICENSE.txt +0 -22
- data/app/assets/images/record_collection/.keep +0 -0
- data/record_collection.gemspec +0 -50
- data/spec/base/accessors_spec.rb +0 -20
- data/spec/base/after_record_update_no_arity_spec.rb +0 -15
- data/spec/base/after_record_update_spec.rb +0 -22
- data/spec/base/before_record_update_no_arity_spec.rb +0 -15
- data/spec/base/before_record_update_spec.rb +0 -22
- data/spec/base/behaviour_spec.rb +0 -39
- data/spec/base/finding_records_spec.rb +0 -98
- data/spec/base/inheritance_spec.rb +0 -15
- data/spec/base/refine_relation_spec.rb +0 -10
- data/spec/base/validations_spec.rb +0 -26
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js.coffee +0 -15
- data/spec/dummy/app/assets/javascripts/foundation.min.js +0 -6081
- data/spec/dummy/app/assets/javascripts/modernizr.js +0 -8
- data/spec/dummy/app/assets/stylesheets/application.sass +0 -3
- data/spec/dummy/app/assets/stylesheets/components/_forms.sass +0 -4
- data/spec/dummy/app/assets/stylesheets/components/_structure.sass +0 -9
- data/spec/dummy/app/assets/stylesheets/foundation.css +0 -6201
- data/spec/dummy/app/assets/stylesheets/normalize.css +0 -427
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/dashboard_controller.rb +0 -4
- data/spec/dummy/app/controllers/employees_controller.rb +0 -73
- data/spec/dummy/app/controllers/projects_controller.rb +0 -73
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- 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/employee/collection.rb +0 -6
- data/spec/dummy/app/models/employee.rb +0 -3
- data/spec/dummy/app/models/project/collection.rb +0 -6
- data/spec/dummy/app/models/project.rb +0 -3
- data/spec/dummy/app/views/application/_form_errors.html.slim +0 -8
- data/spec/dummy/app/views/dashboard/home.html.slim +0 -1
- data/spec/dummy/app/views/employees/_form.html.erb +0 -25
- data/spec/dummy/app/views/employees/collection_edit.html.slim +0 -11
- data/spec/dummy/app/views/employees/edit.html.erb +0 -6
- data/spec/dummy/app/views/employees/index.html.slim +0 -28
- data/spec/dummy/app/views/employees/new.html.erb +0 -5
- data/spec/dummy/app/views/employees/show.html.erb +0 -14
- data/spec/dummy/app/views/layouts/application.html.slim +0 -30
- data/spec/dummy/app/views/projects/_form.html.erb +0 -21
- data/spec/dummy/app/views/projects/collection_edit.html.slim +0 -12
- data/spec/dummy/app/views/projects/edit.html.erb +0 -6
- data/spec/dummy/app/views/projects/index.html.slim +0 -20
- data/spec/dummy/app/views/projects/new.html.erb +0 -5
- data/spec/dummy/app/views/projects/show.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/record_collection.en.yml +0 -28
- data/spec/dummy/config/routes.rb +0 -5
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/migrate/20150203124634_create_employees.rb +0 -10
- data/spec/dummy/db/migrate/20150204103712_add_vegan_to_employees.rb +0 -5
- data/spec/dummy/db/migrate/20150204103925_add_admin_to_employees.rb +0 -5
- data/spec/dummy/db/migrate/20150204125014_create_projects.rb +0 -11
- data/spec/dummy/db/migrate/20150721122805_add_description_to_projects.rb +0 -5
- data/spec/dummy/db/migrate/20151215123553_add_project_id_to_employees.rb +0 -5
- data/spec/dummy/db/migrate/20151225113902_add_start_date_to_projects.rb +0 -5
- data/spec/dummy/db/migrate/20151226083300_add_hint_visible_to_projects.rb +0 -5
- data/spec/dummy/db/schema.rb +0 -37
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/disabled_boolean_spec.rb +0 -19
- data/spec/features/multi_select_spec.rb +0 -24
- data/spec/features/optional_boolean_hint_and_append_text_spec.rb +0 -12
- data/spec/features/optional_boolean_with_normal_resource_spec.rb +0 -20
- data/spec/features/optional_date_field_all_nil_spec.rb +0 -10
- data/spec/features/optional_text_field_with_normal_resource_spec.rb +0 -16
- data/spec/features/optionals_with_one_record_spec.rb +0 -16
- data/spec/features/translations_spec.rb +0 -9
- data/spec/fixtures/collections.rb +0 -0
- data/spec/rails/form_builder_spec.rb +0 -113
- data/spec/rails/form_for_spec.rb +0 -58
- data/spec/record_selection/base_spec.rb +0 -157
- data/spec/record_selection/name_spec.rb +0 -10
- data/spec/spec_helper.rb +0 -32
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
class AfterRecordUpdateCollection < RecordCollection::Base
|
3
|
-
attribute :section
|
4
|
-
after_record_update{|record| record.update(admin: true) }
|
5
|
-
end
|
6
|
-
RSpec.describe AfterRecordUpdateCollection do
|
7
|
-
subject { described_class.new }
|
8
|
-
|
9
|
-
it "executes on the record" do
|
10
|
-
employee = Employee.create section: 'SE1', admin: false
|
11
|
-
described_class.new([employee]).update({})
|
12
|
-
employee.reload
|
13
|
-
employee.admin.should be true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "will not be overridden by the update action itself (hence after)" do
|
17
|
-
employee = Employee.create section: 'SE1', admin: false
|
18
|
-
described_class.new([employee]).update(admin: false)
|
19
|
-
employee.reload
|
20
|
-
employee.admin.should be true
|
21
|
-
end
|
22
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
class BeforeRecordUpdateNoArityCollection < RecordCollection::Base
|
3
|
-
attribute :section
|
4
|
-
attribute :admin
|
5
|
-
before_record_update{ do_a_trick }
|
6
|
-
end
|
7
|
-
|
8
|
-
RSpec.describe BeforeRecordUpdateNoArityCollection do
|
9
|
-
subject { described_class.new }
|
10
|
-
it "triggers the method" do
|
11
|
-
employee = Employee.create section: 'SE1', admin: false
|
12
|
-
expect( employee ).to receive :do_a_trick
|
13
|
-
described_class.new([employee]).update({})
|
14
|
-
end
|
15
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
class BeforeRecordUpdateCollection < RecordCollection::Base
|
3
|
-
attribute :section
|
4
|
-
attribute :admin
|
5
|
-
before_record_update{|record| record.admin = true }
|
6
|
-
end
|
7
|
-
RSpec.describe BeforeRecordUpdateCollection do
|
8
|
-
subject { described_class.new }
|
9
|
-
it "executes on the record" do
|
10
|
-
employee = Employee.create section: 'SE1', admin: false
|
11
|
-
described_class.new([employee]).update({})
|
12
|
-
employee.reload
|
13
|
-
employee.admin.should be true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "will be overriden by the actual update action (hence before)" do
|
17
|
-
employee = Employee.create section: 'SE1', admin: false
|
18
|
-
described_class.new([employee]).update(admin: false)
|
19
|
-
employee.reload
|
20
|
-
employee.admin.should be false
|
21
|
-
end
|
22
|
-
end
|
data/spec/base/behaviour_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Employee::Collection do
|
4
|
-
subject { described_class.new }
|
5
|
-
|
6
|
-
describe '#one?' do
|
7
|
-
it 'is false without a collection' do
|
8
|
-
expect( subject.one? ).to be false
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'is true with exactly one record' do
|
12
|
-
expect( described_class.new([Object.new]).one? ).to be true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'is false with more than one records' do
|
16
|
-
expect( described_class.new([Object.new, Object.new]).one? ).to be false
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#first and #last' do
|
21
|
-
it 'returns the first and last object of the collection' do
|
22
|
-
o1 = Object.new
|
23
|
-
o2 = Object.new
|
24
|
-
expect( described_class.new([o1, o2]).first ).to be o1
|
25
|
-
expect( described_class.new([o1, o2]).last ).to be o2
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'form representation' do
|
30
|
-
it 'has prefix collection for all types in forms' do
|
31
|
-
expect( described_class.model_name.param_key ).to eq 'collection'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "array like behaviour" do
|
36
|
-
collection = described_class.new([1])
|
37
|
-
Array.wrap( collection ).should == collection
|
38
|
-
end
|
39
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Employee::Collection do
|
4
|
-
describe '.find' do
|
5
|
-
describe 'empty argument' do
|
6
|
-
it 'returns an empty collection when initialized with nil' do
|
7
|
-
described_class.find(nil).should be_a described_class
|
8
|
-
described_class.find(nil).should be_empty
|
9
|
-
end
|
10
|
-
it 'returns an empty collection when initialized with empty string' do
|
11
|
-
described_class.find('').should be_a described_class
|
12
|
-
described_class.find('').should be_empty
|
13
|
-
end
|
14
|
-
it 'returns an empty collection when initialized with empty array' do
|
15
|
-
described_class.find([]).should be_a described_class
|
16
|
-
described_class.find([]).should be_empty
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'existing records' do
|
21
|
-
it "finds the records" do
|
22
|
-
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
23
|
-
employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
|
24
|
-
described_class.find([employee1.id, employee2.id]).collection.should match_array [employee1, employee2]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "works with an includes statement (find on instance)" do
|
28
|
-
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
29
|
-
described_class.includes(:project).find([employee1.id]).should be_a RecordCollection::Base
|
30
|
-
end
|
31
|
-
|
32
|
-
it "works with an includes statement (find on instance) and string argument" do
|
33
|
-
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
34
|
-
employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
|
35
|
-
result = described_class.includes(:project).find("#{employee1.id}~#{employee2.id}")
|
36
|
-
result.should be_a RecordCollection::Base
|
37
|
-
result.collection.should match_array [employee1, employee2]
|
38
|
-
end
|
39
|
-
|
40
|
-
it "works with an includes statement (find on instance) and integer id argument" do
|
41
|
-
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
42
|
-
result = described_class.includes(:project).find(employee1.id)
|
43
|
-
result.should be_a RecordCollection::Base
|
44
|
-
result.collection.should eq [employee1]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "finds single id as string as collection" do
|
49
|
-
employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
50
|
-
described_class.find(employee.id).collection.should eq [employee]
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'finds multiple records from a tilde separated string' do
|
54
|
-
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
55
|
-
employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
|
56
|
-
described_class.find("#{employee1.id}~#{employee2.id}").collection.should match_array [employee1, employee2]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '.where' do
|
61
|
-
it "fills the collection with records coming from the query performed on the record_class" do
|
62
|
-
employee1 = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
63
|
-
employee2 = Employee.create name: 'E2', section: 'QNP', admin: false, vegan: false
|
64
|
-
described_class.where(admin: false).ids.should eq [employee2.id]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '.all' do
|
69
|
-
it 'finds all record and makes it part of the collection' do
|
70
|
-
employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
|
71
|
-
described_class.all.collection.should eq [employee]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '.joins' do
|
76
|
-
let(:project_1){ Project.create name: 'P1', finished: true }
|
77
|
-
let(:project_2){ Project.create name: 'P2', finished: false }
|
78
|
-
let!(:employee_1){ Employee.create name: 'E1', section: 'ABC', project: project_1 }
|
79
|
-
let!(:employee_2){ Employee.create name: 'E1', section: 'ABC', project: project_2 }
|
80
|
-
it "returns a scope having a joins activated without further arguments" do
|
81
|
-
result = described_class.joins(:project)
|
82
|
-
result.should be_a RecordCollection::Base
|
83
|
-
result.map(&:project).should match_array [project_1, project_2]
|
84
|
-
end
|
85
|
-
|
86
|
-
it "modifies the scope when a .where clause is applied on an existing relation" do
|
87
|
-
result = described_class.joins(:project).where(projects: {finished: true})
|
88
|
-
result.should be_a RecordCollection::Base
|
89
|
-
result.map(&:project).should eq [project_1]
|
90
|
-
end
|
91
|
-
|
92
|
-
it "modifies the scope when a .where.not clause is applied on an existing relation" do
|
93
|
-
result = described_class.joins(:project).where.not(projects: {finished: true})
|
94
|
-
result.should be_a RecordCollection::Base
|
95
|
-
result.map(&:project).should eq [project_2]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RecordCollection::Base do
|
4
|
-
|
5
|
-
it 'Inherits attributes from parent classes' do
|
6
|
-
class TestClass1 < RecordCollection::Base
|
7
|
-
attribute :attr1
|
8
|
-
end
|
9
|
-
|
10
|
-
class TestClass2 < TestClass1
|
11
|
-
attribute :attr2
|
12
|
-
end
|
13
|
-
TestClass2.attribute_names.should eq %w[attr1 attr2]
|
14
|
-
end
|
15
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe RecordCollection::Base do
|
4
|
-
describe '#refine_relation' do
|
5
|
-
it "does not blow up when array and not ActiveRecord::Relation is given" do
|
6
|
-
expect{ described_class.new([]).refine_relation }.not_to raise_error
|
7
|
-
described_class.new([]).refine_relation{ }.should be_a described_class
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Validations' do
|
4
|
-
let(:collection_class) { Employee::Collection }
|
5
|
-
describe 'conditional validations' do
|
6
|
-
let(:record_class){ Employee }
|
7
|
-
it 'is valid without attribute present' do
|
8
|
-
collection_class.new([]).should be_valid
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'is valid with valid section attribute' do
|
12
|
-
collection_class.new([], section: 'ABC').should be_valid
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'is invalid with invalid section attribute' do
|
16
|
-
collection_class.new([], section: 'SECTION3').should be_invalid
|
17
|
-
end
|
18
|
-
describe '#save' do
|
19
|
-
it 'does not trigger update_collection_attributes! for invalid collection' do
|
20
|
-
collection = collection_class.new [], section: 'INVALID_SECTION_NAME'
|
21
|
-
collection.should_not receive :update_collection_attributes!
|
22
|
-
collection.save
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/spec/dummy/README.rdoc
DELETED
@@ -1,28 +0,0 @@
|
|
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
DELETED
File without changes
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#= require jquery
|
2
|
-
#= require jquery_ujs
|
3
|
-
#= require js-routes
|
4
|
-
#= require record_collection/all
|
5
|
-
#= require foundation.min
|
6
|
-
#= require_tree .
|
7
|
-
#= require_self
|
8
|
-
$ ->
|
9
|
-
$(document).optionals()
|
10
|
-
$(document).foundation()
|
11
|
-
if selector = $(document).multi_select()
|
12
|
-
$('#selected-records-action').click ->
|
13
|
-
ids = selector.selected_ids()
|
14
|
-
return alert "No records selected" unless ids.length
|
15
|
-
window.location = "/employees/collection_edit?#{$.param(ids: ids)}"
|