trailblazer-finder 0.50.0 → 0.80.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trailblazer/finder/activities/find.rb +16 -16
  3. data/lib/trailblazer/finder/activities/prepare_adapter.rb +2 -3
  4. data/lib/trailblazer/finder/activities/prepare_entity.rb +2 -2
  5. data/lib/trailblazer/finder/activities/prepare_paging.rb +2 -2
  6. data/lib/trailblazer/finder/activities/prepare_properties.rb +1 -5
  7. data/lib/trailblazer/finder/activities/process_adapters.rb +8 -2
  8. data/lib/trailblazer/finder/adapters/active_record/paging.rb +1 -1
  9. data/lib/trailblazer/finder/adapters/active_record/predicates.rb +14 -14
  10. data/lib/trailblazer/finder/adapters/active_record/sorting.rb +1 -1
  11. data/lib/trailblazer/finder/adapters/basic/paging.rb +1 -1
  12. data/lib/trailblazer/finder/adapters/basic/predicates.rb +14 -14
  13. data/lib/trailblazer/finder/adapters/basic/sorting.rb +1 -1
  14. data/lib/trailblazer/finder/adapters/kaminari/paging.rb +1 -1
  15. data/lib/trailblazer/finder/adapters/sequel/paging.rb +1 -1
  16. data/lib/trailblazer/finder/adapters/sequel/predicates.rb +14 -14
  17. data/lib/trailblazer/finder/adapters/sequel/sorting.rb +1 -1
  18. data/lib/trailblazer/finder/adapters/will_paginate/paging.rb +1 -1
  19. data/lib/trailblazer/finder/dsl.rb +1 -1
  20. data/lib/trailblazer/finder/find.rb +2 -1
  21. data/lib/trailblazer/finder/helpers/sorting.rb +4 -1
  22. data/lib/trailblazer/finder/version.rb +1 -1
  23. data/lib/trailblazer/finder.rb +1 -7
  24. data/lib/trailblazer/operation/finder.rb +2 -2
  25. data/trailblazer-finder.gemspec +8 -8
  26. metadata +26 -57
  27. data/.gitignore +0 -24
  28. data/.rubocop.yml +0 -5
  29. data/.travis.yml +0 -7
  30. data/CHANGES.md +0 -40
  31. data/Gemfile +0 -14
  32. data/LICENSE.txt +0 -9
  33. data/README.md +0 -451
  34. data/Rakefile +0 -31
  35. data/spec/spec_helper.rb +0 -14
  36. data/spec/spec_helper_active_record.rb +0 -48
  37. data/spec/spec_helper_sequel.rb +0 -33
  38. data/spec/spec_helper_will_paginate.rb +0 -13
  39. data/spec/trailblazer/finder/adapters/active_record_spec.rb +0 -267
  40. data/spec/trailblazer/finder/adapters/basic_spec.rb +0 -251
  41. data/spec/trailblazer/finder/adapters/kaminari_spec.rb +0 -115
  42. data/spec/trailblazer/finder/adapters/sequel_spec.rb +0 -267
  43. data/spec/trailblazer/finder/adapters/will_paginate_spec.rb +0 -117
  44. data/spec/trailblazer/finder/base_spec.rb +0 -417
  45. data/spec/trailblazer/finder/dsl_spec.rb +0 -204
  46. data/spec/trailblazer/finder/utils/hash_spec.rb +0 -26
  47. data/spec/trailblazer/finder/utils/splitter_spec.rb +0 -39
  48. data/spec/trailblazer/finder/utils/string_spec.rb +0 -69
  49. data/spec/trailblazer/operation/finder_spec.rb +0 -122
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Trailblazer
6
- class Finder
7
- module Utils
8
- describe String do
9
- describe ".blank?" do
10
- it "checks if value is blank or nil" do
11
- expect(described_class.blank?("")).to eq true
12
- expect(described_class.blank?(nil)).to eq true
13
- expect(described_class.blank?("what")).to eq false
14
- expect(described_class.blank?(1)).to eq false
15
- end
16
- end
17
-
18
- describe ".numeric?" do
19
- it "checks if value is numeric" do
20
- expect(described_class.numeric?("")).to eq false
21
- expect(described_class.numeric?(nil)).to eq false
22
- expect(described_class.numeric?(1)).to eq true
23
- expect(described_class.numeric?(0)).to eq true
24
- expect(described_class.numeric?(1.00000)).to eq true
25
- expect(described_class.numeric?("1")).to eq true
26
- end
27
- end
28
-
29
- describe ".date?" do
30
- it "checks if value is a date" do
31
- expect(described_class.date?("2018-01-01")).to eq true
32
- expect(described_class.date?(nil)).to eq false
33
- expect(described_class.date?("random")).to eq false
34
- expect(described_class.date?(1)).to eq false
35
- expect(described_class.date?("2018/01/01")).to eq true
36
- expect(described_class.date?("2018.01.01")).to eq true
37
- expect(described_class.date?("21-12-2018")).to eq true
38
- expect(described_class.date?("0fae2de1-6537-4d36-9cdb-30edf1e37990")).to eq false
39
- end
40
- end
41
-
42
- describe ".to_date" do
43
- it "transforms a date like value to a valid date" do
44
- expect(described_class.to_date("28/09/2018")).to eq "2018-09-28"
45
- expect(described_class.to_date("2018/09/28")).to eq "2018-09-28"
46
- expect(described_class.to_date("28 september 2018")).to eq "2018-09-28"
47
- expect(described_class.to_date("third month of this year")).to eq nil
48
- end
49
- end
50
-
51
- describe ".camelize" do
52
- it "transforms a string by capatalizing each word's first letter" do
53
- expect(described_class.camelize(:paging)).to eq "Paging"
54
- expect(described_class.camelize(:some_random_test)).to eq "SomeRandomTest"
55
- end
56
- end
57
-
58
- describe ".underscore" do
59
- it "transforms a string by dividing words with underscores" do
60
- expect(described_class.underscore(:veryPopular)).to eq "very_popular"
61
- expect(described_class.underscore(:VeryPopular)).to eq "very_popular"
62
- expect(described_class.underscore(:SomethingveryPopularButRandom)).to eq "somethingvery_popular_but_random"
63
- expect(described_class.underscore("Very Popular")).to eq "very_popular"
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "delegate"
4
- require "trailblazer"
5
- require "spec_helper_active_record"
6
-
7
- class Product::FinderNoEntity < Trailblazer::Finder
8
- adapter "ActiveRecord"
9
-
10
- property :id, type: Types::Integer
11
- property :name, type: Types::String, sortable: true
12
- filter_by :escaped_name, with: :apply_escaped_name
13
-
14
- def apply_escaped_name(entity, _attribute, value)
15
- return unless value.present?
16
-
17
- entity.where "lower(name) LIKE ?", "%#{value.downcase}%"
18
- end
19
- end
20
-
21
- class Product::FinderWithEntity < Trailblazer::Finder
22
- adapter "ActiveRecord"
23
-
24
- entity { Product }
25
-
26
- property :id, type: Types::Integer
27
- property :name, type: Types::String, sortable: true
28
- filter_by :escaped_name, with: :apply_escaped_name
29
-
30
- def apply_escaped_name(entity, _attribute, value)
31
- return unless value.present?
32
-
33
- entity.where "lower(name) LIKE ?", "%#{value.downcase}%"
34
- end
35
- end
36
-
37
- class Product::Index < Trailblazer::Operation
38
- step Finder(Product::FinderNoEntity, :all, Product)
39
- end
40
-
41
- class Product::Show < Trailblazer::Operation
42
- step Finder(Product::FinderNoEntity, :single, Product)
43
- end
44
-
45
- class Product::IndexNoEntity < Trailblazer::Operation
46
- step Finder(Product::FinderWithEntity, :all)
47
- end
48
-
49
- class Product::ShowNoEntity < Trailblazer::Operation
50
- step Finder(Product::FinderWithEntity, :single)
51
- end
52
-
53
- describe "Trailblazer::Operation - Finder Macro" do
54
- before do
55
- Product.destroy_all
56
- Product.reset_pk_sequence
57
- 22.times { |i| Product.create name: "product_#{i}" }
58
- end
59
-
60
- after do
61
- Product.destroy_all
62
- Product.reset_pk_sequence
63
- end
64
-
65
- it "Can find a single row by id" do
66
- params = {id: 5}
67
- result = Product::Show.call(params: params)
68
-
69
- expect(result[:finder].name).to eq "product_4"
70
- end
71
-
72
- it "Can find a single row by id from ActiveSupport::HashWithIndifferentAccess" do
73
- params = ActiveSupport::HashWithIndifferentAccess.new({id: 6})
74
- result = Product::Show.call(params: params)
75
-
76
- expect(result[:finder].name).to eq "product_5"
77
- end
78
-
79
-
80
- it "Can find a single row by name" do
81
- params = {name_eq: "product_2"}
82
- result = Product::Show.call(params: params)
83
-
84
- expect(result[:finder].name).to eq "product_2"
85
- end
86
-
87
- it "Can find multiple rows by escaped name" do
88
- params = {escaped_name: "product_1"}
89
- result = Product::Index.call(params: params)
90
-
91
- expect(result[:finder].result.last.name).to eq "product_19"
92
- end
93
-
94
- it "Can find multiple rows by escaped name if key is string" do
95
- params = {"escaped_name" => "product_1"}
96
- result = Product::Index.call(params: params)
97
-
98
- expect(result[:finder].result.last.name).to eq "product_19"
99
- end
100
-
101
- it "Can find a single row by id when no entity type is given in macro" do
102
- params = {id: 8}
103
- result = Product::ShowNoEntity.call(params: params)
104
-
105
- expect(result[:finder].name).to eq "product_7"
106
- end
107
-
108
- it "Can find a single row by name when no entity type is given in macro" do
109
- params = {name_eq: "product_2"}
110
- result = Product::ShowNoEntity.call(params: params)
111
-
112
- expect(result[:finder].name).to eq "product_2"
113
- end
114
-
115
- it "Can find multiple rows by escaped name when no entity type is given in macro" do
116
- params = {escaped_name: "product_1"}
117
- result = Product::IndexNoEntity.call(params: params)
118
-
119
- expect(result[:finder].result.count).to eq 11
120
- expect(result[:finder].result.last.name).to eq "product_19"
121
- end
122
- end