brainstem 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5785540a81ca6119478cd1c8567f3c96fa73fa6
4
- data.tar.gz: c8ea012472c8d23767b446dfb941d0ebff5ec067
3
+ metadata.gz: '0942f85fafa0e040a4fdc07a3d61d8e09a5fe0f7'
4
+ data.tar.gz: f6f6d59618aefc3d545e8d9df82b70b124f0762a
5
5
  SHA512:
6
- metadata.gz: 71a2fd84129676cd27b0d669c94080f92b23417c4d7eb0ccb1366b02e2baa388fd53e0a54d0bbb0f84ea47d139bd54d13bd1e725bafa2bfc613ecb343f7cd119
7
- data.tar.gz: e5a35cc09a2a048fa30a4633b1c7b66f2d60f56f52e1889e46466983f4b9dcddbd4828859836680b012a68cbca8fbd74ad66b2cacb6ed2e53a810ea160ee7be8
6
+ metadata.gz: 1a1d425a35a804cec4bea1e1c2cc185ba435e6ffb9bf3e6c4ff1c2ca7b09ec96c23a119fa9f4b54b758ae800abd2327e1abdd7d102056365f39af4b2e31e772c
7
+ data.tar.gz: 4c4d077cac14df7ba87e33c4b193e31b94690192b8a118bc3e99b09cad13f1aa521f4ea68959b9c4efa7af9acd765babe5844a1e597cd53e331753466e5bac1f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brainstem (1.3.0)
4
+ brainstem (1.4.0)
5
5
  activerecord (>= 4.1)
6
6
  activesupport (>= 4.1)
7
7
 
@@ -22,12 +22,12 @@ GEM
22
22
  arel (8.0.0)
23
23
  coderay (1.1.2)
24
24
  concurrent-ruby (1.0.5)
25
- database_cleaner (1.6.1)
25
+ database_cleaner (1.6.2)
26
26
  db-query-matchers (0.9.0)
27
27
  activesupport (>= 4.0, <= 6.0)
28
28
  rspec (~> 3.0)
29
29
  diff-lcs (1.3)
30
- i18n (0.9.0)
30
+ i18n (0.9.1)
31
31
  concurrent-ruby (~> 1.0)
32
32
  method_source (0.9.0)
33
33
  minitest (5.10.3)
@@ -101,12 +101,24 @@ module Brainstem
101
101
  # Is a string because most relevant classes are not loaded until much
102
102
  # later.
103
103
  #
104
- # @see Brainstem::ApiDocs::RailsIntrospector#base_presenter_class=
104
+ # @see Brainstem::ApiDocs::RailsIntrospector#base_controller_class=
105
105
  #
106
106
  config_accessor(:base_controller_class) do
107
107
  "::ApplicationController"
108
108
  end
109
109
 
110
+ #
111
+ # Defines the application or engine that all routes will be fetched from.
112
+ #
113
+ # Is a proc because most relevant classes are not loaded until much
114
+ # later.
115
+ #
116
+ # @see Brainstem::ApiDocs::RailsIntrospector#base_application_proc=
117
+ #
118
+ config_accessor(:base_application_proc) do
119
+ Proc.new { Rails.application }
120
+ end
121
+
110
122
 
111
123
  #
112
124
  # If associations on a presenter have no description, i.e. no documentation,
@@ -70,6 +70,7 @@ module Brainstem
70
70
  :rails_environment_file,
71
71
  :base_presenter_class,
72
72
  :base_controller_class,
73
+ :base_application_proc
73
74
  ]
74
75
  end
75
76
 
@@ -175,6 +176,24 @@ module Brainstem
175
176
  attr_writer :base_controller_class
176
177
 
177
178
 
