katapult 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +57 -9
  4. data/bin/katapult +7 -3
  5. data/features/application_model.feature +4 -1
  6. data/features/authenticate.feature +1 -18
  7. data/features/basics.feature +1 -0
  8. data/features/binary.feature +5 -7
  9. data/features/model.feature +42 -3
  10. data/features/step_definitions/rails_steps.rb +1 -1
  11. data/features/web_ui.feature +17 -5
  12. data/lib/generators/katapult/app_model/templates/lib/katapult/application_model.rb +3 -0
  13. data/lib/generators/katapult/basics/basics_generator.rb +3 -8
  14. data/lib/generators/katapult/basics/templates/README.md.tt +33 -0
  15. data/lib/generators/katapult/basics/templates/features/support/paths.rb +1 -1
  16. data/lib/generators/katapult/clearance/clearance_generator.rb +6 -2
  17. data/lib/generators/katapult/clearance/templates/config/initializers/clearance.rb +1 -0
  18. data/lib/generators/katapult/cucumber_features/cucumber_features_generator.rb +10 -0
  19. data/lib/generators/katapult/cucumber_features/templates/feature.feature +4 -3
  20. data/lib/generators/katapult/model/model_generator.rb +15 -0
  21. data/lib/generators/katapult/model/templates/model.rb +13 -3
  22. data/lib/generators/katapult/model_specs/model_specs_generator.rb +1 -1
  23. data/lib/generators/katapult/model_specs/templates/model_spec.rb +1 -1
  24. data/lib/generators/katapult/transform/transform_generator.rb +4 -7
  25. data/lib/generators/katapult/views/templates/_form.html.haml +16 -13
  26. data/lib/generators/katapult/views/templates/show.html.haml +2 -0
  27. data/lib/katapult/application_model.rb +68 -19
  28. data/lib/katapult/element.rb +13 -18
  29. data/lib/katapult/{action.rb → elements/action.rb} +0 -0
  30. data/lib/katapult/elements/association.rb +35 -0
  31. data/lib/katapult/{attribute.rb → elements/attribute.rb} +14 -5
  32. data/lib/katapult/{authentication.rb → elements/authentication.rb} +2 -5
  33. data/lib/katapult/elements/model.rb +76 -0
  34. data/lib/katapult/{navigation.rb → elements/navigation.rb} +0 -0
  35. data/lib/katapult/{web_ui.rb → elements/web_ui.rb} +2 -12
  36. data/lib/katapult/generator.rb +2 -2
  37. data/lib/katapult/{binary_util.rb → support/binary_util.rb} +2 -1
  38. data/lib/katapult/{generator_goodies.rb → support/generator_goodies.rb} +9 -2
  39. data/lib/katapult/version.rb +1 -1
  40. data/script/console +5 -2
  41. data/script/update +1 -1
  42. data/spec/action_spec.rb +1 -1
  43. data/spec/application_model_spec.rb +26 -0
  44. data/spec/association_spec.rb +12 -0
  45. data/spec/attribute_spec.rb +35 -1
  46. data/spec/model_spec.rb +5 -2
  47. data/spec/util_spec.rb +1 -1
  48. data/spec/web_ui_spec.rb +11 -33
  49. metadata +17 -13
  50. data/lib/katapult/model.rb +0 -45
  51. data/lib/katapult/parser.rb +0 -53
  52. data/spec/parser_spec.rb +0 -26
@@ -0,0 +1,12 @@
1
+ require 'katapult/elements/association'
2
+
3
+ describe Katapult::Association do
4
+
5
+ subject { described_class.new('association') }
6
+
7
+ it 'stores its :belongs_to as String' do
8
+ subject = described_class.new('model', belongs_to: :other_model)
9
+ expect(subject.belongs_to).to eq 'other_model'
10
+ end
11
+
12
+ end
@@ -1,4 +1,4 @@
1
- require 'katapult/attribute'
1
+ require 'katapult/elements/attribute'
2
2
 
