trailblazer 1.0.0.rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +2 -1
- data/Rakefile +3 -16
- data/lib/trailblazer/autoloading.rb +0 -1
- data/lib/trailblazer/operation.rb +1 -6
- data/lib/trailblazer/version.rb +1 -1
- data/test/operation/dsl/representer_test.rb +0 -1
- data/test/test_helper.rb +0 -55
- data/trailblazer.gemspec +2 -5
- metadata +7 -92
- data/lib/trailblazer/operation/controller/active_record.rb +0 -16
- data/lib/trailblazer/operation/responder.rb +0 -23
- data/lib/trailblazer/operation/worker.rb +0 -111
- data/test/fixtures/apotomo.png +0 -0
- data/test/fixtures/cells.png +0 -0
- data/test/rails/__respond_test.rb +0 -20
- data/test/rails/controller_test.rb +0 -159
- data/test/rails/endpoint_test.rb +0 -46
- data/test/rails/fake_app/app-cells/.gitkeep +0 -0
- data/test/rails/fake_app/cells.rb +0 -21
- data/test/rails/fake_app/config.rb +0 -3
- data/test/rails/fake_app/controllers.rb +0 -140
- data/test/rails/fake_app/models.rb +0 -34
- data/test/rails/fake_app/rails_app.rb +0 -78
- data/test/rails/fake_app/song/operations.rb +0 -144
- data/test/rails/fake_app/views/bands/index.html.erb +0 -1
- data/test/rails/fake_app/views/songs/another_view.html.erb +0 -2
- data/test/rails/fake_app/views/songs/new.html.erb +0 -1
- data/test/rails/respond_test.rb +0 -95
- data/test/rails/test_helper.rb +0 -9
- data/test/responder_test.rb +0 -75
- data/test/uploaded_file_test.rb +0 -85
- data/test/worker_test.rb +0 -124
data/test/fixtures/apotomo.png
DELETED
Binary file
|
data/test/fixtures/cells.png
DELETED
Binary file
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require "rack/test"
|
3
|
-
|
4
|
-
class Respond___Test < MiniTest::Spec
|
5
|
-
include Rack::Test::Methods
|
6
|
-
|
7
|
-
def app
|
8
|
-
Rails.application
|
9
|
-
end
|
10
|
-
|
11
|
-
it "respond with :namespace" do
|
12
|
-
# Rails.logger = Logger.new(STDOUT) # TODO: how do we get exceptions with rack-test?
|
13
|
-
|
14
|
-
post "/songs/create_with_namespace", {title: "Teenager Liebe"}.to_json, "CONTENT_TYPE" => "application/json", "HTTP_ACCEPT"=>"application/json"
|
15
|
-
# puts last_response.inspect
|
16
|
-
last_response.status.must_equal 201
|
17
|
-
id = Song.last.id
|
18
|
-
last_response.headers["Location"].must_equal "http://example.org/api/songs/#{id}"
|
19
|
-
end
|
20
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
# BUNDLE_GEMFILE=gemfiles/Gemfile.rails bundle exec rake rails
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
ActionController::TestCase.class_eval do
|
5
|
-
setup do
|
6
|
-
@routes = Rails.application.routes
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class GenericResponderTest < ActionController::TestCase
|
11
|
-
tests SongsController
|
12
|
-
|
13
|
-
setup do
|
14
|
-
@routes = Rails.application.routes
|
15
|
-
end
|
16
|
-
|
17
|
-
test "Create with params" do
|
18
|
-
post :create_with_params, {song: {title: "You're Going Down", length: 120}}
|
19
|
-
assert_response 302
|
20
|
-
|
21
|
-
song = Song.last
|
22
|
-
assert_equal "A Beautiful Indifference", song.title
|
23
|
-
assert_equal nil, song.length # params overwritten from controller.
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# overriding Controller#process_params.
|
28
|
-
class ProcessParamsTest < ActionController::TestCase
|
29
|
-
tests BandsController
|
30
|
-
|
31
|
-
setup do
|
32
|
-
@routes = Rails.application.routes
|
33
|
-
end
|
34
|
-
|
35
|
-
test "Create with overridden #process_params" do
|
36
|
-
post :create, band: {name: "Kreator"}
|
37
|
-
assert_redirected_to band_path(Band.last)
|
38
|
-
|
39
|
-
band = Band.last
|
40
|
-
assert_equal "Kreator", band.name
|
41
|
-
assert_equal "Essen", band.locality
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
class ResponderRunTest < ActionController::TestCase
|
48
|
-
tests BandsController
|
49
|
-
|
50
|
-
test "[html/valid]" do
|
51
|
-
put :update, {id: 1, band: {name: "Nofx"}}
|
52
|
-
assert_equal "no block: Nofx, Essen, Band::Create", response.body
|
53
|
-
end
|
54
|
-
|
55
|
-
test "[html/valid] with builds" do
|
56
|
-
put :update, {id: 1, band: {name: "Nofx"}, admin: true}
|
57
|
-
assert_equal "no block: Nofx [ADMIN], Essen, Band::Create::Admin", response.body
|
58
|
-
end
|
59
|
-
|
60
|
-
test "with block [html/valid]" do
|
61
|
-
put :update_with_block, {id: 1, band: {name: "Nofx"}}
|
62
|
-
assert_equal "[valid] with block: Nofx, Essen", response.body
|
63
|
-
end
|
64
|
-
|
65
|
-
test "with block [html/invalid]" do
|
66
|
-
put :update_with_block, {id: 1, band: {name: ""}}
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
#present.
|
71
|
-
class ControllerPresentTest < ActionController::TestCase
|
72
|
-
tests BandsController
|
73
|
-
|
74
|
-
# let (:band) { }
|
75
|
-
|
76
|
-
test "#present" do
|
77
|
-
band = Band::Create[band: {name: "Nofx"}].model
|
78
|
-
|
79
|
-
get :show, id: band.id
|
80
|
-
|
81
|
-
assert_equal "bands/show: Band,Band,Band::Update,Essen,nil", response.body
|
82
|
-
end
|
83
|
-
|
84
|
-
# TODO: this implicitely tests builds. maybe have separate test for that?
|
85
|
-
test "#present [JSON]" do
|
86
|
-
band = Band::Create[band: {name: "Nofx"}].model
|
87
|
-
|
88
|
-
get :show, id: band.id, format: :json
|
89
|
-
assert_equal "{\"name\":\"Nofx\"}", response.body
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
#collection
|
94
|
-
class ControllerCollectionTest < ActionController::TestCase
|
95
|
-
tests BandsController
|
96
|
-
|
97
|
-
# let (:band) { }
|
98
|
-
|
99
|
-
test "#collection" do
|
100
|
-
Band.destroy_all
|
101
|
-
Band::Create[band: {name: "Nofx"}]
|
102
|
-
Band::Create[band: {name: "Ramones"}]
|
103
|
-
|
104
|
-
|
105
|
-
get :index
|
106
|
-
|
107
|
-
assert_equal "bands/index.html: Nofx Ramones \n", response.body
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# #form.
|
112
|
-
class ControllerFormTest < ActionController::TestCase
|
113
|
-
tests BandsController
|
114
|
-
|
115
|
-
test "#form" do
|
116
|
-
get :new
|
117
|
-
assert_select "form input#band_name"
|
118
|
-
assert response.body =~ /<a>Sydney<\/a>/ # prepopulate!
|
119
|
-
assert_select "b", "Band,true,Band::Create,Band::Create,Essen"
|
120
|
-
end
|
121
|
-
|
122
|
-
test "#form with builder" do
|
123
|
-
get :new, admin: true
|
124
|
-
|
125
|
-
assert_select "b", "Band,true,Band::Create::Admin,Band::Create::Admin,Essen"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class ActiveRecordPresentTest < ActionController::TestCase
|
130
|
-
tests ActiveRecordBandsController
|
131
|
-
|
132
|
-
test "#present" do
|
133
|
-
band = Band::Create.(band: {name: "Nofx"}).model
|
134
|
-
get :show, id: band.id
|
135
|
-
|
136
|
-
assert_equal "active_record_bands/show.html: Band, Band, nil, Band::Update", response.body
|
137
|
-
end
|
138
|
-
|
139
|
-
test "#collection" do
|
140
|
-
Band.destroy_all
|
141
|
-
Band::Create[band: {name: "Nofx"}]
|
142
|
-
|
143
|
-
get :index
|
144
|
-
|
145
|
-
assert_equal "active_record_bands/index.html: Band::ActiveRecord_Relation, Band::ActiveRecord_Relation, Band::Index", response.body
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
class PrefixedTablenameControllerTest < ActionController::TestCase
|
150
|
-
tests TenantsController
|
151
|
-
|
152
|
-
test "show" do
|
153
|
-
tenant = Tenant.create(name: "My Tenant") # yepp, I am not using an operation! blasphemy!!!
|
154
|
-
get :show, id: tenant.id
|
155
|
-
|
156
|
-
assert_equal "My Tenant", response.body
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
data/test/rails/endpoint_test.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module RailsEndpoint
|
4
|
-
class ConfiguredTest < ActionDispatch::IntegrationTest
|
5
|
-
class Create < Trailblazer::Operation
|
6
|
-
include Model
|
7
|
-
model Band
|
8
|
-
|
9
|
-
def process(params)
|
10
|
-
@model = Band.create(params["band"].permit(:name)) # how ridiculous is strong_parameters?
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class JSONCreate < Create
|
15
|
-
def process(params)
|
16
|
-
@model = Band.create(JSON.parse(params["band"])) # document comes in keyed as "band".
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class BandsController < ApplicationController
|
21
|
-
include Trailblazer::Operation::Controller
|
22
|
-
respond_to :html, :json
|
23
|
-
|
24
|
-
def create
|
25
|
-
run Create if request.format == :html
|
26
|
-
run JSONCreate if request.format == :json
|
27
|
-
render text: ""
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
test "Create" do
|
32
|
-
post "/rails_endpoint/configured_test/bands", {band: {name: "All"}}
|
33
|
-
assert_response 200
|
34
|
-
assert_equal "All", Band.last.name
|
35
|
-
end
|
36
|
-
|
37
|
-
test "Create: JSON" do
|
38
|
-
post "/rails_endpoint/configured_test/bands.json", {name: "NOFX"}.to_json,'CONTENT_TYPE' => 'application/json', "HTTP_ACCEPT"=>"application/json" #, headers # FIXME: headers do not work
|
39
|
-
assert_response 200
|
40
|
-
assert_equal "NOFX", Band.last.name
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# test :is_document
|
46
|
-
# test :namespace
|
File without changes
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class UserCell < Cell::Rails
|
2
|
-
include Kaminari::Cells
|
3
|
-
|
4
|
-
def show(users)
|
5
|
-
@users = users
|
6
|
-
|
7
|
-
render inline: <<-ERB
|
8
|
-
<%= paginate @users %>
|
9
|
-
ERB
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class ViewModelCell < Cell::ViewModel
|
14
|
-
include Kaminari::Cells
|
15
|
-
|
16
|
-
def show
|
17
|
-
render inline: <<-ERB
|
18
|
-
<%= paginate model %>
|
19
|
-
ERB
|
20
|
-
end
|
21
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# controllers
|
2
|
-
class ApplicationController < ActionController::Base
|
3
|
-
append_view_path "test/rails/fake_app/views"
|
4
|
-
end
|
5
|
-
|
6
|
-
class SongsController < ApplicationController
|
7
|
-
respond_to :json, :js
|
8
|
-
|
9
|
-
def index
|
10
|
-
@users = Song.all.page params[:page]
|
11
|
-
render inline: <<-ERB
|
12
|
-
<%= render_cell(:user, :show, @users) %>
|
13
|
-
ERB
|
14
|
-
end
|
15
|
-
|
16
|
-
include Trailblazer::Operation::Controller
|
17
|
-
respond_to :html
|
18
|
-
|
19
|
-
def create
|
20
|
-
respond Song::Create
|
21
|
-
end
|
22
|
-
|
23
|
-
def other_create
|
24
|
-
respond Song::Create, location: other_create_songs_path, action: :another_view
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_with_params
|
28
|
-
respond Song::Create, {}, song: {title: "A Beautiful Indifference"}
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_with_block
|
32
|
-
respond Song::Create do |op, formats|
|
33
|
-
return render text: "block run, valid: #{op.valid?}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_with_namespace
|
38
|
-
respond Song::Create::Json, namespace: [:api]
|
39
|
-
end
|
40
|
-
|
41
|
-
def destroy
|
42
|
-
respond Song::Delete
|
43
|
-
end
|
44
|
-
|
45
|
-
def destroy_with_formats
|
46
|
-
respond Song::Delete do |op, formats|
|
47
|
-
formats.js { render text: "#{op.model.class} slayer!" }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class BandsController < ApplicationController
|
53
|
-
include Trailblazer::Operation::Controller
|
54
|
-
respond_to :html, :json
|
55
|
-
|
56
|
-
def index
|
57
|
-
collection Band::Index
|
58
|
-
end
|
59
|
-
|
60
|
-
def show
|
61
|
-
op = present Band::Update
|
62
|
-
@klass = op.model.class
|
63
|
-
@locality = params[:band][:locality] unless params[:format] == "json"
|
64
|
-
|
65
|
-
return render json: op.to_json if params[:format] == "json"
|
66
|
-
render text: "bands/show: #{[@klass, @model.class, @operation.class, @locality, @form.inspect].join(',')}"
|
67
|
-
end
|
68
|
-
|
69
|
-
def new
|
70
|
-
@op = form Band::Create
|
71
|
-
|
72
|
-
@locality = params[:band][:locality]
|
73
|
-
|
74
|
-
render inline: <<-ERB
|
75
|
-
<%= form_for @form do |f| %>
|
76
|
-
<%= f.text_field :name %>
|
77
|
-
<a><%= @form.locality %></a>
|
78
|
-
<% end %>
|
79
|
-
|
80
|
-
<b><%= [@model.class, @form.is_a?(Reform::Form), @operation.class, @op.class, @locality].join(",") %></b>
|
81
|
-
ERB
|
82
|
-
end
|
83
|
-
|
84
|
-
def create
|
85
|
-
respond Band::Create
|
86
|
-
end
|
87
|
-
|
88
|
-
def update
|
89
|
-
run Band::Create
|
90
|
-
|
91
|
-
render text: "no block: #{@operation.model.name}, #{params[:band][:locality]}, #{@operation.class}"
|
92
|
-
end
|
93
|
-
|
94
|
-
def update_with_block
|
95
|
-
run Band::Create do |op|
|
96
|
-
return render text: "[valid] with block: #{op.model.name}, #{params[:band][:locality]}"
|
97
|
-
end
|
98
|
-
|
99
|
-
render text: "[invalid] with block: #{@operation.model.name}, #{params[:band][:locality]}"
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
def process_params!(params) # this is where you set :current_user, etc.
|
104
|
-
return if params[:format] == "json"
|
105
|
-
|
106
|
-
params[:band] ||= {}
|
107
|
-
params[:band][:locality] = "Essen"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
require 'trailblazer/operation/controller/active_record'
|
112
|
-
class ActiveRecordBandsController < ApplicationController
|
113
|
-
include Trailblazer::Operation::Controller
|
114
|
-
include Trailblazer::Operation::Controller::ActiveRecord
|
115
|
-
respond_to :html
|
116
|
-
|
117
|
-
def index
|
118
|
-
collection Band::Index
|
119
|
-
render text: "active_record_bands/index.html: #{@collection.class}, #{@bands.class}, #{@operation.class}"
|
120
|
-
end
|
121
|
-
|
122
|
-
def show
|
123
|
-
present Band::Update
|
124
|
-
|
125
|
-
render text: "active_record_bands/show.html: #{@model.class}, #{@band.class}, #{@form.inspect}, #{@operation.class}"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
require 'trailblazer/operation/controller/active_record'
|
130
|
-
class TenantsController < ApplicationController
|
131
|
-
include Trailblazer::Operation::Controller
|
132
|
-
include Trailblazer::Operation::Controller::ActiveRecord
|
133
|
-
respond_to :html
|
134
|
-
|
135
|
-
def show
|
136
|
-
present Tenant::Show
|
137
|
-
render text: "#{@tenant.name}" # model ivar doesn't contain table prefix `bla.xxx`.
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# models
|
2
|
-
class Song < ActiveRecord::Base
|
3
|
-
end
|
4
|
-
|
5
|
-
class Band < ActiveRecord::Base
|
6
|
-
has_many :songs
|
7
|
-
end
|
8
|
-
|
9
|
-
class Tenant < ActiveRecord::Base
|
10
|
-
self.table_name = 'public.tenants'
|
11
|
-
end
|
12
|
-
|
13
|
-
# migrations
|
14
|
-
class CreateAllTables < ActiveRecord::Migration
|
15
|
-
def self.up
|
16
|
-
create_table(:songs) do |t|
|
17
|
-
t.string :title
|
18
|
-
t.integer :length
|
19
|
-
t.integer :band_id
|
20
|
-
end
|
21
|
-
|
22
|
-
create_table(:bands) do |t|
|
23
|
-
t.string :name
|
24
|
-
t.string :locality
|
25
|
-
end
|
26
|
-
|
27
|
-
create_table(:"public.tenants") do |t|
|
28
|
-
t.string :name
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
ActiveRecord::Migration.verbose = false
|
33
|
-
CreateAllTables.up
|
34
|
-
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# BUNDLE_GEMFILE=gemfiles/Gemfile.rails bundle exec rake rails
|
2
|
-
# TODO: how does rails handle all the different rake test tasks?
|
3
|
-
|
4
|
-
# require 'rails/all'
|
5
|
-
require 'action_controller/railtie'
|
6
|
-
require 'action_view/railtie'
|
7
|
-
require 'active_record'
|
8
|
-
require 'responders'
|
9
|
-
|
10
|
-
require 'fake_app/config'
|
11
|
-
|
12
|
-
|
13
|
-
# config
|
14
|
-
app = Class.new(Rails::Application)
|
15
|
-
app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
|
16
|
-
app.config.session_store :cookie_store, key: '_myapp_session'
|
17
|
-
app.config.active_support.deprecation = :log
|
18
|
-
app.config.eager_load = false
|
19
|
-
# Rais.root
|
20
|
-
app.config.root = File.dirname(__FILE__)
|
21
|
-
Rails.backtrace_cleaner.remove_silencers!
|
22
|
-
app.initialize!
|
23
|
-
|
24
|
-
# routes
|
25
|
-
app.routes.draw do
|
26
|
-
|
27
|
-
resources :songs do
|
28
|
-
member do # argh.
|
29
|
-
delete :destroy_with_formats
|
30
|
-
end
|
31
|
-
|
32
|
-
collection do
|
33
|
-
post :other_create
|
34
|
-
post :create_with_params
|
35
|
-
post :create_with_block
|
36
|
-
post :create_with_namespace
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
resources :active_record_bands
|
41
|
-
|
42
|
-
resources :bands do
|
43
|
-
collection do
|
44
|
-
post :create
|
45
|
-
get :new_with_block
|
46
|
-
end
|
47
|
-
|
48
|
-
member do
|
49
|
-
post :update_with_block
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
namespace :rails_endpoint do
|
54
|
-
namespace :unconfigured_test do
|
55
|
-
resources :bands
|
56
|
-
end
|
57
|
-
namespace :configured_test do
|
58
|
-
resources :bands
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
namespace :api do
|
63
|
-
resources :songs
|
64
|
-
end
|
65
|
-
|
66
|
-
resources :tenants, only: [:show]
|
67
|
-
end
|
68
|
-
|
69
|
-
require 'trailblazer/operation/responder'
|
70
|
-
require 'trailblazer/operation/controller'
|
71
|
-
require 'trailblazer/operation/representer'
|
72
|
-
|
73
|
-
require 'fake_app/controllers'
|
74
|
-
require 'fake_app/models'
|
75
|
-
require 'fake_app/song/operations.rb'
|
76
|
-
|
77
|
-
# helpers
|
78
|
-
Object.const_set(:ApplicationHelper, Module.new)
|