179
+ #
180
+ # Returns a proc that will return the application or engine to get routes from.
181
+ #
182
+ # @return [Proc] Proc that returns the Rails application or an engine
183
+ #
184
+ def base_application_proc
185
+ @base_application_proc ||= Proc.new { Rails.application }
186
+ end
187
+
188
+
189
+ #
190
+ # Allows for the specification for an alternate base application
191
+ #
192
+ # @param [Proc] Proc that returns the Rails application or an engine
193
+ #
194
+ attr_writer :base_application_proc
195
+
196
+
178
197
  #
179
198
  # Returns the proc that is called to format and retrieve routes.
180
199
  # The proc's return must be an array of hashes that contains the
@@ -188,7 +207,7 @@ module Brainstem
188
207
  #
189
208
  def routes_method
190
209
  @routes_method ||= Proc.new do
191
- Rails.application.routes.routes.map do |route|
210
+ base_application_proc.call.routes.routes.map do |route|
192
211
  next unless route.defaults.has_key?(:controller) &&
193
212
  controller_const = "#{route.defaults[:controller]}_controller"
194
213
  .classify
@@ -1,3 +1,3 @@
1
1
  module Brainstem
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -9,17 +9,15 @@ module Brainstem
9
9
  File.expand_path('../../../../../spec/dummy/rails.rb', __FILE__)
10
10
  end
11
11
 
12
- let(:described_klass) { RailsIntrospector }
13
- let(:default_args) { { rails_environment_file: dummy_environment_file } }
12
+ let(:default_args) { { rails_environment_file: dummy_environment_file } }
14
13
 
15
14
  subject do
16
- RailsIntrospector.send(:new, default_args)
15
+ described_class.send(:new, default_args)
17
16
  end
18
17
 
19
-
20
18
  context "when cannot find the environment file" do
21
19
  describe "#load_environment!" do
22
- subject { described_klass.send(:new) }
20
+ subject { described_class.send(:new) }
23
21
 
24
22
  before do
25
23
  # In the event that we've already loaded the environment through
@@ -74,11 +72,11 @@ module Brainstem
74
72
 
75
73
  describe "#presenters" do
76
74
  before do
77
- stub.any_instance_of(described_klass).validate!
75
+ stub.any_instance_of(described_class).validate!
78
76
  end
79
77
 
80
78
  subject do