3
3
  describe Katapult::Attribute do
4
4
 
@@ -57,4 +57,38 @@ describe Katapult::Attribute do
57
57
  end
58
58
  end
59
59
 
60
+ describe '#asset_values_as_list?' do
61
+ it 'returns false when there are no assignable values given' do
62
+ subject = described_class.new('name')
63
+ expect(subject.assignable_values_as_list?).to be false
64
+ end
65
+
66
+ it 'returns false when assignable values are give as a string (= custom code)' do
67
+ subject = described_class.new('name', assignable_values: 'NameProvider.all')
68
+ expect(subject.assignable_values_as_list?).to be false
69
+ end
70
+
71
+ it 'returns true when assignable values are an Array' do
72
+ subject = described_class.new('name', assignable_values: %w[andi andy])
73
+ expect(subject.assignable_values_as_list?).to be true
74
+ end
75
+
76
+ it 'returns true when assignable values are a Range' do
77
+ subject = described_class.new('age', assignable_values: (1..99))
78
+ expect(subject.assignable_values_as_list?).to be true
79
+ end
80
+ end
81
+
82
+ describe '#has_defaults?' do
83
+ it 'returns false when it is an "assignable values" attribute' do
84
+ subject = described_class.new('kind', assignable_values: %w[customer guest])
85
+ expect(subject.has_defaults?).to be false
86
+ end
87
+
88
+ it 'returns false when it is a flag attribute' do
89
+ subject = described_class.new('active', type: :flag, default: true)
90
+ expect(subject.has_defaults?).to be false
91
+ end
92
+ end
93
+
60
94
  end
data/spec/model_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'katapult/model'
2
- require 'katapult/attribute'
1
+ require 'katapult/elements/model'
3
2
 
4
3
  describe Katapult::Model do
5
4
 
@@ -13,6 +12,10 @@ describe Katapult::Model do
13
12
 
14
13
  expect(subject.label_attr.name).to eql('second_attr')
15
14
  end
15
+
16
+ it 'raises an error when someone needs/wants/expect a label attribute but there is none' do
17
+ expect{ subject.label_attr }.to raise_error Katapult::Model::MissingLabelAttributeError
18
+ end
16
19
  end
17
20
 
18
21
  end
data/spec/util_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'katapult/binary_util'
1
+ require 'katapult/support/binary_util'
2
2
 
3
3
  describe Katapult::BinaryUtil do
4
4
 
data/spec/web_ui_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'katapult/web_ui'
2
- require 'katapult/model'
1
+ require 'katapult/elements/web_ui'
2
+ require 'katapult/elements/model'
3
3
  require 'katapult/application_model'
4
4
 
5
5
  describe Katapult::WebUI do
@@ -37,43 +37,21 @@ describe Katapult::WebUI do
37
37
 
38
38
  describe '#model' do
39
39
  it 'returns the model object' do
40
- subject = described_class.new('Customer', model: 'User')
41
- model = Katapult::Model.new('User')
40
+ application_model.model 'User'
42
41
 
43
- application_model.add_web_ui(subject)
44
- application_model.add_model(model)
42
+ subject = described_class.new('Customer',
43
+ model: 'User',
44
+ application_model: application_model,
45
+ )
45
46
 
46
- expect(subject.model).to eql(model)
47
+ expect(subject.model).to be application_model.models.first
47
48
  end
48
49
 
49
50
  it 'detects the model from its own name, if not stated explicitly' do
50
- subject = described_class.new('Customer')
51
- model = Katapult::Model.new('Customer')
51
+ application_model.model 'Customer'
52
+ subject = described_class.new('Customer', application_model: application_model)
52
53
 
