decent_exposure 3.0.0 → 3.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 +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -5
- data/decent_exposure.gemspec +1 -0
- data/lib/decent_exposure.rb +2 -0
- data/lib/decent_exposure/context.rb +1 -1
- data/lib/decent_exposure/exposure.rb +3 -2
- data/lib/decent_exposure/mailer.rb +14 -0
- data/lib/decent_exposure/version.rb +1 -1
- data/spec/{controller_spec.rb → decent_exposure/controller_spec.rb} +8 -3
- data/spec/features/api_birds_controller_spec.rb +70 -0
- data/spec/features/birds_controller_spec.rb +70 -0
- data/spec/features/birds_mailer_spec.rb +44 -0
- data/spec/support/rails_app.rb +36 -6
- metadata +26 -6
- data/spec/integration_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c22278ff98a7439d7b4a8b1f6cde9f9a1dc9a9a
|
4
|
+
data.tar.gz: 7a781674c590dbf7d1d200895babf9633b49c733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa99377c24ced53c356cbb1fbf7c37b261085011de8eb0c104c2fdbfef54f3befed765f5aabf3bffaee6e900b948e640b84891c9b51b22378a98b9a3ffcdddc
|
7
|
+
data.tar.gz: 97a5d39339fd28c51c003e1aa216c1174bcfbaa85d80f25c0ce87db98ecaf82dac2521ae3a89c6b271d470d5dcb460d795acc5f5c33b5194756a10ac1d4341a8
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# DecentExposure History/Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
|
+
|
6
|
+
|
7
|
+
## 3.0.1
|
8
|
+
|
9
|
+
* Allow exposures with a question mark (?).
|
10
|
+
* Remove setter from view helper.
|
11
|
+
* Fix undefined `helper_method` error
|
12
|
+
|
13
|
+
## 3.0.0
|
14
|
+
|
15
|
+
* New codebase, see [api changes document](https://github.com/hashrocket/decent_exposure/wiki/Api-changes-in-version-3).
|
16
|
+
|
data/README.md
CHANGED
@@ -334,18 +334,15 @@ Mailers and Controllers use the save decent_exposure dsl.
|
|
334
334
|
|
335
335
|
```ruby
|
336
336
|
class PostMailer < ApplicationMailer
|
337
|
-
attr_accessor :post_id
|
338
|
-
|
339
337
|
expose(:posts, -> { Post.last(10) })
|
340
|
-
expose(:post
|
338
|
+
expose(:post)
|
341
339
|
|
342
340
|
def top_posts
|
343
341
|
@greeting = "Top Posts"
|
344
342
|
mail to: "to@example.org"
|
345
343
|
end
|
346
344
|
|
347
|
-
def featured_post(
|
348
|
-
self.post_id = post_id
|
345
|
+
def featured_post(id:)
|
349
346
|
@greeting = "Featured Post"
|
350
347
|
mail to: "to@example.org"
|
351
348
|
end
|
data/decent_exposure.gemspec
CHANGED
data/lib/decent_exposure.rb
CHANGED
@@ -4,6 +4,7 @@ require "generators/decent_exposure/scaffold_templates_generator"
|
|
4
4
|
|
5
5
|
module DecentExposure
|
6
6
|
autoload :Controller, "decent_exposure/controller"
|
7
|
+
autoload :Mailer, "decent_exposure/mailer"
|
7
8
|
autoload :Exposure, "decent_exposure/exposure"
|
8
9
|
autoload :Attribute, "decent_exposure/attribute"
|
9
10
|
autoload :Context, "decent_exposure/context"
|
@@ -16,5 +17,6 @@ module DecentExposure
|
|
16
17
|
|
17
18
|
ActiveSupport.on_load :action_mailer do
|
18
19
|
include Controller
|
20
|
+
include Mailer
|
19
21
|
end
|
20
22
|
end
|
@@ -67,8 +67,9 @@ module DecentExposure
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def expose_helper_methods!
|
70
|
-
|
71
|
-
|
70
|
+
return unless controller.respond_to?(:helper_method)
|
71
|
+
|
72
|
+
controller.helper_method attribute.getter_method_name
|
72
73
|
end
|
73
74
|
|
74
75
|
def normalize_options
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe DecentExposure::Controller do
|
3
|
+
RSpec.describe DecentExposure::Controller do
|
4
4
|
class Thing; end
|
5
5
|
class DifferentThing; end
|
6
6
|
|
@@ -41,8 +41,13 @@ describe DecentExposure::Controller do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
context "helper methods" do
|
44
|
-
it "exposes getter
|
45
|
-
expect(controller_klass).to receive(:helper_method).with(:thing
|
44
|
+
it "exposes getter as controller helper methods" do
|
45
|
+
expect(controller_klass).to receive(:helper_method).with(:thing)
|
46
|
+
expose :thing
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does not expose setter as controller helper methods" do
|
50
|
+
expect(controller_klass).to_not receive(:helper_method).with(:thing=)
|
46
51
|
expose :thing
|
47
52
|
end
|
48
53
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "support/rails_app"
|
3
|
+
require "rspec/rails"
|
4
|
+
|
5
|
+
RSpec.describe Api::BirdsController, type: :controller do
|
6
|
+
let(:bird){ Bird.new }
|
7
|
+
|
8
|
+
context 'when birds relation is exposed' do
|
9
|
+
class Api::BirdsController
|
10
|
+
expose :birds, ->{ Bird.all }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "fetches all birds" do
|
14
|
+
expect(Bird).to receive(:all).and_return([bird])
|
15
|
+
get :index
|
16
|
+
expect(controller.birds).to eq([bird])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when a bird is exposed' do
|
21
|
+
class Api::BirdsController
|
22
|
+
expose :bird
|
23
|
+
end
|
24
|
+
|
25
|
+
it "finds model by id" do
|
26
|
+
expect(Bird).to receive(:find).with("bird-id").and_return(bird)
|
27
|
+
get :show, request_params(id: "bird-id")
|
28
|
+
expect(controller.bird).to eq(bird)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "finds model by bird_id" do
|
32
|
+
expect(Bird).to receive(:find).with("bird-id").and_return(bird)
|
33
|
+
get :new, request_params(bird_id: "bird-id")
|
34
|
+
expect(controller.bird).to eq(bird)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "builds bird if id is not provided" do
|
38
|
+
get :new
|
39
|
+
expect(controller.bird).to be_a(Bird)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when bird_params is defined" do
|
44
|
+
class Api::BirdsController
|
45
|
+
expose :bird
|
46
|
+
|
47
|
+
def bird_params
|
48
|
+
params.require(:bird).permit(:name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "bird is build with params set" do
|
53
|
+
post :create, request_params(bird: { name: "crow" })
|
54
|
+
expect(controller.bird.name).to eq("crow")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when a bird? with a question mark is exposed' do
|
59
|
+
class Api::BirdsController
|
60
|
+
expose :bird
|
61
|
+
expose :bird?, -> { bird.present? }
|
62
|
+
end
|
63
|
+
|
64
|
+
it "exposes bird?" do
|
65
|
+
expect(Bird).to receive(:find).with("bird-id").and_return(bird)
|
66
|
+
get :show, request_params(id: "bird-id")
|
67
|
+
expect(controller.bird?).to be true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "support/rails_app"
|
3
|
+
require "rspec/rails"
|
4
|
+
|
5
|
+
RSpec.describe BirdsController, type: :controller do
|
6
|
+
let(:bird){ Bird.new }
|
7
|
+
|
8
|
+
context 'when birds relation is exposed' do
|
9
|
+
class BirdsController
|
10
|
+
expose :birds, ->{ Bird.all }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "fetches all birds" do
|
14
|
+
expect(Bird).to receive(:all).and_return([bird])
|
15
|
+
get :index
|
16
|
+
expect(controller.birds).to eq([bird])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when a bird is exposed' do
|
21
|
+
class BirdsController
|
22
|
+
expose :bird
|
23
|
+
end
|
24
|
+
|
25
|
+
it "finds model by id" do
|
26
|
+
expect(Bird).to receive(:find).with("bird-id").and_return(bird)
|
27
|
+
get :show, request_params(id: "bird-id")
|
28
|
+
expect(controller.bird).to eq(bird)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "finds model by bird_id" do
|
32
|
+
expect(Bird).to receive(:find).with("bird-id").and_return(bird)
|
33
|
+
get :new, request_params(bird_id: "bird-id")
|
34
|
+
expect(controller.bird).to eq(bird)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "builds bird if id is not provided" do
|
38
|
+
get :new
|
39
|
+
expect(controller.bird).to be_a(Bird)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when bird_params is defined" do
|
44
|
+
class BirdsController
|
45
|
+
expose :bird
|
46
|
+
|
47
|
+
def bird_params
|
48
|
+
params.require(:bird).permit(:name)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "bird is build with params set" do
|
53
|
+
post :create, request_params(bird: { name: "crow" })
|
54
|
+
expect(controller.bird.name).to eq("crow")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when a bird? with a question mark is exposed' do
|
59
|
+
class BirdsController
|
60
|
+
expose :bird
|
61
|
+
expose :bird?, -> { bird.present? }
|
62
|
+
end
|
63
|
+
|
64
|
+
it "exposes bird?" do
|
65
|
+
expect(Bird).to receive(:find).with("bird-id").and_return(bird)
|
66
|
+
get :show, request_params(id: "bird-id")
|
67
|
+
expect(controller.bird?).to be true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "support/rails_app"
|
3
|
+
require "rspec/rails"
|
4
|
+
require "action_mailer"
|
5
|
+
|
6
|
+
class BirdsMailer < ActionMailer::Base
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.describe BirdsMailer, type: :mailer do
|
10
|
+
let(:bird){ double :bird }
|
11
|
+
let(:birds) { double :birds }
|
12
|
+
|
13
|
+
context "when birds relation is exposed" do
|
14
|
+
class BirdsMailer
|
15
|
+
expose(:birds, -> { Bird.all })
|
16
|
+
|
17
|
+
def hello_birds
|
18
|
+
mail { |format| format.text { render plain: "Hello #{birds}" } }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sends the email with exposed birds" do
|
23
|
+
expect(Bird).to receive(:all).and_return(birds)
|
24
|
+
expect(described_class.hello_birds.body.to_s)
|
25
|
+
.to include("Hello #{birds}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when bird is exposed" do
|
30
|
+
class BirdsMailer
|
31
|
+
expose(:bird)
|
32
|
+
|
33
|
+
def hello_bird(id:)
|
34
|
+
mail { |format| format.text { render plain: "Hello #{bird}" } }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "sends the email with exposed bird" do
|
39
|
+
expect(Bird).to receive(:find).with('some-id').and_return(bird)
|
40
|
+
expect(described_class.hello_bird(id: 'some-id').body.to_s)
|
41
|
+
.to include("Hello #{bird}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/support/rails_app.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
require "active_support/all"
|
2
1
|
require "action_controller"
|
3
|
-
require "action_dispatch"
|
4
2
|
require "rails"
|
5
3
|
|
4
|
+
def request_params(params)
|
5
|
+
return params if Rails::VERSION::MAJOR < 5
|
6
|
+
{ params: params }
|
7
|
+
end
|
8
|
+
|
6
9
|
module Rails
|
7
10
|
class App
|
8
11
|
def env_config; {} end
|
@@ -10,28 +13,55 @@ module Rails
|
|
10
13
|
def routes
|
11
14
|
@routes ||= ActionDispatch::Routing::RouteSet.new.tap do |routes|
|
12
15
|
routes.draw do
|
13
|
-
|
16
|
+
resources :birds
|
17
|
+
|
18
|
+
namespace :api do
|
19
|
+
resources :birds
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
18
25
|
|
26
|
+
def self.root
|
27
|
+
''
|
28
|
+
end
|
29
|
+
|
19
30
|
def self.application
|
20
31
|
@app ||= App.new
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
24
35
|
class Bird
|
36
|
+
attr_accessor :name
|
37
|
+
def initialize(options = {})
|
38
|
+
options.each { |k, v| self.public_send("#{k}=", v) }
|
39
|
+
end
|
25
40
|
end
|
26
41
|
|
27
42
|
class ApplicationController < ActionController::Base
|
28
43
|
include Rails.application.routes.url_helpers
|
29
44
|
end
|
30
45
|
|
46
|
+
def base_api_class
|
47
|
+
return ApplicationController if Rails::VERSION::MAJOR < 5
|
48
|
+
ActionController::API
|
49
|
+
end
|
50
|
+
|
31
51
|
class BirdsController < ApplicationController
|
32
|
-
|
52
|
+
%i(index show edit new create update).each do |action|
|
53
|
+
define_method action do
|
54
|
+
head :ok
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
33
58
|
|
34
|
-
|
35
|
-
|
59
|
+
module Api
|
60
|
+
class BirdsController < base_api_class
|
61
|
+
%i(index show edit new create update).each do |action|
|
62
|
+
define_method action do
|
63
|
+
head :ok
|
64
|
+
end
|
65
|
+
end
|
36
66
|
end
|
37
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decent_exposure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Pravosud
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '4.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: actionmailer
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: rspec-rails
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,6 +81,7 @@ extra_rdoc_files: []
|
|
67
81
|
files:
|
68
82
|
- ".gitignore"
|
69
83
|
- ".travis.yml"
|
84
|
+
- CHANGELOG.md
|
70
85
|
- Gemfile
|
71
86
|
- LICENSE.txt
|
72
87
|
- README.md
|
@@ -83,6 +98,7 @@ files:
|
|
83
98
|
- lib/decent_exposure/controller.rb
|
84
99
|
- lib/decent_exposure/exposure.rb
|
85
100
|
- lib/decent_exposure/flow.rb
|
101
|
+
- lib/decent_exposure/mailer.rb
|
86
102
|
- lib/decent_exposure/version.rb
|
87
103
|
- lib/generators/decent_exposure/USAGE
|
88
104
|
- lib/generators/decent_exposure/scaffold_templates_generator.rb
|
@@ -97,9 +113,11 @@ files:
|
|
97
113
|
- lib/generators/decent_exposure/templates/new.html.haml
|
98
114
|
- lib/generators/decent_exposure/templates/show.html.erb
|
99
115
|
- lib/generators/decent_exposure/templates/show.html.haml
|
100
|
-
- spec/controller_spec.rb
|
116
|
+
- spec/decent_exposure/controller_spec.rb
|
117
|
+
- spec/features/api_birds_controller_spec.rb
|
118
|
+
- spec/features/birds_controller_spec.rb
|
119
|
+
- spec/features/birds_mailer_spec.rb
|
101
120
|
- spec/generators/decent_exposure/scaffold_templates_generator_spec.rb
|
102
|
-
- spec/integration_spec.rb
|
103
121
|
- spec/spec_helper.rb
|
104
122
|
- spec/support/rails_app.rb
|
105
123
|
homepage: https://github.com/hashrocket/decent_exposure
|
@@ -127,8 +145,10 @@ signing_key:
|
|
127
145
|
specification_version: 4
|
128
146
|
summary: A helper for creating declarative interfaces in controllers
|
129
147
|
test_files:
|
130
|
-
- spec/controller_spec.rb
|
148
|
+
- spec/decent_exposure/controller_spec.rb
|
149
|
+
- spec/features/api_birds_controller_spec.rb
|
150
|
+
- spec/features/birds_controller_spec.rb
|
151
|
+
- spec/features/birds_mailer_spec.rb
|
131
152
|
- spec/generators/decent_exposure/scaffold_templates_generator_spec.rb
|
132
|
-
- spec/integration_spec.rb
|
133
153
|
- spec/spec_helper.rb
|
134
154
|
- spec/support/rails_app.rb
|
data/spec/integration_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "support/rails_app"
|
3
|
-
require "rspec/rails"
|
4
|
-
|
5
|
-
describe BirdsController, type: :controller do
|
6
|
-
context "finds bird by id" do
|
7
|
-
let(:mockingbird){ double("Bird") }
|
8
|
-
before{ expect(Bird).to receive(:find).with("mockingbird").once.and_return(mockingbird) }
|
9
|
-
after{ expect(controller.bird).to eq(mockingbird) }
|
10
|
-
|
11
|
-
it "finds model by id" do
|
12
|
-
get :show, { id: "mockingbird" }
|
13
|
-
end
|
14
|
-
|
15
|
-
it "finds model by bird_id" do
|
16
|
-
get :show, { bird_id: "mockingbird" }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it "builds bird if id is not provided" do
|
21
|
-
bird = double("Bird")
|
22
|
-
expect(Bird).to receive(:new).with({}).and_return(bird)
|
23
|
-
get :show
|
24
|
-
expect(controller.bird).to eq(bird)
|
25
|
-
end
|
26
|
-
end
|