81
- described_klass.with_loaded_environment(
79
+ described_class.with_loaded_environment(
82
80
  default_args.merge(base_presenter_class: "::FakeBasePresenter")
83
81
  )
84
82
  end
@@ -96,11 +94,11 @@ module Brainstem
96
94
 
97
95
  describe "#controllers" do
98
96
  before do
99
- stub.any_instance_of(described_klass).validate!
97
+ stub.any_instance_of(described_class).validate!
100
98
  end
101
99
 
102
100
  subject do
103
- described_klass.with_loaded_environment(
101
+ described_class.with_loaded_environment(
104
102
  default_args.merge(base_controller_class: "::FakeBaseController")
105
103
  )
106
104
  end
@@ -120,12 +118,12 @@ module Brainstem
120
118
  let(:a_proc) { Object.new }
121
119
 
122
120
  before do
123
- stub.any_instance_of(described_klass).validate!
121
+ stub.any_instance_of(described_class).validate!
124
122
  end
125
123
 
126
124
  context "with dummy method" do
127
125
  subject do
128
- described_klass.with_loaded_environment(
126
+ described_class.with_loaded_environment(
129
127
  default_args.merge(routes_method: a_proc)
130
128
  )
131
129
  end
@@ -142,7 +140,7 @@ module Brainstem
142
140
 
143
141
  context "with fake (but realistic) data" do
144
142
  subject do
145
- described_klass.with_loaded_environment(default_args)
143
+ described_class.with_loaded_environment(default_args)
146
144
  end
147
145
 
148
146
  it "skips the entry if it does not have a valid controller" do
@@ -160,7 +158,38 @@ module Brainstem
160
158
  it "transforms the HTTP method regexp into a list of verbs" do
161
159
  expect(subject.routes.first[:http_methods]).to eq %w(GET POST)
162
160
  end
161
+ end
162
+
163
+ context "with an alternate base application or engine provided" do
164
+ let(:base_application_proc) { Proc.new { FakeRailsApplication.new(true, routes) } }
165
+ let(:routes) { FakeRailsRoutesObject.new([route_1, route_2]) }
166
+ let(:route_1) {
167
+ FakeRailsRoute.new(
168
+ "fake_descendant",
169
+ FakeRailsRoutePathObject.new(spec: '/fake_route_1'),
170
+ { controller: "fake_descendant", action: "show" },
171
+ { :request_method => /^GET$/ }
172
+ )
173
+ }
174
+ let(:route_2) {
175
+ FakeRailsRoute.new(
176
+ "fake_descendant",
177
+ FakeRailsRoutePathObject.new(spec: '/fake_route_2'),
178
+ { controller: "fake_descendant", action: "show" },
179
+ { :request_method => /^GET$/ }
180
+ )
181
+ }
163
182
 
183
+ subject do
184
+ described_class.with_loaded_environment(default_args.merge({ base_application_proc: base_application_proc }))
185
+ end
186
+
187
+ it "recognizes the configured application or engine's routes" do
188
+ expect(subject.routes.map { |route| route[:path] }).to match_array([
189
+ { spec: "/fake_route_1" }.to_s,
190
+ { spec: "/fake_route_2" }.to_s
191
+ ])
192
+ end
164
193
  end
165
194
  end
166
195
  end
@@ -5,7 +5,6 @@ module Brainstem
5
5
  describe ApiDocs do
6
6
  let(:lorem) { "lorem ipsum dolor sit amet" }
7
7
 
8
-
9
8
  describe "configuration" do
10
9
  describe "formatters" do
11
10
  it "has a formatters constant" do
@@ -13,7 +12,6 @@ module Brainstem
13
12
  end
14
13
  end
15
14
 
16
-
17
15
  %w(
18
16
  controller_filename_pattern
19
17
  presenter_filename_pattern
@@ -23,21 +21,22 @@ module Brainstem
23
21
  output_extension
24
22
  base_presenter_class
25
23
  base_controller_class
24
+ base_application_proc
26
25
  document_empty_presenter_associations
27
26
  document_empty_presenter_filters
28
27
  ).each do |meth|
29
28
  describe meth do
30
29
  before do
31
- @original = Brainstem::ApiDocs.public_send(meth)
30
+ @original = described_class.public_send(meth)
32
31
  end
33
32
 
34
33
  after do
35
- Brainstem::ApiDocs.public_send("#{meth}=", @original)
34
+ described_class.public_send("#{meth}=", @original)
36
35
  end
37
36
 
38
37
  it "can be set and read" do
39
- Brainstem::ApiDocs.public_send("#{meth}=", lorem)
40
- expect(Brainstem::ApiDocs.public_send(meth)).to eq lorem
38
+ described_class.public_send("#{meth}=", lorem)
39
+ expect(described_class.public_send(meth)).to eq lorem
41
40
  end
42
41
  end
43
42
  end
@@ -45,14 +44,12 @@ module Brainstem
45
44
 
46
45
  describe "filename link patterns" do
47
46
  it 'defaults to the filename pattern' do
48
- expect(Brainstem::ApiDocs.public_send("controller_filename_link_pattern")).
49
- to eq(Brainstem::ApiDocs.public_send("controller_filename_pattern"))
47
+ expect(described_class.public_send("controller_filename_link_pattern")).
48
+ to eq(described_class.public_send("controller_filename_pattern"))
50
49
 
51
- expect(Brainstem::ApiDocs.public_send("presenter_filename_link_pattern")).
52
- to eq(Brainstem::ApiDocs.public_send("presenter_filename_pattern"))
50
+ expect(described_class.public_send("presenter_filename_link_pattern")).
51
+ to eq(described_class.public_send("presenter_filename_pattern"))
53
52
  end
54
53
  end
55
-
56
-
57
54
  end
58
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainstem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mavenlink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord