ff-tbl-macros 0.1.8

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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/Dockerfile +13 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +117 -0
  5. data/MIT-LICENSE +18 -0
  6. data/README.md +147 -0
  7. data/lib/ff-tbl-macros.rb +29 -0
  8. data/lib/macros/auth.rb +9 -0
  9. data/lib/macros/auth/authenticate.rb +24 -0
  10. data/lib/macros/auth/sign_in.rb +43 -0
  11. data/lib/macros/auth/sign_out.rb +48 -0
  12. data/lib/macros/base.rb +37 -0
  13. data/lib/macros/contract.rb +8 -0
  14. data/lib/macros/contract/extract_params.rb +25 -0
  15. data/lib/macros/contract/prepopulate.rb +16 -0
  16. data/lib/macros/ctx.rb +9 -0
  17. data/lib/macros/ctx/copy.rb +18 -0
  18. data/lib/macros/ctx/inspect.rb +28 -0
  19. data/lib/macros/ctx/validate_presence.rb +20 -0
  20. data/lib/macros/current_user.rb +7 -0
  21. data/lib/macros/current_user/set.rb +25 -0
  22. data/lib/macros/error.rb +7 -0
  23. data/lib/macros/error/set_from_contract.rb +19 -0
  24. data/lib/macros/model.rb +10 -0
  25. data/lib/macros/model/build.rb +32 -0
  26. data/lib/macros/model/copy.rb +17 -0
  27. data/lib/macros/model/destroy.rb +18 -0
  28. data/lib/macros/model/persist.rb +21 -0
  29. data/lib/macros/search.rb +7 -0
  30. data/lib/macros/search/query.rb +34 -0
  31. data/lib/macros/verify_params.rb +7 -0
  32. data/lib/macros/verify_params/date.rb +17 -0
  33. data/lib/macros/version.rb +6 -0
  34. data/spec/lib/auth/authenticate_spec.rb +21 -0
  35. data/spec/lib/auth/sign_in_spec.rb +37 -0
  36. data/spec/lib/auth/sign_out_spec.rb +37 -0
  37. data/spec/lib/auth_spec.rb +15 -0
  38. data/spec/lib/contract/extract_params_spec.rb +35 -0
  39. data/spec/lib/contract/prepopulate_spec.rb +27 -0
  40. data/spec/lib/contract_spec.rb +14 -0
  41. data/spec/lib/ctx/copy_spec.rb +27 -0
  42. data/spec/lib/ctx/inspect_spec.rb +26 -0
  43. data/spec/lib/ctx/validate_presence_spec.rb +20 -0
  44. data/spec/lib/ctx_spec.rb +19 -0
  45. data/spec/lib/current_user.rb +7 -0
  46. data/spec/lib/current_user/set_spec.rb +24 -0
  47. data/spec/lib/error/set_from_contract_spec.rb +27 -0
  48. data/spec/lib/error_spec.rb +7 -0
  49. data/spec/lib/ff_tbl_macros_spec.rb +11 -0
  50. data/spec/lib/model/build_spec.rb +53 -0
  51. data/spec/lib/model/copy_spec.rb +26 -0
  52. data/spec/lib/model/destroy_spec.rb +13 -0
  53. data/spec/lib/model/persist_spec.rb +45 -0
  54. data/spec/lib/model_spec.rb +21 -0
  55. data/spec/lib/search/query_spec.rb +23 -0
  56. data/spec/lib/search_spec.rb +9 -0
  57. data/spec/lib/verify_params/date_spec.rb +22 -0
  58. data/spec/lib/verify_params_spec.rb +9 -0
  59. data/spec/spec_helper.rb +38 -0
  60. metadata +169 -0
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::Model::Persist do
4
+ let(:user) { mock_model('User', save!: true, save: true) }
5
+ let(:ctx) { { model: user } }
6
+
7
+ describe 'default save!' do
8
+ subject(:persist_step) { described_class.new }
9
+
10
+ it 'expect to save model' do
11
+ expect(user).to receive(:save!)
12
+ persist_step.call(ctx)
13
+ end
14
+
15
+ context 'ctx key is not default one' do
16
+ subject(:persist_step) { described_class.new(ctx_key: ctx_key) }
17
+ let(:project) { mock_model('Project', save!: true, save: true) }
18
+ let(:ctx_key) { :project }
19
+ let(:ctx) { { project: project } }
20
+
21
+ it 'expect to save model' do
22
+ expect(project).to receive(:save!)
23
+ persist_step.call(ctx)
24
+ end
25
+ end
26
+
27
+ context 'model is not present in context' do
28
+ let(:ctx) { { foo: :bar } }
29
+
30
+ it 'expect not to save model' do
31
+ expect(user).not_to receive(:save!)
32
+ persist_step.call(ctx)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe 'different save method' do
38
+ subject(:persist_step) { described_class.new(method: :save) }
39
+
40
+ it 'expect to save model' do
41
+ expect(user).to receive(:save)
42
+ persist_step.call(ctx)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::Model do
4
+ let(:ctx_key) { :project }
5
+
6
+ describe '#Build()' do
7
+ it { expect(described_class::Build(from: ctx_key)).to be_a described_class::Build }
8
+ end
9
+
10
+ describe '#Copy()' do
11
+ it { expect(described_class::Copy(ctx_key)).to be_a described_class::Copy }
12
+ end
13
+
14
+ describe '#Destroy()' do
15
+ it { expect(described_class::Destroy()).to be_a described_class::Destroy }
16
+ end
17
+
18
+ describe '#Persist()' do
19
+ it { expect(described_class::Persist(ctx_key: ctx_key)).to be_a described_class::Persist }
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::Search::Query do
4
+ subject(:query_step) { described_class.new(searchable: klass) }
5
+
6
+ let(:page) { 1 }
7
+ let(:result) { double('result', page: page) }
8
+ let(:ransack_result) { OpenStruct.new(q: query, result: result) }
9
+ let(:klass) { mock_model('User', ransack: ransack_result) }
10
+
11
+ let(:query) { { name_cont: 'foo' } }
12
+ let(:params) { { q: query, page: page } }
13
+ let(:ctx) { { params: params } }
14
+
15
+ it 'expects to search' do
16
+ expect(klass).to receive(:ransack).with(query)
17
+
18
+ query_step.call(ctx, params: params)
19
+
20
+ expect(ctx[:query].q).to eql query
21
+ expect(ctx[:query].result).to eql result
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::Search do
4
+ describe '#Query()' do
5
+ let(:searchable) { :admin }
6
+
7
+ it { expect(described_class::Query(searchable: searchable)).to be_a described_class::Query }
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::VerifyParams::Date do
4
+ subject(:date_step) { described_class.new(params_key: params_key) }
5
+
6
+ let(:params_key) { :date }
7
+
8
+ let(:date) { Date.parse('2019-01-15') }
9
+ let(:ctx) { { params: { date: date } } }
10
+
11
+ it 'expects to pass' do
12
+ expect(date_step.call(ctx)).to be true
13
+ end
14
+
15
+ context 'date invalid' do
16
+ let(:date) { '2018' }
17
+
18
+ it 'expects to fail' do
19
+ expect(date_step.call(ctx)).to be false
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Macros::VerifyParams do
4
+ describe '#Date()' do
5
+ let(:params_key) { :date }
6
+
7
+ it { expect(described_class::Date(params_key: params_key)).to be_a described_class::Date }
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+ %w[
7
+ recursive-open-struct
8
+ reform
9
+ rspec/active_model/mocks
10
+ rubygems
11
+ simplecov
12
+ warden
13
+ ].each do |lib|
14
+ require lib
15
+ end
16
+
17
+ # Don't include unnecessary stuff into rcov
18
+ SimpleCov.start do
19
+ add_filter '/.bundle/'
20
+ add_filter '/doc/'
21
+ add_filter '/spec/'
22
+ add_filter '/config/'
23
+ merge_timeout 600
24
+ end
25
+
26
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
27
+
28
+ RSpec.configure do |config|
29
+ config.disable_monkey_patching!
30
+ config.order = :random
31
+ # config.mock_with :rspec
32
+
33
+ config.expect_with :rspec do |expectations|
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+ end
37
+
38
+ require 'ff-tbl-macros'
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ff-tbl-macros
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Artur Szwed, Claudio Perez Gamayo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: require_all
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: trailblazer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description: Collection of useful macros for Trailblazer to operate on context, contracts,
56
+ params etc.
57
+ email: devops@firefield.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Dockerfile
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - MIT-LICENSE
66
+ - README.md
67
+ - lib/ff-tbl-macros.rb
68
+ - lib/macros/auth.rb
69
+ - lib/macros/auth/authenticate.rb
70
+ - lib/macros/auth/sign_in.rb
71
+ - lib/macros/auth/sign_out.rb
72
+ - lib/macros/base.rb
73
+ - lib/macros/contract.rb
74
+ - lib/macros/contract/extract_params.rb
75
+ - lib/macros/contract/prepopulate.rb
76
+ - lib/macros/ctx.rb
77
+ - lib/macros/ctx/copy.rb
78
+ - lib/macros/ctx/inspect.rb
79
+ - lib/macros/ctx/validate_presence.rb
80
+ - lib/macros/current_user.rb
81
+ - lib/macros/current_user/set.rb
82
+ - lib/macros/error.rb
83
+ - lib/macros/error/set_from_contract.rb
84
+ - lib/macros/model.rb
85
+ - lib/macros/model/build.rb
86
+ - lib/macros/model/copy.rb
87
+ - lib/macros/model/destroy.rb
88
+ - lib/macros/model/persist.rb
89
+ - lib/macros/search.rb
90
+ - lib/macros/search/query.rb
91
+ - lib/macros/verify_params.rb
92
+ - lib/macros/verify_params/date.rb
93
+ - lib/macros/version.rb
94
+ - spec/lib/auth/authenticate_spec.rb
95
+ - spec/lib/auth/sign_in_spec.rb
96
+ - spec/lib/auth/sign_out_spec.rb
97
+ - spec/lib/auth_spec.rb
98
+ - spec/lib/contract/extract_params_spec.rb
99
+ - spec/lib/contract/prepopulate_spec.rb
100
+ - spec/lib/contract_spec.rb
101
+ - spec/lib/ctx/copy_spec.rb
102
+ - spec/lib/ctx/inspect_spec.rb
103
+ - spec/lib/ctx/validate_presence_spec.rb
104
+ - spec/lib/ctx_spec.rb
105
+ - spec/lib/current_user.rb
106
+ - spec/lib/current_user/set_spec.rb
107
+ - spec/lib/error/set_from_contract_spec.rb
108
+ - spec/lib/error_spec.rb
109
+ - spec/lib/ff_tbl_macros_spec.rb
110
+ - spec/lib/model/build_spec.rb
111
+ - spec/lib/model/copy_spec.rb
112
+ - spec/lib/model/destroy_spec.rb
113
+ - spec/lib/model/persist_spec.rb
114
+ - spec/lib/model_spec.rb
115
+ - spec/lib/search/query_spec.rb
116
+ - spec/lib/search_spec.rb
117
+ - spec/lib/verify_params/date_spec.rb
118
+ - spec/lib/verify_params_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/firefield/ff-tbl-macros
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.0.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Trailblazer shared macros
143
+ test_files:
144
+ - spec/lib/auth/authenticate_spec.rb
145
+ - spec/lib/auth/sign_in_spec.rb
146
+ - spec/lib/auth/sign_out_spec.rb
147
+ - spec/lib/auth_spec.rb
148
+ - spec/lib/contract/extract_params_spec.rb
149
+ - spec/lib/contract/prepopulate_spec.rb
150
+ - spec/lib/contract_spec.rb
151
+ - spec/lib/ctx/copy_spec.rb
152
+ - spec/lib/ctx/inspect_spec.rb
153
+ - spec/lib/ctx/validate_presence_spec.rb
154
+ - spec/lib/ctx_spec.rb
155
+ - spec/lib/current_user.rb
156
+ - spec/lib/current_user/set_spec.rb
157
+ - spec/lib/error/set_from_contract_spec.rb
158
+ - spec/lib/error_spec.rb
159
+ - spec/lib/ff_tbl_macros_spec.rb
160
+ - spec/lib/model/build_spec.rb
161
+ - spec/lib/model/copy_spec.rb
162
+ - spec/lib/model/destroy_spec.rb
163
+ - spec/lib/model/persist_spec.rb
164
+ - spec/lib/model_spec.rb
165
+ - spec/lib/search/query_spec.rb
166
+ - spec/lib/search_spec.rb
167
+ - spec/lib/verify_params/date_spec.rb
168
+ - spec/lib/verify_params_spec.rb
169
+ - spec/spec_helper.rb