before_actions 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +106 -0
- data/Rakefile +13 -19
- data/app/controllers/before_actions/foo_controller.rb +8 -0
- data/lib/before_actions.rb +7 -1
- data/lib/before_actions/controller.rb +29 -20
- data/lib/before_actions/engine.rb +7 -0
- data/lib/before_actions/version.rb +1 -1
- data/spec/controllers/admin_foos_controller_spec.rb +78 -0
- data/spec/controllers/foos_controller_spec.rb +139 -0
- data/{test → spec}/dummy/README.rdoc +0 -0
- data/{test → spec}/dummy/Rakefile +0 -0
- data/{test → spec}/dummy/app/assets/javascripts/application.js +0 -3
- data/{test → spec}/dummy/app/assets/stylesheets/application.css +0 -0
- data/spec/dummy/app/controllers/admin_foos_controller.rb +53 -0
- data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/foos_controller.rb +92 -0
- data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/models/admin_foo.rb +2 -0
- data/spec/dummy/app/models/foo.rb +3 -0
- data/spec/dummy/app/views/admin_foos/_form.html.erb +21 -0
- data/spec/dummy/app/views/admin_foos/edit.html.erb +6 -0
- data/spec/dummy/app/views/admin_foos/index.html.erb +25 -0
- data/spec/dummy/app/views/admin_foos/new.html.erb +5 -0
- data/spec/dummy/app/views/admin_foos/show.html.erb +9 -0
- data/spec/dummy/app/views/foos/_form.html.erb +21 -0
- data/spec/dummy/app/views/foos/edit.html.erb +6 -0
- data/spec/dummy/app/views/foos/index.html.erb +25 -0
- data/spec/dummy/app/views/foos/new.html.erb +5 -0
- data/spec/dummy/app/views/foos/show.html.erb +9 -0
- data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
- data/{test → spec}/dummy/bin/bundle +0 -0
- data/{test → spec}/dummy/bin/rails +0 -0
- data/{test → spec}/dummy/bin/rake +0 -0
- data/{test → spec}/dummy/config.ru +0 -0
- data/{test → spec}/dummy/config/application.rb +8 -0
- data/{test → spec}/dummy/config/boot.rb +0 -0
- data/{test → spec}/dummy/config/database.yml +0 -0
- data/{test → spec}/dummy/config/environment.rb +0 -0
- data/{test → spec}/dummy/config/environments/development.rb +0 -0
- data/{test → spec}/dummy/config/environments/production.rb +0 -0
- data/{test → spec}/dummy/config/environments/test.rb +0 -0
- data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/{test → spec}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
- data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
- data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
- data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/{test → spec}/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/{test → spec}/dummy/config/locales/en.yml +0 -0
- data/{test → spec}/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140912040816_create_foos.rb +9 -0
- data/spec/dummy/db/migrate/20140912042735_create_admin_foos.rb +9 -0
- data/spec/dummy/db/schema.rb +28 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/templates/rails/scaffold_controller/controller.rb +97 -0
- data/spec/dummy/log/development.log +15 -0
- data/spec/dummy/log/test.log +1590 -0
- data/{test → spec}/dummy/public/404.html +0 -0
- data/{test → spec}/dummy/public/422.html +0 -0
- data/{test → spec}/dummy/public/500.html +0 -0
- data/{test → spec}/dummy/public/favicon.ico +0 -0
- data/spec/rails_helper.rb +54 -0
- data/spec/spec_helper.rb +85 -0
- metadata +168 -74
- data/README.rdoc +0 -60
- data/lib/before_actions/command.rb +0 -15
- data/test/before_actions_test.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/integration/navigation_test.rb +0 -10
- data/test/test_helper.rb +0 -15
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class AdminFoosController < ApplicationController
|
2
|
+
|
3
|
+
# Use callbacks to share common setup or constraints between actions.
|
4
|
+
before_actions do
|
5
|
+
actions(:new, :create, :edit, :update, :destroy) { render_not_authorized }
|
6
|
+
actions(:index) { @admin_foos = AdminFoo.all }
|
7
|
+
actions(:new) { raise_it }
|
8
|
+
actions(:create) { raise_it }
|
9
|
+
actions(:show, :edit, :update, :destroy) { @admin_foo = AdminFoo.find(params[:id]) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def index
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
def new
|
22
|
+
raise_it
|
23
|
+
end
|
24
|
+
|
25
|
+
def create
|
26
|
+
raise_it
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
raise_it
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
raise_it
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
raise_it
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def render_not_authorized
|
44
|
+
render text: "not authorized", status: :unauthorized
|
45
|
+
end
|
46
|
+
|
47
|
+
def raise_it
|
48
|
+
raise "expect not to run this code"
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
File without changes
|
@@ -0,0 +1,92 @@
|
|
1
|
+
class FoosController < ApplicationController
|
2
|
+
|
3
|
+
# Use callbacks to share common setup or constraints between actions.
|
4
|
+
before_actions do
|
5
|
+
actions { } # load your nested resource's parent here if you need one
|
6
|
+
actions(:index) { @foos = Foo.all }
|
7
|
+
actions(:new) { @foo = Foo.new }
|
8
|
+
actions(:create) { @foo = Foo.new(foo_params) }
|
9
|
+
actions(:show, :edit, :update, :destroy) { @foo = Foo.find(params[:id]) }
|
10
|
+
actions { } # run your authorization logic here if you need one
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /foos
|
14
|
+
# GET /foos.json
|
15
|
+
def index
|
16
|
+
respond_to do |format|
|
17
|
+
format.html # index.html.erb
|
18
|
+
format.json { render json: @foos }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
# GET /foos/new
|
25
|
+
def new
|
26
|
+
end
|
27
|
+
|
28
|
+
# GET /foos/1
|
29
|
+
# GET /foos/1.json
|
30
|
+
def show
|
31
|
+
respond_to do |format|
|
32
|
+
format.html # show.html.erb
|
33
|
+
format.json { render json: @foo }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# GET /foos/1/edit
|
38
|
+
def edit
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# POST /foos
|
44
|
+
# POST /foos.json
|
45
|
+
def create
|
46
|
+
respond_to do |format|
|
47
|
+
if @foo.save
|
48
|
+
format.html { redirect_to @foo, notice: 'Foo was successfully created.' }
|
49
|
+
format.json { render json: @foo, status: :created }
|
50
|
+
else
|
51
|
+
format.html { render action: 'new' }
|
52
|
+
format.json { render json: @foo.errors, status: :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# PATCH/PUT /foos/1
|
58
|
+
# PATCH/PUT /foos/1.json
|
59
|
+
def update
|
60
|
+
respond_to do |format|
|
61
|
+
if @foo.update(foo_params)
|
62
|
+
format.html { redirect_to @foo, notice: 'Foo was successfully updated.' }
|
63
|
+
format.json { head :no_content }
|
64
|
+
else
|
65
|
+
format.html { render action: 'edit' }
|
66
|
+
format.json { render json: @foo.errors, status: :unprocessable_entity }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# DELETE /foos/1
|
72
|
+
# DELETE /foos/1
|
73
|
+
def destroy
|
74
|
+
respond_to do |format|
|
75
|
+
if @foo.destroy
|
76
|
+
format.html { redirect_to foos_url, notice: 'Foo was successfully destroyed.' }
|
77
|
+
format.json { head :no_content }
|
78
|
+
else
|
79
|
+
format.html { render action: 'edit' }
|
80
|
+
format.json { render json: @foo.errors, status: :unprocessable_entity }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Only allow a trusted parameter "white list" through.
|
88
|
+
def foo_params
|
89
|
+
params.require(:foo).permit(:bar)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%= form_for(@admin_foo) do |f| %>
|
2
|
+
<% if @admin_foo.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@admin_foo.errors.count, "error") %> prohibited this admin_foo from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @admin_foo.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :bar %><br>
|
16
|
+
<%= f.text_field :bar %>
|
17
|
+
</div>
|
18
|
+
<div class="actions">
|
19
|
+
<%= f.submit %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing admin_foos</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Bar</th>
|
7
|
+
<th colspan="3"></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
|
11
|
+
<tbody>
|
12
|
+
<% @admin_foos.each do |admin_foo| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= admin_foo.bar %></td>
|
15
|
+
<td><%= link_to 'Show', admin_foo %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_admin_foo_path(admin_foo) %></td>
|
17
|
+
<td><%= link_to 'Destroy', admin_foo, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
25
|
+
<%= link_to 'New Admin foo', new_admin_foo_path %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%= form_for(@foo) do |f| %>
|
2
|
+
<% if @foo.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@foo.errors.count, "error") %> prohibited this foo from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @foo.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :bar %><br>
|
16
|
+
<%= f.text_field :bar %>
|
17
|
+
</div>
|
18
|
+
<div class="actions">
|
19
|
+
<%= f.submit %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing foos</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Bar</th>
|
7
|
+
<th colspan="3"></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
|
11
|
+
<tbody>
|
12
|
+
<% @foos.each do |foo| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= foo.bar %></td>
|
15
|
+
<td><%= link_to 'Show', foo %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_foo_path(foo) %></td>
|
17
|
+
<td><%= link_to 'Destroy', foo, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
25
|
+
<%= link_to 'New Foo', new_foo_path %>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -18,6 +18,14 @@ module Dummy
|
|
18
18
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
19
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
20
|
# config.i18n.default_locale = :de
|
21
|
+
|
22
|
+
# don't generate RSpec tests for views and helpers
|
23
|
+
config.generators do |g|
|
24
|
+
g.test_framework :rspec
|
25
|
+
g.stylesheets = false
|
26
|
+
g.javascripts = false
|
27
|
+
g.helper = false
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20140912042735) do
|
15
|
+
|
16
|
+
create_table "admin_foos", force: true do |t|
|
17
|
+
t.string "bar"
|
18
|
+
t.datetime "created_at"
|
19
|
+
t.datetime "updated_at"
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "foos", force: true do |t|
|
23
|
+
t.string "bar"
|
24
|
+
t.datetime "created_at"
|
25
|
+
t.datetime "updated_at"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|