abstracted 0.0.4
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 +7 -0
- data/.envrc +1 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +218 -0
- data/Guardfile +77 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +15 -0
- data/abstracted.gemspec +51 -0
- data/app/assets/images/abstracted/.keep +0 -0
- data/app/assets/javascripts/abstract_resources.js +39 -0
- data/app/assets/javascripts/abstracted/.keep +0 -0
- data/app/assets/javascripts/crud.js.coffee +49 -0
- data/app/assets/javascripts/initializers.js.coffee +111 -0
- data/app/assets/stylesheets/abstract_resources.css +5 -0
- data/app/assets/stylesheets/abstracted/.keep +0 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/abstract_resources_controller.rb +290 -0
- data/app/controllers/application_controller.rb +22 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/abstract_resources_helper.rb +26 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/models/abstract_resource.rb +122 -0
- data/app/models/concerns/roleable.rb +61 -0
- data/app/policies/abstract_resource_policy.rb +58 -0
- data/app/views/.keep +0 -0
- data/app/views/abstract_resources/_default.html.erb +11 -0
- data/app/views/abstract_resources/destroy.js.haml +1 -0
- data/app/views/abstract_resources/edit.html.haml +11 -0
- data/app/views/abstract_resources/index.html.erb +1 -0
- data/app/views/abstract_resources/new.html.haml +12 -0
- data/app/views/abstract_resources/show.html.haml +13 -0
- data/bin/rails +12 -0
- data/config/locales/abstracted.en.yml +20 -0
- data/config/routes.rb +4 -0
- data/lib/abstracted.rb +8 -0
- data/lib/abstracted/engine.rb +19 -0
- data/lib/abstracted/version.rb +3 -0
- data/lib/abstracted_responder.rb +7 -0
- data/lib/tasks/abstracted_tasks.rake +4 -0
- data/spec/controllers/abstract_resources_controller_spec.rb +241 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +21 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +6229 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/abstract_resources.rb +6 -0
- data/spec/factories/users.rb +5 -0
- data/spec/features/posts/manage_posts_spec.rb +24 -0
- data/spec/models/abstract_resource_spec.rb +14 -0
- data/spec/rails_helper.rb +114 -0
- data/spec/spec_helper.rb +97 -0
- data/test/integration/abstract_resource_test.rb +7 -0
- metadata +424 -0
@@ -0,0 +1,241 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
|
4
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
5
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
6
|
+
# was generated by Rails when you ran the scaffold generator.
|
7
|
+
#
|
8
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
9
|
+
# generator. If you are using any extension libraries to generate different
|
10
|
+
# controller code, this generated spec may or may not pass.
|
11
|
+
#
|
12
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
13
|
+
# of tools you can use to make these specs even more expressive, but we're
|
14
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
15
|
+
#
|
16
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
17
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
18
|
+
# is no simpler way to get a handle on the object needed for the example.
|
19
|
+
# Message expectations are only used when there is no simpler way to specify
|
20
|
+
# that an instance is receiving a specific message.
|
21
|
+
RSpec.describe "nested requests", :type => :request do
|
22
|
+
|
23
|
+
describe "GET #index" do
|
24
|
+
it "gets all posts" do
|
25
|
+
get "/posts"
|
26
|
+
expect(assigns(:posts)).not_to eq([])
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets all posts to a user" do
|
30
|
+
user = User.create(login: 'fisk')
|
31
|
+
post = Post.create(user: user, title: 'fisk')
|
32
|
+
get user_posts_path(user_id: user.id)
|
33
|
+
expect(@controller.parent?).to eq true
|
34
|
+
expect(@controller.resources_url).to eq "/users/1/posts"
|
35
|
+
expect(@controller.resources.first).to eq (post)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec.describe UsersController, type: :controller do
|
43
|
+
|
44
|
+
|
45
|
+
# This should return the minimal set of attributes required to create a valid
|
46
|
+
# User. As you add validations to User, be sure to
|
47
|
+
# adjust the attributes here as well.
|
48
|
+
let(:valid_attributes) {
|
49
|
+
{id: 1,login:'mos'}
|
50
|
+
}
|
51
|
+
|
52
|
+
let(:invalid_attributes) {
|
53
|
+
{surname: 'mikkel',slogan: false}
|
54
|
+
}
|
55
|
+
|
56
|
+
let(:valid_post) {
|
57
|
+
{title: 'post', user_id: 1}
|
58
|
+
}
|
59
|
+
|
60
|
+
# This should return the minimal set of values that should be in the session
|
61
|
+
# in order to pass any filters (e.g. authentication) defined in
|
62
|
+
# UsersController. Be sure to keep this updated too.
|
63
|
+
let(:valid_session) { {} }
|
64
|
+
|
65
|
+
describe "GET #index" do
|
66
|
+
it "assigns all users as @resources" do
|
67
|
+
user = User.create! valid_attributes
|
68
|
+
get :index, {}, valid_session
|
69
|
+
expect(assigns(:resources)).to eq([user])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "GET #show" do
|
74
|
+
it "assigns the requested user as @resource" do
|
75
|
+
user = User.create! valid_attributes
|
76
|
+
get :show, {:id => user.to_param}, valid_session
|
77
|
+
expect(assigns(:resource)).to eq(user)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
describe "GET #new" do
|
83
|
+
it "assigns a new user as @resource" do
|
84
|
+
get :new, {}, valid_session
|
85
|
+
expect(assigns(:resource)).to be_a_new(User)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "GET #edit" do
|
90
|
+
it "assigns the requested user as @resource" do
|
91
|
+
user = User.create! valid_attributes
|
92
|
+
get :edit, {:id => user.to_param}, valid_session
|
93
|
+
expect(assigns(:resource)).to eq(user)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "POST #create" do
|
98
|
+
context "with valid params" do
|
99
|
+
it "creates a new User" do
|
100
|
+
expect {
|
101
|
+
post :create, {:user => valid_attributes}, valid_session
|
102
|
+
}.to change(User, :count).by(1)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "assigns a newly created user as @resource" do
|
106
|
+
post :create, {:user => valid_attributes}, valid_session
|
107
|
+
expect(assigns(:resource)).to be_a(User)
|
108
|
+
expect(assigns(:resource)).to be_persisted
|
109
|
+
end
|
110
|
+
|
111
|
+
it "redirects to the list of users, as @resources" do
|
112
|
+
post :create, {:user => valid_attributes}, valid_session
|
113
|
+
expect(response).to redirect_to(users_url)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# with Rails 4.x strong_parameters and Responders, forms with invalid attributes
|
118
|
+
# will silently fail - thus depriving haxors any idea of the issues
|
119
|
+
#
|
120
|
+
# context "with invalid params" do
|
121
|
+
# it "assigns a newly created but unsaved user as @user" do
|
122
|
+
# post :create, {:user => invalid_attributes}, valid_session
|
123
|
+
# expect(assigns(:resource)).to be_a_new(User)
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# it "re-renders the 'new' template" do
|
127
|
+
# post :create, {:user => invalid_attributes}, valid_session
|
128
|
+
# expect(response).to render_template("new")
|
129
|
+
# end
|
130
|
+
# end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "PUT #update" do
|
134
|
+
context "with valid params" do
|
135
|
+
let(:new_attributes) {
|
136
|
+
{ login: 'mil'}
|
137
|
+
}
|
138
|
+
|
139
|
+
it "updates the requested @resource" do
|
140
|
+
user = User.create! valid_attributes
|
141
|
+
put :update, {:id => user.to_param, :user => new_attributes}, valid_session
|
142
|
+
user.reload
|
143
|
+
expect(user.login).to eq('mil')
|
144
|
+
end
|
145
|
+
|
146
|
+
it "assigns the requested user as @resource" do
|
147
|
+
user = User.create! valid_attributes
|
148
|
+
put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
|
149
|
+
expect(assigns(:resource)).to eq(user)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "redirects to list of users" do
|
153
|
+
user = User.create! valid_attributes
|
154
|
+
put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
|
155
|
+
expect(response).to redirect_to(users_url)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# with Rails 4.x strong_parameters and Responders, forms with invalid attributes
|
160
|
+
# will silently fail - thus depriving haxors any idea of the issues
|
161
|
+
#
|
162
|
+
context "with invalid params" do
|
163
|
+
it "assigns the user as @resource" do
|
164
|
+
user = User.create! valid_attributes
|
165
|
+
put :update, {:id => user.to_param, :user => invalid_attributes}, valid_session
|
166
|
+
expect(assigns(:resource)).to eq(user)
|
167
|
+
end
|
168
|
+
#
|
169
|
+
# it "re-renders the 'edit' template" do
|
170
|
+
# user = User.create! valid_attributes
|
171
|
+
# put :update, {:id => user.to_param, :user => invalid_attributes}, valid_session
|
172
|
+
# expect(response).to render_template("edit")
|
173
|
+
# end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "DELETE #destroy" do
|
178
|
+
it "destroys the requested user" do
|
179
|
+
user = User.create! valid_attributes
|
180
|
+
expect {
|
181
|
+
delete :destroy, {:id => user.to_param}, valid_session
|
182
|
+
}.to change(User, :count).by(-1)
|
183
|
+
end
|
184
|
+
|
185
|
+
it "redirects to the users list" do
|
186
|
+
user = User.create! valid_attributes
|
187
|
+
delete :destroy, {:id => user.to_param}, valid_session
|
188
|
+
expect(response).to redirect_to(users_url)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
describe "inherited methods to verify resources, classes and names" do
|
194
|
+
|
195
|
+
it "any action should respond to parent?" do
|
196
|
+
get :index
|
197
|
+
expect(@controller.parent?).to eq(false)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "any action should respond to resource" do
|
201
|
+
get :new
|
202
|
+
expect(@controller.resource).not_to eq(nil)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "index action should respond to resources" do
|
206
|
+
get :index
|
207
|
+
expect(@controller.resources).not_to eq(nil)
|
208
|
+
end
|
209
|
+
|
210
|
+
it "any action should respond to resource_class" do
|
211
|
+
get :new
|
212
|
+
expect(@controller.resource_class).to eq(User)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "any action should respond to resource_name" do
|
216
|
+
get :new
|
217
|
+
expect(@controller.resource_name).to eq('users')
|
218
|
+
end
|
219
|
+
|
220
|
+
it "any action should respond to parent_class" do
|
221
|
+
get :new
|
222
|
+
expect(@controller.parent_class).to eq(NilClass)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should return a url on the resource" do
|
226
|
+
user = User.create! valid_attributes
|
227
|
+
response = get :show, {:id => user.to_param, murky: '2'}, valid_session
|
228
|
+
expect(@controller.resource_url).to eq "/users/#{user.id}?murky=2"
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should return a url on the resources" do
|
232
|
+
user = User.create! valid_attributes
|
233
|
+
get :index, {:id => user.to_param}, valid_session
|
234
|
+
expect(@controller.resources_url).to eq "/users"
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "abstracted"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
|
22
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
+
config.active_record.raise_in_transactional_callbacks = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: db/development.sqlite3
|
15
|
+
|
16
|
+
# Warning: The database defined as "test" will be erased and
|
17
|
+
# re-generated from your development database when you run "rake".
|
18
|
+
# Do not set this db to the same as development or production.
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
database: db/test.sqlite3
|
22
|
+
|
23
|
+
production:
|
24
|
+
<<: *default
|
25
|
+
database: db/production.sqlite3
|