lazy_crud 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +7 -0
- data/.gitignore +37 -0
- data/.travis.yml +15 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +142 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +1 -0
- data/config/locales/en.yml +11 -0
- data/lazy_crud.gemspec +42 -0
- data/lib/lazy_crud/version.rb +3 -0
- data/lib/lazy_crud.rb +161 -0
- data/spec/integration/discounts_controller_spec.rb +95 -0
- data/spec/rails_helper.rb +15 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/factories.rb +18 -0
- data/spec/support/factory_girl.rb +7 -0
- data/spec/support/rails_app/Rakefile +6 -0
- data/spec/support/rails_app/app/assets/images/.keep +0 -0
- data/spec/support/rails_app/app/assets/javascripts/application.js +16 -0
- data/spec/support/rails_app/app/assets/javascripts/some_resources.js +2 -0
- data/spec/support/rails_app/app/assets/javascripts/users.js +2 -0
- data/spec/support/rails_app/app/assets/stylesheets/application.css +15 -0
- data/spec/support/rails_app/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/support/rails_app/app/assets/stylesheets/some_resources.css +4 -0
- data/spec/support/rails_app/app/assets/stylesheets/users.css +4 -0
- data/spec/support/rails_app/app/controllers/application_controller.rb +14 -0
- data/spec/support/rails_app/app/controllers/discounts_controller.rb +14 -0
- data/spec/support/rails_app/app/controllers/events_controller.rb +58 -0
- data/spec/support/rails_app/app/controllers/users_controller.rb +6 -0
- data/spec/support/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/support/rails_app/app/helpers/events_helper.rb +2 -0
- data/spec/support/rails_app/app/helpers/users_helper.rb +2 -0
- data/spec/support/rails_app/app/models/collaboration.rb +16 -0
- data/spec/support/rails_app/app/models/concerns/.keep +0 -0
- data/spec/support/rails_app/app/models/discount.rb +5 -0
- data/spec/support/rails_app/app/models/event.rb +4 -0
- data/spec/support/rails_app/app/models/user.rb +9 -0
- data/spec/support/rails_app/app/views/discounts/edit.html.erb +0 -0
- data/spec/support/rails_app/app/views/discounts/index.html.erb +0 -0
- data/spec/support/rails_app/app/views/discounts/new.html.erb +0 -0
- data/spec/support/rails_app/app/views/discounts/show.html.erb +0 -0
- data/spec/support/rails_app/app/views/events/_form.html.erb +17 -0
- data/spec/support/rails_app/app/views/events/edit.html.erb +6 -0
- data/spec/support/rails_app/app/views/events/index.html.erb +25 -0
- data/spec/support/rails_app/app/views/events/new.html.erb +5 -0
- data/spec/support/rails_app/app/views/events/show.html.erb +4 -0
- data/spec/support/rails_app/app/views/layouts/application.html.erb +14 -0
- data/spec/support/rails_app/app/views/users/_form.html.erb +17 -0
- data/spec/support/rails_app/app/views/users/edit.html.erb +6 -0
- data/spec/support/rails_app/app/views/users/index.html.erb +25 -0
- data/spec/support/rails_app/app/views/users/new.html.erb +5 -0
- data/spec/support/rails_app/app/views/users/show.html.erb +4 -0
- data/spec/support/rails_app/bin/bundle +3 -0
- data/spec/support/rails_app/bin/rails +8 -0
- data/spec/support/rails_app/bin/rake +4 -0
- data/spec/support/rails_app/config/application.rb +30 -0
- data/spec/support/rails_app/config/boot.rb +3 -0
- data/spec/support/rails_app/config/database.yml +25 -0
- data/spec/support/rails_app/config/environment.rb +5 -0
- data/spec/support/rails_app/config/environments/development.rb +41 -0
- data/spec/support/rails_app/config/environments/production.rb +79 -0
- data/spec/support/rails_app/config/environments/test.rb +42 -0
- data/spec/support/rails_app/config/initializers/assets.rb +11 -0
- data/spec/support/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/rails_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/support/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/rails_app/config/initializers/inflections.rb +16 -0
- data/spec/support/rails_app/config/initializers/mime_types.rb +4 -0
- data/spec/support/rails_app/config/initializers/session_store.rb +3 -0
- data/spec/support/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/rails_app/config/locales/en.yml +23 -0
- data/spec/support/rails_app/config/routes.rb +67 -0
- data/spec/support/rails_app/config/secrets.yml +22 -0
- data/spec/support/rails_app/config.ru +0 -0
- data/spec/support/rails_app/db/development.sqlite3 +0 -0
- data/spec/support/rails_app/db/migrate/20141231134904_create_users.rb +8 -0
- data/spec/support/rails_app/db/migrate/20150102225507_create_events.rb +9 -0
- data/spec/support/rails_app/db/migrate/20150104171110_create_discounts.rb +13 -0
- data/spec/support/rails_app/db/schema.rb +38 -0
- data/spec/support/rails_app/db/seeds.rb +7 -0
- data/spec/support/rails_app/db/test.sqlite3 +0 -0
- data/spec/support/rails_app/public/404.html +67 -0
- data/spec/support/rails_app/public/422.html +67 -0
- data/spec/support/rails_app/public/500.html +66 -0
- data/spec/support/rails_app/public/favicon.ico +0 -0
- data/spec/support/rails_app/public/robots.txt +5 -0
- data/spec/support/rails_app/reset-db +1 -0
- data/spec/unit/lazy_crud_spec.rb +0 -0
- metadata +377 -0
File without changes
|
@@ -0,0 +1,16 @@
|
|
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 jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= 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
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
# Prevent CSRF attacks by raising an exception.
|
3
|
+
# For APIs, you may want to use :null_session instead.
|
4
|
+
protect_from_forgery with: :exception
|
5
|
+
|
6
|
+
# some fake helpers here
|
7
|
+
def current_user=(user = User.last)
|
8
|
+
@current_user = user
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_user
|
12
|
+
@current_user
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DiscountsController < ApplicationController
|
2
|
+
before_action :set_event
|
3
|
+
include LazyCrud
|
4
|
+
|
5
|
+
set_resource Discount
|
6
|
+
set_resource_parent Event
|
7
|
+
set_param_whitelist(:name, :amount)
|
8
|
+
|
9
|
+
|
10
|
+
def set_event
|
11
|
+
@event = Event.find(params[:event_id])
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class EventsController < ApplicationController
|
2
|
+
before_action :set_event, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /events
|
5
|
+
def index
|
6
|
+
@events = Event.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /events/1
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /events/new
|
14
|
+
def new
|
15
|
+
@event = Event.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /events/1/edit
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /events
|
23
|
+
def create
|
24
|
+
@event = Event.new(event_params)
|
25
|
+
|
26
|
+
if @event.save
|
27
|
+
redirect_to @event, notice: 'Event was successfully created.'
|
28
|
+
else
|
29
|
+
render :new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /events/1
|
34
|
+
def update
|
35
|
+
if @event.update(event_params)
|
36
|
+
redirect_to @event, notice: 'Event was successfully updated.'
|
37
|
+
else
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /events/1
|
43
|
+
def destroy
|
44
|
+
@event.destroy
|
45
|
+
redirect_to events_url, notice: 'Event was successfully destroyed.'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Use callbacks to share common setup or constraints between actions.
|
50
|
+
def set_event
|
51
|
+
@event = Event.find(params[:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def event_params
|
56
|
+
params[:event]
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Collaboration < ActiveRecord::Base
|
2
|
+
serialize :permissions, JSON
|
3
|
+
|
4
|
+
belongs_to :collaborated, polymorphic: true
|
5
|
+
belongs_to :user
|
6
|
+
|
7
|
+
after_initialize :update_permissions
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def update_permissions
|
12
|
+
# initialize
|
13
|
+
self.permissions ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= form_for(@event) do |f| %>
|
2
|
+
<% if @event.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @event.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="actions">
|
15
|
+
<%= f.submit %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1>Listing Events</h1>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th colspan="3"></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
|
12
|
+
<tbody>
|
13
|
+
<% @events.each do |event| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= link_to 'Show', event %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_event_path(event) %></td>
|
17
|
+
<td><%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
25
|
+
<%= link_to 'New Some resource', new_event_path %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>RailsApp</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>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= form_for(@user) do |f| %>
|
2
|
+
<% if @user.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @user.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="actions">
|
15
|
+
<%= f.submit %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<h1>Listing Users</h1>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th colspan="3"></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
|
12
|
+
<tbody>
|
13
|
+
<% @users.each do |user| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= link_to 'Show', user %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
17
|
+
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</tbody>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br>
|
24
|
+
|
25
|
+
<%= link_to 'New User', new_user_path %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
|
6
|
+
require 'lazy_crud'
|
7
|
+
require 'paranoia'
|
8
|
+
|
9
|
+
# Require the gems listed in Gemfile, including any gems
|
10
|
+
# you've limited to :test, :development, or :production.
|
11
|
+
Bundler.require(*Rails.groups)
|
12
|
+
|
13
|
+
module RailsApp
|
14
|
+
class Application < Rails::Application
|
15
|
+
# Settings in config/environments/* take precedence over those specified here.
|
16
|
+
# Application configuration should go into files in config/initializers
|
17
|
+
# -- all .rb files in that directory are automatically loaded.
|
18
|
+
|
19
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
20
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
21
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
22
|
+
|
23
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
24
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
25
|
+
# config.i18n.default_locale = :de
|
26
|
+
|
27
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
28
|
+
# config.active_record.raise_in_transactional_callbacks = true
|
29
|
+
end
|
30
|
+
end
|
@@ -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
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations.
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
|
30
|
+
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
31
|
+
# yet still be able to expire them through the digest params.
|
32
|
+
config.assets.digest = true
|
33
|
+
|
34
|
+
# Adds additional error checking when serving assets at runtime.
|
35
|
+
# Checks for improperly declared sprockets dependencies.
|
36
|
+
# Raises helpful error messages.
|
37
|
+
config.assets.raise_runtime_errors = true
|
38
|
+
|
39
|
+
# Raises error for missing translations
|
40
|
+
# config.action_view.raise_on_missing_translations = true
|
41
|
+
end
|