53
- application_model.add_web_ui(subject)
54
- application_model.add_model(model)
55
-
56
- expect(subject.model).to eql(model)
57
- end
58
-
59
- it 'raises an error if it cannot find the model' do
60
- subject = described_class.new('MissingModel')
61
- application_model.add_web_ui(subject)
62
-
63
- expect{ subject.model }.to raise_error(Katapult::WebUI::UnknownModelError)
64
- end
65
- end
66
-
67
- describe '#render' do
68
- it 'raises an error when its model does not have a label attribute' do
69
- subject = described_class.new('user')
70
- model = Katapult::Model.new('user')
71
-
72
- application_model.add_web_ui(subject)
73
- application_model.add_model(model)
74
-
75
- expect{ subject.render }.to raise_error Katapult::WebUI::MissingLabelAttrError,
76
- 'Cannot render a WebUI without a model with a label attribute'
54
+ expect(subject.model).to be application_model.models.first
77
55
  end
78
56
  end
79
57
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katapult
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Schöler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-11 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,7 @@ files:
52
52
  - ".gitignore"
53
53
  - ".rspec"
54
54
  - ".ruby-version"
55
+ - CHANGELOG.md
55
56
  - Gemfile
56
57
  - Guardfile
57
58
  - LICENSE.txt
@@ -86,6 +87,7 @@ files:
86
87
  - lib/generators/katapult/basics/templates/Capfile
87
88
  - lib/generators/katapult/basics/templates/Gemfile
88
89
  - lib/generators/katapult/basics/templates/Guardfile
90
+ - lib/generators/katapult/basics/templates/README.md.tt
89
91
  - lib/generators/katapult/basics/templates/app/controllers/errors_controller.rb
90
92
  - lib/generators/katapult/basics/templates/app/helpers/unpoly_helper.rb
91
93
  - lib/generators/katapult/basics/templates/app/views/layouts/_flashes.html.haml
@@ -189,27 +191,28 @@ files:
189
191
  - lib/generators/katapult/web_ui/templates/controller.rb
190
192
  - lib/generators/katapult/web_ui/web_ui_generator.rb
191
193
  - lib/katapult.rb
192
- - lib/katapult/action.rb
193
194
  - lib/katapult/application_model.rb
194
- - lib/katapult/attribute.rb
195
- - lib/katapult/authentication.rb
196
- - lib/katapult/binary_util.rb
197
195
  - lib/katapult/element.rb
196
+ - lib/katapult/elements/action.rb
197
+ - lib/katapult/elements/association.rb
198
+ - lib/katapult/elements/attribute.rb
199
+ - lib/katapult/elements/authentication.rb
200
+ - lib/katapult/elements/model.rb
201
+ - lib/katapult/elements/navigation.rb
202
+ - lib/katapult/elements/web_ui.rb
198
203
  - lib/katapult/generator.rb
199
- - lib/katapult/generator_goodies.rb
200
- - lib/katapult/model.rb
201
- - lib/katapult/navigation.rb
202
- - lib/katapult/parser.rb
204
+ - lib/katapult/support/binary_util.rb
205
+ - lib/katapult/support/generator_goodies.rb
203
206
  - lib/katapult/version.rb
204
- - lib/katapult/web_ui.rb
205
207
  - script/console
206
208
  - script/kta
207
209
  - script/update
208
210
  - spec/action_spec.rb
211
+ - spec/application_model_spec.rb
212
+ - spec/association_spec.rb
209
213
  - spec/attribute_spec.rb
210
214
  - spec/element_spec.rb
211
215
  - spec/model_spec.rb
212
- - spec/parser_spec.rb
213
216
  - spec/spec_helper.rb
214
217
  - spec/util_spec.rb
215
218
  - spec/web_ui_spec.rb
@@ -255,10 +258,11 @@ test_files:
255
258
  - features/support/env.rb
256
259
  - features/web_ui.feature
257
260
  - spec/action_spec.rb
261
+ - spec/application_model_spec.rb
262
+ - spec/association_spec.rb
258
263
  - spec/attribute_spec.rb
259
264
  - spec/element_spec.rb
260
265
  - spec/model_spec.rb
261
- - spec/parser_spec.rb
262
266
  - spec/spec_helper.rb
263
267
  - spec/util_spec.rb
264
268
  - spec/web_ui_spec.rb
@@ -1,45 +0,0 @@
1
- # Models a Rails model.
2
-
3
- require 'katapult/element'
4
- require 'katapult/attribute'
5
- require 'generators/katapult/model/model_generator'
6
-
7
- module Katapult
8
- class Model < Element
9
-
10
- UnknownAttributeError = Class.new(StandardError)
11
-
12
- attr_accessor :attrs
13
-
14
- def initialize(*args)
15
- self.attrs = []
16
-
17
- super
18
- end
19
-
20
- def attr(attr_name, options = {})
21
- attrs << Attribute.new(attr_name, options)
22
- end
23
-
24
- def label_attr
25
- renderable_attrs.first
26
- end
27
-
28
- def db_fields
29
- attrs.reject(&:skip_db)
30
- end
31
-
32
- def renderable_attrs
33
- attrs.reject { |a| %w[plain_json json password].include? a.type.to_s }
34
- end
35
-
36
- def editable_attrs
37
- attrs.reject { |a| %w[plain_json json].include? a.type.to_s }
38
- end
39
-
40
- def render
41
- Generators::ModelGenerator.new(self).invoke_all
42
- end
43
-
44
- end
45
- end
@@ -1,53 +0,0 @@
1
- # This class reads an application model file and turns it into an
2
- # ApplicationModel instance.
3
-
4
- require_relative 'application_model'
5
- require 'katapult/model'
6
- require 'katapult/web_ui'
7
- require 'katapult/navigation'
8
- require 'katapult/authentication'
9
-
10
- module Katapult
11
- class Parser
12
-
13
- def initialize
14
- self.application_model = Katapult::ApplicationModel.new
15
- end
16
-
17
- def parse(application_model_string, path_to_model = '')
18
- instance_eval application_model_string, path_to_model
19
-
20
- application_model
21
- end
22
-
23
- def model(name, &block)
24
- application_model.add_model Model.new(name, &block)
25
- end
26
-
27
- def web_ui(name, options = {}, &block)
28
- application_model.add_web_ui WebUI.new(name, options, &block)
29
- end
30
-
31
- # A shortcut to create a #model together with a default #web_ui with CRUD
32
- # actions
33
- def crud(name, &block)
34
- application_model.add_model Model.new(name, &block)
35
- application_model.add_web_ui WebUI.new(name, &:crud)
36
- end
37
-
38
- def navigation(name = :main)
39
- application_model.set_navigation Navigation.new(name)
40
- end
41
-
42
- def authenticate(name, system_email:)
43
- application_model.set_authentication Authentication.new(name,
44
- system_email: system_email
45
- )
46
- end
47
-
48
- private
49
-
50
- attr_accessor :application_model
51
-
52
- end
53
- end
data/spec/parser_spec.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'katapult/parser'
2
-
3
- describe Katapult::Parser do
4
-
5
- describe '#crud' do
6
- it 'creates a model plus a web UI with crud actions' do
7
- model = <<-MODEL
8
- crud 'user' do |user|
9
- user.attr :age
10
- end
11
- MODEL
12
-
13
- parsed_model = subject.parse(model)
14
- expect(parsed_model.models.count).to be 1
15
- user = parsed_model.models.first
16
- expect(user.name).to eq 'user'
17
- expect(user.attrs.count).to be 1
18
- expect(user.attrs.first.name).to eq 'age'
19
-
20
- expect(parsed_model.web_uis.count).to be 1
21
- web_ui = parsed_model.web_uis.first
22
- expect(web_ui.actions.map(&:name)).to match Katapult::WebUI::RAILS_ACTIONS
23
- end
24
- end
25
-
26
- end