├── .github └── FUNDING.yml ├── .gitignore ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.md ├── Rakefile ├── app └── views │ └── mega_scaffold │ ├── _css.html.erb │ ├── _form.html.erb │ ├── edit.html.erb │ ├── index.html.erb │ ├── new.html.erb │ └── show.html.erb ├── bin └── test ├── docs ├── edit.png ├── index.png └── mega_scaffold.png ├── lib ├── mega_scaffold.rb └── mega_scaffold │ ├── code_generator.rb │ ├── controller.rb │ ├── engine.rb │ ├── fields_generator.rb │ ├── helpers.rb │ ├── klass_decorator.rb │ ├── routing.rb │ ├── type_detector.rb │ └── version.rb ├── mega_scaffold.gemspec ├── spec ├── controllers │ └── home_controller_spec.rb ├── helpers │ └── helpers_spec.rb ├── rails_helper.rb └── spec_helper.rb └── test ├── dummy ├── Rakefile ├── app │ ├── assets │ │ ├── config │ │ │ └── manifest.js │ │ ├── images │ │ │ └── .keep │ │ ├── javascripts │ │ │ └── application.js │ │ └── stylesheets │ │ │ └── application.scss │ ├── channels │ │ └── application_cable │ │ │ ├── channel.rb │ │ │ └── connection.rb │ ├── controllers │ │ ├── application_controller.rb │ │ ├── companies_controller.rb │ │ ├── concerns │ │ │ ├── .keep │ │ │ └── protected.rb │ │ └── home_controller.rb │ ├── helpers │ │ ├── application_helper.rb │ │ └── home_helper.rb │ ├── jobs │ │ └── application_job.rb │ ├── mailers │ │ └── application_mailer.rb │ ├── models │ │ ├── account.rb │ │ ├── application_record.rb │ │ ├── attachment.rb │ │ ├── category.rb │ │ ├── color.rb │ │ ├── company.rb │ │ ├── company_user.rb │ │ ├── concerns │ │ │ └── .keep │ │ ├── export_list.rb │ │ ├── photo.rb │ │ └── user.rb │ ├── uploaders │ │ ├── attachment_uploader.rb │ │ └── photo_uploader.rb │ └── views │ │ ├── companies │ │ ├── _company.html.erb │ │ ├── _form.html.erb │ │ ├── edit.html.erb │ │ ├── index.html.erb │ │ ├── new.html.erb │ │ └── show.html.erb │ │ ├── home │ │ └── index.html.erb │ │ └── layouts │ │ ├── application.html.erb │ │ ├── mailer.html.erb │ │ └── mailer.text.erb ├── bin │ ├── rails │ ├── rake │ └── setup ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── cable.yml │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── content_security_policy.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ └── permissions_policy.rb │ ├── locales │ │ └── en.yml │ ├── puma.rb │ ├── routes.rb │ └── storage.yml ├── db │ ├── migrate │ │ ├── 20220502094418_create_users.rb │ │ ├── 20220502124520_create_accounts.rb │ │ ├── 20220502155108_create_categories.rb │ │ ├── 20220502185843_add_habtm.rb │ │ ├── 20220502195803_create_photos.rb │ │ ├── 20220502201418_create_companies.rb │ │ ├── 20220502201501_create_attachments.rb │ │ ├── 20220503184142_add_more_fields_to_user.rb │ │ ├── 20220503185215_add_more_fields_to_user2.rb │ │ ├── 20220503191207_create_colors.rb │ │ ├── 20220504065200_add_r_ole_to_user.rb │ │ ├── 20220504065350_create_company_users.rb │ │ ├── 20220504065821_add_role_to_account_too.rb │ │ ├── 20220504073418_add_pritority_to_account.rb │ │ ├── 20220504192931_add_email_to_company.rb │ │ └── 20220509173200_create_export_lists.rb │ └── schema.rb ├── lib │ └── assets │ │ └── .keep ├── log │ └── .keep └── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ ├── apple-touch-icon-precomposed.png │ ├── apple-touch-icon.png │ └── favicon.ico ├── mega_scaffold_test.rb └── test_helper.rb /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: igorkasyanchuk 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /doc/ 3 | /log/*.log 4 | /pkg/ 5 | /tmp/ 6 | /test/dummy/db/*.sqlite3 7 | /test/dummy/db/*.sqlite3-* 8 | /test/dummy/log/*.log 9 | /test/dummy/storage/ 10 | /test/dummy/tmp/ 11 | 12 | *.gem 13 | 14 | /test/dummu/pubic/uploads 15 | test/dummy/public/uploads/ 16 | 17 | coverage/ -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | gemspec 5 | 6 | gem "sqlite3" 7 | 8 | gem 'puma' 9 | gem 'pry' 10 | gem 'sprockets-rails' 11 | gem 'sassc' 12 | gem 'kaminari' 13 | gem 'carrierwave' 14 | gem 'wrapped_print' 15 | gem 'wrapped_print' 16 | gem 'ppp-util' -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | mega_scaffold (0.1.1) 5 | rails 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | actioncable (7.0.2.4) 11 | actionpack (= 7.0.2.4) 12 | activesupport (= 7.0.2.4) 13 | nio4r (~> 2.0) 14 | websocket-driver (>= 0.6.1) 15 | actionmailbox (7.0.2.4) 16 | actionpack (= 7.0.2.4) 17 | activejob (= 7.0.2.4) 18 | activerecord (= 7.0.2.4) 19 | activestorage (= 7.0.2.4) 20 | activesupport (= 7.0.2.4) 21 | mail (>= 2.7.1) 22 | net-imap 23 | net-pop 24 | net-smtp 25 | actionmailer (7.0.2.4) 26 | actionpack (= 7.0.2.4) 27 | actionview (= 7.0.2.4) 28 | activejob (= 7.0.2.4) 29 | activesupport (= 7.0.2.4) 30 | mail (~> 2.5, >= 2.5.4) 31 | net-imap 32 | net-pop 33 | net-smtp 34 | rails-dom-testing (~> 2.0) 35 | actionpack (7.0.2.4) 36 | actionview (= 7.0.2.4) 37 | activesupport (= 7.0.2.4) 38 | rack (~> 2.0, >= 2.2.0) 39 | rack-test (>= 0.6.3) 40 | rails-dom-testing (~> 2.0) 41 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 42 | actiontext (7.0.2.4) 43 | actionpack (= 7.0.2.4) 44 | activerecord (= 7.0.2.4) 45 | activestorage (= 7.0.2.4) 46 | activesupport (= 7.0.2.4) 47 | globalid (>= 0.6.0) 48 | nokogiri (>= 1.8.5) 49 | actionview (7.0.2.4) 50 | activesupport (= 7.0.2.4) 51 | builder (~> 3.1) 52 | erubi (~> 1.4) 53 | rails-dom-testing (~> 2.0) 54 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 55 | activejob (7.0.2.4) 56 | activesupport (= 7.0.2.4) 57 | globalid (>= 0.3.6) 58 | activemodel (7.0.2.4) 59 | activesupport (= 7.0.2.4) 60 | activerecord (7.0.2.4) 61 | activemodel (= 7.0.2.4) 62 | activesupport (= 7.0.2.4) 63 | activestorage (7.0.2.4) 64 | actionpack (= 7.0.2.4) 65 | activejob (= 7.0.2.4) 66 | activerecord (= 7.0.2.4) 67 | activesupport (= 7.0.2.4) 68 | marcel (~> 1.0) 69 | mini_mime (>= 1.1.0) 70 | activesupport (7.0.2.4) 71 | concurrent-ruby (~> 1.0, >= 1.0.2) 72 | i18n (>= 1.6, < 2) 73 | minitest (>= 5.1) 74 | tzinfo (~> 2.0) 75 | addressable (2.8.0) 76 | public_suffix (>= 2.0.2, < 5.0) 77 | builder (3.2.4) 78 | carrierwave (2.2.2) 79 | activemodel (>= 5.0.0) 80 | activesupport (>= 5.0.0) 81 | addressable (~> 2.6) 82 | image_processing (~> 1.1) 83 | marcel (~> 1.0.0) 84 | mini_mime (>= 0.1.3) 85 | ssrf_filter (~> 1.0) 86 | coderay (1.1.3) 87 | concurrent-ruby (1.1.10) 88 | crass (1.0.6) 89 | diff-lcs (1.5.0) 90 | digest (3.1.0) 91 | docile (1.4.0) 92 | erubi (1.10.0) 93 | faker (2.20.0) 94 | i18n (>= 1.8.11, < 2) 95 | ffi (1.15.5) 96 | globalid (1.0.0) 97 | activesupport (>= 5.0) 98 | i18n (1.10.0) 99 | concurrent-ruby (~> 1.0) 100 | image_processing (1.12.2) 101 | mini_magick (>= 4.9.5, < 5) 102 | ruby-vips (>= 2.0.17, < 3) 103 | kaminari (1.2.2) 104 | activesupport (>= 4.1.0) 105 | kaminari-actionview (= 1.2.2) 106 | kaminari-activerecord (= 1.2.2) 107 | kaminari-core (= 1.2.2) 108 | kaminari-actionview (1.2.2) 109 | actionview 110 | kaminari-core (= 1.2.2) 111 | kaminari-activerecord (1.2.2) 112 | activerecord 113 | kaminari-core (= 1.2.2) 114 | kaminari-core (1.2.2) 115 | loofah (2.17.0) 116 | crass (~> 1.0.2) 117 | nokogiri (>= 1.5.9) 118 | mail (2.7.1) 119 | mini_mime (>= 0.1.1) 120 | marcel (1.0.2) 121 | method_source (1.0.0) 122 | mini_magick (4.11.0) 123 | mini_mime (1.1.2) 124 | minitest (5.15.0) 125 | net-imap (0.2.3) 126 | digest 127 | net-protocol 128 | strscan 129 | net-pop (0.1.1) 130 | digest 131 | net-protocol 132 | timeout 133 | net-protocol (0.1.3) 134 | timeout 135 | net-smtp (0.3.1) 136 | digest 137 | net-protocol 138 | timeout 139 | nio4r (2.5.8) 140 | nokogiri (1.13.4-x86_64-darwin) 141 | racc (~> 1.4) 142 | ppp-util (0.1.0) 143 | pry (0.14.1) 144 | coderay (~> 1.1) 145 | method_source (~> 1.0) 146 | public_suffix (4.0.7) 147 | puma (5.6.4) 148 | nio4r (~> 2.0) 149 | racc (1.6.0) 150 | rack (2.2.3) 151 | rack-test (1.1.0) 152 | rack (>= 1.0, < 3) 153 | rails (7.0.2.4) 154 | actioncable (= 7.0.2.4) 155 | actionmailbox (= 7.0.2.4) 156 | actionmailer (= 7.0.2.4) 157 | actionpack (= 7.0.2.4) 158 | actiontext (= 7.0.2.4) 159 | actionview (= 7.0.2.4) 160 | activejob (= 7.0.2.4) 161 | activemodel (= 7.0.2.4) 162 | activerecord (= 7.0.2.4) 163 | activestorage (= 7.0.2.4) 164 | activesupport (= 7.0.2.4) 165 | bundler (>= 1.15.0) 166 | railties (= 7.0.2.4) 167 | rails-dom-testing (2.0.3) 168 | activesupport (>= 4.2.0) 169 | nokogiri (>= 1.6) 170 | rails-html-sanitizer (1.4.2) 171 | loofah (~> 2.3) 172 | railties (7.0.2.4) 173 | actionpack (= 7.0.2.4) 174 | activesupport (= 7.0.2.4) 175 | method_source 176 | rake (>= 12.2) 177 | thor (~> 1.0) 178 | zeitwerk (~> 2.5) 179 | rake (13.0.6) 180 | rspec-core (3.11.0) 181 | rspec-support (~> 3.11.0) 182 | rspec-expectations (3.11.0) 183 | diff-lcs (>= 1.2.0, < 2.0) 184 | rspec-support (~> 3.11.0) 185 | rspec-mocks (3.11.1) 186 | diff-lcs (>= 1.2.0, < 2.0) 187 | rspec-support (~> 3.11.0) 188 | rspec-rails (5.1.1) 189 | actionpack (>= 5.2) 190 | activesupport (>= 5.2) 191 | railties (>= 5.2) 192 | rspec-core (~> 3.10) 193 | rspec-expectations (~> 3.10) 194 | rspec-mocks (~> 3.10) 195 | rspec-support (~> 3.10) 196 | rspec-support (3.11.0) 197 | ruby-vips (2.1.4) 198 | ffi (~> 1.12) 199 | sassc (2.4.0) 200 | ffi (~> 1.9) 201 | simplecov (0.21.2) 202 | docile (~> 1.1) 203 | simplecov-html (~> 0.11) 204 | simplecov_json_formatter (~> 0.1) 205 | simplecov-html (0.12.3) 206 | simplecov_json_formatter (0.1.4) 207 | sprockets (4.0.3) 208 | concurrent-ruby (~> 1.0) 209 | rack (> 1, < 3) 210 | sprockets-rails (3.4.2) 211 | actionpack (>= 5.2) 212 | activesupport (>= 5.2) 213 | sprockets (>= 3.0.0) 214 | sqlite3 (1.4.2) 215 | ssrf_filter (1.0.7) 216 | strscan (3.0.2) 217 | thor (1.2.1) 218 | timeout (0.2.0) 219 | tzinfo (2.0.4) 220 | concurrent-ruby (~> 1.0) 221 | websocket-driver (0.7.5) 222 | websocket-extensions (>= 0.1.0) 223 | websocket-extensions (0.1.5) 224 | wrapped_print (0.1.0) 225 | activesupport 226 | zeitwerk (2.5.4) 227 | 228 | PLATFORMS 229 | x86_64-darwin-21 230 | 231 | DEPENDENCIES 232 | carrierwave 233 | faker 234 | kaminari 235 | mega_scaffold! 236 | ppp-util 237 | pry 238 | puma 239 | rspec-rails 240 | sassc 241 | simplecov 242 | sprockets-rails 243 | sqlite3 244 | wrapped_print 245 | 246 | BUNDLED WITH 247 | 2.3.7 248 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mega_scaffold 2 | 3 | [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com) 4 | 5 | [!["Buy Me A Coffee"](https://github.com/igorkasyanchuk/get-smart/blob/main/docs/snapshot-bmc-button-small.png?raw=true)](https://buymeacoffee.com/igorkasyanchuk) 6 | 7 | This is the FASTEST way how to add CRUD functionality for your models. Literally by just adding ONE LINE of code in `routes.rb`. 8 | 9 | With additional customization options it allows you to build quickly admin panels or simple controllers to output data. 10 | 11 | It works with existing models so all your validations, associations, etc will work as usual. 12 | 13 | ![rails scaffold generator](docs/mega_scaffold.png) 14 | 15 | ## Usage 16 | 17 | 1) add gem to Gemfile `gem "mega_scaffold"` 18 | 19 | 2) open `routes.rb` 20 | 21 | 3) add `mega_scaffold :categories` (if you have `Category` model) 22 | 23 | 24 | ## Customization 25 | 26 | - configure layout 27 | - specify how to fetch records 28 | - specify type for input 29 | - configure to work with associations 30 | - access helpers to output value 31 | - hide columns 32 | - change labels 33 | - specify which fields where to show 34 | - provide additional options for form fields 35 | 36 | How CRUD looks - simple but created in 2 minutes: 37 | 38 | ![rails scaffold generator](docs/index.png) 39 | ![rails scaffold generator](docs/edit.png) 40 | 41 | If you need examples of customization (see `test/dummy` as an example): 42 | 43 | ```ruby 44 | # routes.rb 45 | 46 | Rails.application.routes.draw do 47 | 48 | # could be nested in existing resources 49 | resources :companies do 50 | mega_scaffold :attachments, 51 | parent: -> (controller) { Company.find(controller.params[:company_id]) }, 52 | collection: -> (controller) { controller.parent.attachments }, 53 | fields: [ 54 | { name: :id, view: :index }, 55 | { name: :file, type: :file_field, view: :all, value: -> (record, view) { view.link_to 'Download', record.file.url } }, 56 | { name: :created_at, view: :index }, 57 | ] 58 | end 59 | 60 | # could be added to namespaces 61 | namespace :secret do 62 | namespace :admin do 63 | mega_scaffold :categories, fields: [ 64 | { name: :id, view: :index }, 65 | { name: :name, view: :all, value: -> (record, _) { record.name&.upcase } }, 66 | { name: :accounts, view: [:index, :show], value: -> (record, _) { record.accounts.count } }, 67 | { name: :created_at, view: [:index, :show], value: -> (record, _) { I18n.l record.created_at, format: :short } }, 68 | ] 69 | end 70 | end 71 | 72 | # simple usage, you can specify concerns with "before_action" or other contoller-related logic 73 | mega_scaffold :users, 74 | collection: -> (_) { User.ordered }, 75 | concerns: [Protected], 76 | layout: 'admin', 77 | only: [:id, :name, :age, :dob, :country, :created_at, :phone] 78 | 79 | # usage with file upload and showing images in the index and show views 80 | mega_scaffold :photos, 81 | fields: [ 82 | { name: :user, column: :user_id, view: :all, type: :select, collection: -> { User.by_name.map{|e| [e.name, e.id]} }, value: -> (record, view) { view.link_to_if record.user, record.user&.name, record.user } }, 83 | { name: :photo, type: :file_field, view: :all, value: -> (record, view) { view.image_tag record.photo.url, style: 'width: 200px' } }, 84 | { name: :created_at, view: :index, value: -> (record, view) { view.l record.created_at, format: :long } }, 85 | ] 86 | 87 | # access to different set of records (for example admin can see all records and all other users only own) + form with associations 88 | mega_scaffold :accounts, 89 | collection: -> (controller) { controller.admin? ? Account.all : current_user.accounts }, 90 | fields: [ 91 | { name: :id, view: [:show] }, 92 | { name: :name, type: :text_field, view: :all, value: -> (record, view) { view.link_to record.name.to_s.upcase, record } }, 93 | { 94 | view: :all, 95 | name: :account_type, 96 | type: :collection_select, 97 | collection: -> { Account::TYPES }, 98 | options: [:to_s, :to_s, include_blank: true] 99 | }, 100 | { 101 | view: :all, 102 | name: :priority, 103 | type: :range_field, 104 | options: { min: 0, max: 100, step: 10 } 105 | }, 106 | { 107 | name: :categories, 108 | column: { 109 | name: :category_ids, 110 | permit: [], 111 | }, 112 | type: :collection_check_boxes, 113 | options: [:id, :name], 114 | view: :form, 115 | collection: -> { Category.by_name }, 116 | value: { 117 | index: -> (record, _) { record.categories.count }, 118 | show: -> (record, _) { record.categories.pluck(:name).join(", ") } 119 | } 120 | }, 121 | { name: 'VIRTUAL ATTR', type: :virtual, view: :index, value: -> (record, view) { "ID: #{record.id}" } }, 122 | { 123 | name: :owner_id, 124 | label: "Owner", 125 | view: :all, 126 | options: { include_blank: true }, 127 | type: :select, 128 | collection: -> { User.by_name.map{|e| [e.name, e.id]} }, 129 | value: -> (record, _) { record.owner&.name } 130 | }, 131 | { name: :created_at, view: [:index, :show], value: -> (record, _) { I18n.l(record.created_at, format: :long) } }, 132 | ] 133 | end 134 | ``` 135 | 136 | ## TODO Ideas 137 | 138 | - config for actions 139 | - more specs 140 | - simple search using ransack? 141 | - how to overide view instructions 142 | - check if all is ok with turbo/turbolinks 143 | - export to CSV, JSON? 144 | - integration with pundit or cancancan? 145 | - support for "resource" type 146 | - work with I18n to translate labels? 147 | - how to customize views 148 | - view customization per controller 149 | - refactor how controller is generated on the fly (combine into one file) 150 | 151 | ## Contributing 152 | 153 | You are welcome to contribute. 154 | 155 | ## License 156 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 157 | 158 | 159 | [](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=mega_scaffold) 161 | 162 | [!["Buy Me A Coffee"](https://github.com/igorkasyanchuk/get-smart/blob/main/docs/snapshot-bmc-button.png?raw=true)](https://buymeacoffee.com/igorkasyanchuk) 163 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | 3 | require "bundler/gem_tasks" 4 | -------------------------------------------------------------------------------- /app/views/mega_scaffold/_css.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/views/mega_scaffold/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for record, url: url_for(action: record.persisted? ? :update : :create, mega_scaffold.pk => record.send(mega_scaffold.pk)) , data: { turbo: false, turbolinks: false } do |f| %> 2 | <% if record.errors.any? %> 3 |
4 |

<%= pluralize(record.errors.count, "error") %> prohibited this record from being saved:

5 | 10 |
11 | <% end %> 12 | 13 | <% mega_scaffold.form.each do |e| %> 14 | <% type = e[:type].presence || :text_field %> 15 | <% field = e[:column].presence || e[:name] %> 16 | <% field = field.is_a?(Hash) ? field[:name] : field %> 17 | <% label = mega_scaffold_field_name(e) %> 18 | <% options = e[:options].presence || {} rescue {} %> 19 | 20 | <%# default %> 21 | <% options.merge!({ rows: 4, cols: 60 }) if type == :text_area %> 22 | 23 |
24 | <% if type.to_s =~ /collection/ %> 25 | 26 |
27 | <%= f.send type, field, e[:collection].call, *options %> 28 |
29 | 30 | <% elsif type == :select %> 31 | 37 | 38 | 39 | <% elsif type == :check_box %> 40 | 44 | 45 | 46 | <% else %> 47 | 53 | <% end %> 54 |
55 | 56 | <% end %> 57 | 58 |
59 |
60 | 61 | <%= f.submit %> 62 | — 63 | <%= link_to 'Back', { action: :index } %> 64 | <% end %> -------------------------------------------------------------------------------- /app/views/mega_scaffold/edit.html.erb: -------------------------------------------------------------------------------- 1 | <%= render 'mega_scaffold/css' %> 2 | 3 |
4 |

Edit <%= mega_scaffold.model %>

5 | 6 | <%= render 'mega_scaffold/form', record: @record %> 7 |
-------------------------------------------------------------------------------- /app/views/mega_scaffold/index.html.erb: -------------------------------------------------------------------------------- 1 | <%= render 'mega_scaffold/css' %> 2 | 3 |
4 |
5 |

<%= mega_scaffold.model.to_s.pluralize %>

6 |
7 | <%= link_to 'New', { action: :new }, { class: 'button btn btn-primary' } %> 8 | <% if @parent %> 9 | — 10 | <%= link_to 'Back', mega_scaffold_parent_url %> 11 | <% end %> 12 |
13 |
14 | 15 | 16 | 17 | 18 | <% mega_scaffold.columns.each do |field| %> 19 | 20 | <% end %> 21 | 22 | 23 | 24 | 25 | 26 | <% if @records.present? %> 27 | <% @records.each do |record| %> 28 | 29 | <% mega_scaffold.columns.each do |field| %> 30 | 33 | <% end %> 34 | 35 | 36 | 37 | 38 | <% end %> 39 | <% else %> 40 | 41 | 44 | 45 | <% end %> 46 | 47 | 48 |
<%= mega_scaffold_field_name field %>
31 | <%= mega_scaffold_value record, field, :index %> 32 | <%= link_to 'show', { action: :show, mega_scaffold.pk => record.send(mega_scaffold.pk) } %><%= link_to 'edit', { action: :edit, mega_scaffold.pk => record.send(mega_scaffold.pk) } %><%= link_to 'delete', { action: :show, mega_scaffold.pk => record.send(mega_scaffold.pk) }, data: { method: :delete, turbo: false, turbolinks: false, confirm: "Are you sure?" } %>
42 | No Records. 43 |
49 | 50 | <% if respond_to?(:paginate) %> 51 | <%= paginate @records %> 52 | <% elsif respond_to?(:will_paginate) %> 53 | <%= will_paginate @records %> 54 | <% end %> 55 |
-------------------------------------------------------------------------------- /app/views/mega_scaffold/new.html.erb: -------------------------------------------------------------------------------- 1 | <%= render 'mega_scaffold/css' %> 2 | 3 |
4 |

New <%= mega_scaffold.model %>

5 | 6 | <%= render 'mega_scaffold/form', record: @record %> 7 |
-------------------------------------------------------------------------------- /app/views/mega_scaffold/show.html.erb: -------------------------------------------------------------------------------- 1 | <%= render 'mega_scaffold/css' %> 2 | 3 |
4 |

<%= mega_scaffold.model %>

5 | 6 |
7 | <% mega_scaffold.show.each do |field| %> 8 |
<%= mega_scaffold_field_name field %>:
9 |
10 | <%= mega_scaffold_value @record, field %> 11 |
12 | <% end %> 13 |
14 | 15 | <%= link_to 'Edit', { action: :edit, mega_scaffold.pk => @record.send(mega_scaffold.pk) }, { class: 'button' } %> 16 | - 17 | <%= link_to 'Back', { action: :index }, { class: 'button' } %> 18 |
-------------------------------------------------------------------------------- /bin/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $: << File.expand_path("../test", __dir__) 3 | 4 | require "bundler/setup" 5 | require "rails/plugin/test" 6 | -------------------------------------------------------------------------------- /docs/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/docs/edit.png -------------------------------------------------------------------------------- /docs/index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/docs/index.png -------------------------------------------------------------------------------- /docs/mega_scaffold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/docs/mega_scaffold.png -------------------------------------------------------------------------------- /lib/mega_scaffold.rb: -------------------------------------------------------------------------------- 1 | require "mega_scaffold/version" 2 | require "mega_scaffold/helpers" 3 | require "mega_scaffold/controller" 4 | require "mega_scaffold/fields_generator" 5 | require "mega_scaffold/code_generator" 6 | require "mega_scaffold/klass_decorator" 7 | require "mega_scaffold/type_detector" 8 | require "mega_scaffold/routing" 9 | require "mega_scaffold/engine" 10 | 11 | module MegaScaffold 12 | end 13 | -------------------------------------------------------------------------------- /lib/mega_scaffold/code_generator.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | class CodeGenerator 3 | attr_reader :options 4 | 5 | def initialize(options) 6 | @options = options 7 | end 8 | 9 | def generate 10 | strs = [] 11 | options[:namespaces].each_with_index do |e, index| 12 | strs << "#{' ' * index}module #{index == 0 ? '::' + e : e}" 13 | end 14 | 15 | strs << %Q{ 16 | class #{'::' if options[:namespaces].empty?}#{options[:model].to_s.pluralize}Controller < ::ApplicationController 17 | include MegaScaffold::Controller 18 | include Helpers 19 | 20 | #{"include " + options[:concerns].join(", ") if options[:concerns].any?} 21 | 22 | helper :all 23 | 24 | def parent 25 | mega_scaffold.parent.call(self) if mega_scaffold.parent.is_a?(Proc) 26 | end 27 | 28 | def collection 29 | mega_scaffold.collection.call(self) 30 | end 31 | 32 | def resource 33 | collection.find(params[:id]) 34 | end 35 | 36 | def find_parent 37 | @parent = parent 38 | end 39 | 40 | private 41 | def mega_scaffold 42 | @mega_scaffold ||= OpenStruct.new({ 43 | scope: #{options[:scope][:as].to_s.to_json}, 44 | model: #{options[:model]}, 45 | pk: :#{options[:model].primary_key}, 46 | fields: self.class.fields_config, 47 | columns: self.class.columns_config, 48 | form: self.class.form_config, 49 | show: self.class.show_config, 50 | collection: self.class.collection_config, 51 | parent: self.class.parent_config, 52 | }) 53 | end 54 | 55 | def detect_layout 56 | "#{options[:layout].presence || 'application'}" 57 | end 58 | end 59 | } 60 | 61 | options[:namespaces].each_with_index do |e, index| 62 | strs << "#{' ' * (options[:namespaces].size - index - 1)}end" 63 | end 64 | 65 | klass_name = "#{options[:namespaces].any? ? options[:namespaces].join("::") + "::" : '::'}#{options[:model].to_s.pluralize}Controller" 66 | strs << klass_name 67 | 68 | # delete old constant 69 | # because it has conficts with same which was previosly initialized 70 | # happend after changing routes.rb in dev mode 71 | object_space = options[:namespaces].join("::").constantize rescue Object 72 | object_space.send(:remove_const, :"#{options[:model].to_s.pluralize}Controller") rescue '=' 73 | 74 | strs.join("\n") 75 | end 76 | end 77 | end -------------------------------------------------------------------------------- /lib/mega_scaffold/controller.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | module Controller 3 | extend ActiveSupport::Concern 4 | 5 | included do 6 | prepend_view_path("#{MegaScaffold::Engine.root}/app/views") 7 | before_action :find_parent 8 | layout :detect_layout 9 | helper_method :mega_scaffold 10 | end 11 | 12 | def index 13 | @records = if defined?(Kaminari) 14 | collection.page(params[:page]) 15 | elsif defined?(WillPaginate) 16 | collection.paginate(params[:page]) 17 | else 18 | collection 19 | end 20 | render template: 'mega_scaffold/index' 21 | end 22 | 23 | def show 24 | @record = resource 25 | render template: 'mega_scaffold/show' 26 | end 27 | 28 | def new 29 | @record = collection.new 30 | render template: 'mega_scaffold/new' 31 | end 32 | 33 | def create 34 | @record = collection.build(record_params) 35 | if @record.save 36 | flash[:notice] = "#{mega_scaffold.model} successfully created" 37 | redirect_to url_for({ action: :show, mega_scaffold.pk => @record.send(mega_scaffold.pk) }) 38 | else 39 | render template: 'mega_scaffold/new', status: :unprocessable_entity 40 | end 41 | end 42 | 43 | def edit 44 | @record = resource 45 | render template: 'mega_scaffold/edit' 46 | end 47 | 48 | def update 49 | @record = resource 50 | if @record.update(record_params) 51 | flash[:notice] = "#{mega_scaffold.model} successfully updated" 52 | redirect_to url_for({ action: :show, mega_scaffold.pk => @record.send(mega_scaffold.pk) }) 53 | else 54 | render template: 'mega_scaffold/edit', status: :unprocessable_entity 55 | end 56 | end 57 | 58 | def destroy 59 | @record = resource 60 | @record.destroy 61 | flash[:notice] = "#{mega_scaffold.model} successfully deleted" 62 | redirect_to action: :index 63 | end 64 | 65 | private 66 | 67 | def mega_scaffold_permits 68 | mega_scaffold.fields.map do |ee| 69 | next if ee[:type] == :virtual 70 | result = ee[:column].presence || ee[:name] 71 | if result.is_a?(Hash) 72 | if result[:permit] 73 | { result[:name] => result[:permit] } 74 | else 75 | result[:name] 76 | end 77 | else 78 | result 79 | end 80 | end.compact 81 | end 82 | 83 | def record_params 84 | params.require(mega_scaffold.model.to_s.underscore).permit(mega_scaffold_permits) 85 | end 86 | 87 | end 88 | end -------------------------------------------------------------------------------- /lib/mega_scaffold/engine.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | class Engine < ::Rails::Engine 3 | isolate_namespace MegaScaffold 4 | 5 | initializer 'mega_scaffold.helpers', before: :load_config_initializers do 6 | ActiveSupport.on_load :action_view do 7 | include MegaScaffold::Helpers 8 | end 9 | end 10 | 11 | ActionDispatch::Routing::Mapper.send :include, MegaScaffold::Routing 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/mega_scaffold/fields_generator.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | class FieldsGenerator 3 | attr_reader :model 4 | 5 | def initialize(model) 6 | @model = model 7 | end 8 | 9 | def generate 10 | model.columns.map do |e| 11 | { 12 | name: e.name, 13 | type: MegaScaffold::TypeDetector.find_type(e), 14 | } 15 | end 16 | end 17 | end 18 | end -------------------------------------------------------------------------------- /lib/mega_scaffold/helpers.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | module Helpers 3 | 4 | def mega_scaffold_value(record, field, type = :show) 5 | if field[:value].is_a?(Proc) 6 | field[:value].call record, self 7 | elsif field[:value].is_a?(Hash) 8 | field[:value][type].call record, self 9 | else 10 | record.send(field[:name]) 11 | end 12 | end 13 | 14 | def mega_scaffold_field_name(field) 15 | (field[:label].presence || field[:name]).to_s.titleize 16 | end 17 | 18 | def mega_scaffold_parent_url 19 | [mega_scaffold.scope&.to_sym, @parent].reject(&:blank?) 20 | end 21 | 22 | end 23 | end -------------------------------------------------------------------------------- /lib/mega_scaffold/klass_decorator.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | class KlassDecorator 3 | attr_reader :klass, :options 4 | 5 | def initialize(klass, options) 6 | @klass = klass 7 | @options = options 8 | end 9 | 10 | def decorate 11 | # hack to have local variable available for define_method 12 | local = options 13 | 14 | klass.singleton_class.define_method :rules do 15 | { 16 | except: (Array.wrap(local[:except]) + Array.wrap(local[:ignore])).map(&:to_sym), 17 | only: (Array.wrap(local[:only]) - Array.wrap(local[:ignore])).map(&:to_sym), 18 | } 19 | end 20 | 21 | klass.singleton_class.define_method :fields_config do 22 | local[:fields].map do |e| 23 | e.merge({view: Array.wrap(e[:view]).map(&:to_sym)}).deep_symbolize_keys 24 | end 25 | end 26 | 27 | klass.singleton_class.define_method :columns_config do 28 | fields_config.select do |e| 29 | next true if e[:view].empty? 30 | next true if e[:view].include?(:index) || e[:view].include?(:all) 31 | 32 | false 33 | end 34 | end 35 | 36 | klass.singleton_class.define_method :form_config do 37 | fields_config.select do |e| 38 | next false if rules[:except].any? && rules[:except].include?(e[:name].to_sym) 39 | next false if rules[:only].any? && !rules[:only].include?(e[:name].to_sym) 40 | 41 | next true if e[:view].empty? 42 | next true if e[:view].include?(:form) || e[:view].include?(:all) 43 | false 44 | end 45 | end 46 | 47 | klass.singleton_class.define_method :show_config do 48 | fields_config.select do |e| 49 | next true if e[:view].empty? 50 | next true if e[:view].include?(:show) || e[:view].include?(:all) 51 | 52 | false 53 | end 54 | end 55 | 56 | klass.singleton_class.define_method :collection_config do 57 | if local[:collection].is_a?(Proc) 58 | local[:collection] 59 | else 60 | -> (controller) { local[:model].all } 61 | end 62 | end 63 | 64 | klass.singleton_class.define_method :parent_config do 65 | local[:parent] 66 | end 67 | end 68 | end 69 | end -------------------------------------------------------------------------------- /lib/mega_scaffold/routing.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | module Routing 3 | 4 | def mega_scaffold(*options, 5 | fields: nil, 6 | ignore: [:id, :created_at, :updated_at], 7 | except: [], 8 | only: [], 9 | collection: nil, 10 | parent: nil, 11 | concerns: nil, 12 | layout: "application" 13 | ) 14 | 15 | model_name = options[0].to_s.singularize # user 16 | model = model_name.classify.safe_constantize # User 17 | concerns = Array.wrap(concerns) 18 | return unless model 19 | 20 | fields = MegaScaffold::FieldsGenerator.new(model).generate if fields.blank? 21 | generator = MegaScaffold::CodeGenerator.new({ 22 | namespaces: @scope[:module].to_s.split("/").map{|e| e.classify}, 23 | concerns: concerns, 24 | model: model, 25 | scope: @scope, 26 | layout: layout 27 | }) 28 | 29 | klass = eval(generator.generate) 30 | 31 | MegaScaffold::KlassDecorator.new(klass, { 32 | fields: fields, 33 | collection: collection, 34 | parent: parent, 35 | model: model, 36 | except: except, 37 | only: only, 38 | ignore: ignore 39 | }).decorate 40 | 41 | resources *options 42 | rescue ActiveRecord::StatementInvalid => ex 43 | puts ex.message 44 | end 45 | 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/mega_scaffold/type_detector.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | class TypeDetector 3 | def TypeDetector.find_type(field) 4 | case field.type 5 | when :datetime 6 | :datetime_field 7 | when :date 8 | :date_field 9 | when :text 10 | :text_area 11 | when :boolean 12 | :check_box 13 | when :integer 14 | :number_field 15 | else 16 | case field.name 17 | when /password/ 18 | :password_field 19 | when /phone/ 20 | :phone_field 21 | when /email/ 22 | :email_field 23 | when /color/ 24 | :color_field 25 | when /url/ 26 | :url_field 27 | else 28 | :text_field 29 | end 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/mega_scaffold/version.rb: -------------------------------------------------------------------------------- 1 | module MegaScaffold 2 | VERSION = "0.1.1" 3 | end 4 | -------------------------------------------------------------------------------- /mega_scaffold.gemspec: -------------------------------------------------------------------------------- 1 | require_relative "lib/mega_scaffold/version" 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = "mega_scaffold" 5 | spec.version = MegaScaffold::VERSION 6 | spec.authors = ["Igor Kasyanchuk", "Liubomyr Manastyretskyi"] 7 | spec.email = ["igorkasyanchuk@gmail.com", "manastyretskyi@gmail.com"] 8 | spec.homepage = "https://github.com/railsjazz/mega_scaffold" 9 | spec.summary = "Fastest way to add CRUD functionality to your models." 10 | spec.description = "Fastest way to add CRUD functionality to your Rails models. No jQuery or other frontend dependencies." 11 | spec.license = "MIT" 12 | 13 | spec.metadata["homepage_uri"] = 'https://www.railsjazz.com/' 14 | spec.metadata["source_code_uri"] = "https://github.com/railsjazz/mega_scaffold" 15 | 16 | spec.files = Dir.chdir(File.expand_path(__dir__)) do 17 | Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] 18 | end 19 | 20 | spec.add_dependency "rails" 21 | 22 | spec.add_development_dependency "puma" 23 | spec.add_development_dependency "pry" 24 | spec.add_development_dependency "sprockets-rails" 25 | spec.add_development_dependency "sassc" 26 | spec.add_development_dependency "kaminari" 27 | spec.add_development_dependency "faker" 28 | spec.add_development_dependency "carrierwave" 29 | spec.add_development_dependency "rspec-rails" 30 | spec.add_development_dependency "simplecov" 31 | spec.add_development_dependency "wrapped_print" 32 | spec.add_development_dependency "ppp-util" 33 | end 34 | -------------------------------------------------------------------------------- /spec/controllers/home_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../rails_helper" 2 | 3 | describe "Pages", type: :request do 4 | before do 5 | @user = User.create!(name: "john") 6 | @account = Account.create!(name: "soft", owner: @user) 7 | @company = Company.create!(name: "company") 8 | @category = Category.create!(name: "category") 9 | end 10 | 11 | it "works" do 12 | [ 13 | '/', 14 | "/companies/#{@company.id}", 15 | "/companies/#{@company.id}/edit", 16 | "/companies/#{@company.id}/attachments", 17 | "/companies/#{@company.id}/attachments/new", 18 | '/accounts', 19 | '/accounts/new', 20 | "/accounts/#{@account.id}", 21 | "/accounts/#{@account.id}/edit", 22 | '/secret/admin/categories', 23 | '/secret/admin/categories/new', 24 | "/secret/admin/categories/#{@category.id}", 25 | "/secret/admin/categories/#{@category.id}/edit", 26 | '/photos', 27 | ].each do |url| 28 | get url 29 | expect(response).to be_successful 30 | end 31 | end 32 | 33 | 34 | it 'with protection' do 35 | [ 36 | '/users', 37 | '/users/new', 38 | "/users/#{@user.id}", 39 | "/users/#{@user.id}/edit", 40 | ].each do |url| 41 | get url, headers: { HTTP_AUTHORIZATION: ActionController::HttpAuthentication::Basic.encode_credentials('user', 'secret') } 42 | expect(response).to be_successful 43 | end 44 | end 45 | 46 | it 'creates records' do 47 | post '/accounts', params: { account: { name: 'ABC123', owner_id: @user.id } } 48 | expect(response).to be_redirect 49 | expect(Account.find_by(name: 'ABC123')).to be 50 | 51 | post '/accounts', params: { account: { name: '' } } 52 | expect(response.status).to eq(422) 53 | end 54 | 55 | it 'updates records' do 56 | expect(@account.name).to eq("soft") 57 | patch "/accounts/#{@account.id}", params: { account: { name: 'ABC123', owner_id: @user.id } } 58 | expect(response).to be_redirect 59 | @account.reload 60 | expect(@account.name).to eq("ABC123") 61 | 62 | patch "/accounts/#{@account.id}", params: { account: { name: '' } } 63 | expect(response.status).to eq(422) 64 | end 65 | 66 | it 'deleted the record' do 67 | delete "/accounts/#{@account.id}" 68 | expect(response).to be_redirect 69 | expect(Account.find_by(id: @account.id)).to be_nil 70 | end 71 | 72 | it 'saves with underscore record' do 73 | post "/export_lists", params: { export_list: { name: "name", account_id: 42 } } 74 | expect(response).to be_redirect 75 | expect(ExportList.first.account_id).to eq(42) 76 | end 77 | 78 | end -------------------------------------------------------------------------------- /spec/helpers/helpers_spec.rb: -------------------------------------------------------------------------------- 1 | require_relative "../rails_helper" 2 | 3 | describe MegaScaffold::Helpers do 4 | end -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require 'spec_helper' 3 | ENV['RAILS_ENV'] ||= 'test' 4 | 5 | require 'simplecov' 6 | SimpleCov.start 'rails' 7 | 8 | require_relative '../test/dummy/config/environment' 9 | # Prevent database truncation if the environment is production 10 | abort("The Rails environment is running in production mode!") if Rails.env.production? 11 | require 'rspec/rails' 12 | 13 | # Add additional requires below this line. Rails is not loaded until this point! 14 | 15 | # Requires supporting ruby files with custom matchers and macros, etc, in 16 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 17 | # run as spec files by default. This means that files in spec/support that end 18 | # in _spec.rb will both be required and run as specs, causing the specs to be 19 | # run twice. It is recommended that you do not name files matching this glob to 20 | # end with _spec.rb. You can configure this pattern with the --pattern 21 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 22 | # 23 | # The following line is provided for convenience purposes. It has the downside 24 | # of increasing the boot-up time by auto-requiring all files in the support 25 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 26 | # require only the support files necessary. 27 | # 28 | # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } 29 | 30 | # Checks for pending migrations and applies them before tests are run. 31 | # If you are not using ActiveRecord, you can remove these lines. 32 | begin 33 | ActiveRecord::Migration.maintain_test_schema! 34 | rescue ActiveRecord::PendingMigrationError => e 35 | puts e.to_s.strip 36 | exit 1 37 | end 38 | RSpec.configure do |config| 39 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 40 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 41 | 42 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 43 | # examples within a transaction, remove the following line or assign false 44 | # instead of true. 45 | config.use_transactional_fixtures = true 46 | 47 | # You can uncomment this line to turn off ActiveRecord support entirely. 48 | # config.use_active_record = false 49 | 50 | # RSpec Rails can automatically mix in different behaviours to your tests 51 | # based on their file location, for example enabling you to call `get` and 52 | # `post` in specs under `spec/controllers`. 53 | # 54 | # You can disable this behaviour by removing the line below, and instead 55 | # explicitly tag your specs with their type, e.g.: 56 | # 57 | # RSpec.describe UsersController, type: :controller do 58 | # # ... 59 | # end 60 | # 61 | # The different available types are documented in the features, such as in 62 | # https://relishapp.com/rspec/rspec-rails/docs 63 | config.infer_spec_type_from_file_location! 64 | 65 | # Filter lines from Rails gems in backtraces. 66 | config.filter_rails_from_backtrace! 67 | # arbitrary gems may also be filtered via: 68 | # config.filter_gems_from_backtrace("gem name") 69 | end 70 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | =begin 50 | # This allows you to limit a spec run to individual examples or groups 51 | # you care about by tagging them with `:focus` metadata. When nothing 52 | # is tagged with `:focus`, all examples get run. RSpec also provides 53 | # aliases for `it`, `describe`, and `context` that include `:focus` 54 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 55 | config.filter_run_when_matching :focus 56 | 57 | # Allows RSpec to persist some state between runs in order to support 58 | # the `--only-failures` and `--next-failure` CLI options. We recommend 59 | # you configure your source control system to ignore this file. 60 | config.example_status_persistence_file_path = "spec/examples.txt" 61 | 62 | # Limits the available syntax to the non-monkey patched syntax that is 63 | # recommended. For more details, see: 64 | # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode 65 | config.disable_monkey_patching! 66 | 67 | # Many RSpec users commonly either run the entire suite or an individual 68 | # file, and it's useful to allow more verbose output when running an 69 | # individual spec file. 70 | if config.files_to_run.one? 71 | # Use the documentation formatter for detailed output, 72 | # unless a formatter has already been configured 73 | # (e.g. via a command-line flag). 74 | config.default_formatter = "doc" 75 | end 76 | 77 | # Print the 10 slowest examples and example groups at the 78 | # end of the spec run, to help surface which specs are running 79 | # particularly slow. 80 | config.profile_examples = 10 81 | 82 | # Run specs in random order to surface order dependencies. If you find an 83 | # order dependency and want to debug it, you can fix the order by providing 84 | # the seed, which is printed after each run. 85 | # --seed 1234 86 | config.order = :random 87 | 88 | # Seed global randomization in this process using the `--seed` CLI option. 89 | # Setting this allows you to use `--seed` to deterministically reproduce 90 | # test failures related to randomization by passing the same `--seed` value 91 | # as the one that triggered the failure. 92 | Kernel.srand config.seed 93 | =end 94 | end 95 | -------------------------------------------------------------------------------- /test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative "config/application" 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /test/dummy/app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css -------------------------------------------------------------------------------- /test/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /test/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | //= require rails-ujs -------------------------------------------------------------------------------- /test/dummy/app/assets/stylesheets/application.scss: -------------------------------------------------------------------------------- 1 | /* Application styles */ 2 | 3 | body { 4 | padding: 50px; 5 | padding-top: 20px; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /test/dummy/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | 3 | def admin? 4 | true 5 | end 6 | 7 | def current_user 8 | User.first 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/companies_controller.rb: -------------------------------------------------------------------------------- 1 | class CompaniesController < ApplicationController 2 | before_action :set_company, only: %i[ show edit update destroy ] 3 | 4 | # GET /companies 5 | def index 6 | @companies = Company.all 7 | end 8 | 9 | # GET /companies/1 10 | def show 11 | end 12 | 13 | # GET /companies/new 14 | def new 15 | @company = Company.new 16 | end 17 | 18 | # GET /companies/1/edit 19 | def edit 20 | end 21 | 22 | # POST /companies 23 | def create 24 | @company = Company.new(company_params) 25 | 26 | if @company.save 27 | redirect_to @company, notice: "Company was successfully created." 28 | else 29 | render :new, status: :unprocessable_entity 30 | end 31 | end 32 | 33 | # PATCH/PUT /companies/1 34 | def update 35 | if @company.update(company_params) 36 | redirect_to @company, notice: "Company was successfully updated." 37 | else 38 | render :edit, status: :unprocessable_entity 39 | end 40 | end 41 | 42 | # DELETE /companies/1 43 | def destroy 44 | @company.destroy 45 | redirect_to companies_url, notice: "Company was successfully destroyed." 46 | end 47 | 48 | private 49 | # Use callbacks to share common setup or constraints between actions. 50 | def set_company 51 | @company = Company.find(params[:id]) 52 | end 53 | 54 | # Only allow a list of trusted parameters through. 55 | def company_params 56 | params.require(:company).permit(:name) 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/controllers/concerns/protected.rb: -------------------------------------------------------------------------------- 1 | module Protected 2 | extend ActiveSupport::Concern 3 | 4 | included do 5 | http_basic_authenticate_with name: "user", password: "secret" 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | class HomeController < ApplicationController 2 | def index 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/helpers/home_helper.rb: -------------------------------------------------------------------------------- 1 | module HomeHelper 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | # Automatically retry jobs that encountered a deadlock 3 | # retry_on ActiveRecord::Deadlocked 4 | 5 | # Most jobs are safe to ignore if the underlying records are no longer available 6 | # discard_on ActiveJob::DeserializationError 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: "from@example.com" 3 | layout "mailer" 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/models/account.rb: -------------------------------------------------------------------------------- 1 | class Account < ApplicationRecord 2 | TYPES = ["bussines", "personal", "corporate"] 3 | 4 | belongs_to :owner, class_name: "User" 5 | 6 | has_and_belongs_to_many :categories 7 | 8 | scope :by_name, -> { order(name: :asc) } 9 | 10 | validates :name, presence: true 11 | validate :name_is_not_include_5 12 | 13 | private 14 | 15 | def name_is_not_include_5 16 | errors.add(:name, "can't include 5 in name") if name.to_s =~ /5/ 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /test/dummy/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/models/attachment.rb: -------------------------------------------------------------------------------- 1 | class Attachment < ApplicationRecord 2 | belongs_to :company 3 | 4 | mount_uploader :file, AttachmentUploader 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/app/models/category.rb: -------------------------------------------------------------------------------- 1 | class Category < ApplicationRecord 2 | has_and_belongs_to_many :accounts 3 | 4 | scope :by_name, -> { order(:name) } 5 | 6 | validates :name, presence: true 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/models/color.rb: -------------------------------------------------------------------------------- 1 | class Color < ApplicationRecord 2 | has_and_belongs_to_many :users 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/models/company.rb: -------------------------------------------------------------------------------- 1 | class Company < ApplicationRecord 2 | has_many :attachments, dependent: :destroy 3 | has_many :company_users 4 | has_many :user, through: :company_users 5 | 6 | validates :name, presence: true 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/app/models/company_user.rb: -------------------------------------------------------------------------------- 1 | class CompanyUser < ApplicationRecord 2 | belongs_to :company 3 | belongs_to :user 4 | end 5 | -------------------------------------------------------------------------------- /test/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /test/dummy/app/models/export_list.rb: -------------------------------------------------------------------------------- 1 | class ExportList < ApplicationRecord 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/app/models/photo.rb: -------------------------------------------------------------------------------- 1 | class Photo < ApplicationRecord 2 | belongs_to :user 3 | 4 | mount_uploader :photo, PhotoUploader 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | has_many :photos 3 | has_many :accounts, foreign_key: :owner_id 4 | has_and_belongs_to_many :colors 5 | has_many :company_users 6 | has_many :companies, through: :company_users 7 | 8 | scope :ordered, -> { order(id: :desc) } 9 | scope :by_name, -> { order(name: :asc) } 10 | 11 | validates :name, presence: true 12 | end 13 | -------------------------------------------------------------------------------- /test/dummy/app/uploaders/attachment_uploader.rb: -------------------------------------------------------------------------------- 1 | class AttachmentUploader < CarrierWave::Uploader::Base 2 | # Include RMagick or MiniMagick support: 3 | # include CarrierWave::RMagick 4 | # include CarrierWave::MiniMagick 5 | 6 | # Choose what kind of storage to use for this uploader: 7 | storage :file 8 | # storage :fog 9 | 10 | # Override the directory where uploaded files will be stored. 11 | # This is a sensible default for uploaders that are meant to be mounted: 12 | def store_dir 13 | "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 14 | end 15 | 16 | # Provide a default URL as a default if there hasn't been a file uploaded: 17 | # def default_url(*args) 18 | # # For Rails 3.1+ asset pipeline compatibility: 19 | # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 20 | # 21 | # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 22 | # end 23 | 24 | # Process files as they are uploaded: 25 | # process scale: [200, 300] 26 | # 27 | # def scale(width, height) 28 | # # do something 29 | # end 30 | 31 | # Create different versions of your uploaded files: 32 | # version :thumb do 33 | # process resize_to_fit: [50, 50] 34 | # end 35 | 36 | # Add an allowlist of extensions which are allowed to be uploaded. 37 | # For images you might use something like this: 38 | # def extension_allowlist 39 | # %w(jpg jpeg gif png) 40 | # end 41 | 42 | # Override the filename of the uploaded files: 43 | # Avoid using model.id or version_name here, see uploader/store.rb for details. 44 | # def filename 45 | # "something.jpg" if original_filename 46 | # end 47 | end 48 | -------------------------------------------------------------------------------- /test/dummy/app/uploaders/photo_uploader.rb: -------------------------------------------------------------------------------- 1 | class PhotoUploader < CarrierWave::Uploader::Base 2 | # Include RMagick or MiniMagick support: 3 | # include CarrierWave::RMagick 4 | # include CarrierWave::MiniMagick 5 | 6 | # Choose what kind of storage to use for this uploader: 7 | storage :file 8 | # storage :fog 9 | 10 | # Override the directory where uploaded files will be stored. 11 | # This is a sensible default for uploaders that are meant to be mounted: 12 | def store_dir 13 | "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 14 | end 15 | 16 | # Provide a default URL as a default if there hasn't been a file uploaded: 17 | # def default_url(*args) 18 | # # For Rails 3.1+ asset pipeline compatibility: 19 | # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 20 | # 21 | # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 22 | # end 23 | 24 | # Process files as they are uploaded: 25 | # process scale: [200, 300] 26 | # 27 | # def scale(width, height) 28 | # # do something 29 | # end 30 | 31 | # Create different versions of your uploaded files: 32 | # version :thumb do 33 | # process resize_to_fit: [50, 50] 34 | # end 35 | 36 | # Add an allowlist of extensions which are allowed to be uploaded. 37 | # For images you might use something like this: 38 | # def extension_allowlist 39 | # %w(jpg jpeg gif png) 40 | # end 41 | 42 | # Override the filename of the uploaded files: 43 | # Avoid using model.id or version_name here, see uploader/store.rb for details. 44 | # def filename 45 | # "something.jpg" if original_filename 46 | # end 47 | end 48 | -------------------------------------------------------------------------------- /test/dummy/app/views/companies/_company.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

3 | Name: 4 | <%= company.name %> 5 |

6 | 7 |
8 | -------------------------------------------------------------------------------- /test/dummy/app/views/companies/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_with(model: company) do |form| %> 2 | <% if company.errors.any? %> 3 |
4 |

<%= pluralize(company.errors.count, "error") %> prohibited this company from being saved:

5 | 6 | 11 |
12 | <% end %> 13 | 14 |
15 | <%= form.label :name, style: "display: block" %> 16 | <%= form.text_field :name %> 17 |
18 | 19 |
20 | <%= form.submit %> 21 |
22 | <% end %> 23 | -------------------------------------------------------------------------------- /test/dummy/app/views/companies/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing company

2 | 3 | <%= render "form", company: @company %> 4 | 5 |
6 | 7 |
8 | <%= link_to "Show this company", @company %> | 9 | <%= link_to "Back to companies", companies_path %> 10 |
11 | -------------------------------------------------------------------------------- /test/dummy/app/views/companies/index.html.erb: -------------------------------------------------------------------------------- 1 |

Companies

2 | 3 |
4 | <% @companies.each do |company| %> 5 |
6 | <%= render company %> 7 |

8 | <%= link_to "Show", company %> 9 | | 10 | <%= link_to "Attachments", [company, :attachments] %> 11 |

12 |
13 | <% end %> 14 |
15 | 16 |
17 | <%= link_to "New company", new_company_path %> 18 | -------------------------------------------------------------------------------- /test/dummy/app/views/companies/new.html.erb: -------------------------------------------------------------------------------- 1 |

New company

2 | 3 | <%= render "form", company: @company %> 4 | 5 |
6 | 7 |
8 | <%= link_to "Back to companies", companies_path %> 9 |
10 | -------------------------------------------------------------------------------- /test/dummy/app/views/companies/show.html.erb: -------------------------------------------------------------------------------- 1 | <%= render @company %> 2 | 3 |
4 | <%= link_to "Edit this company", edit_company_path(@company) %> | 5 | <%= link_to "Manage Attachments", company_attachments_path(@company) %> | 6 | <%= link_to "Back to companies", companies_path %> 7 | 8 |
9 | 10 | Attachments: <%= @company.attachments.count %> 11 | 12 |
13 |
14 | 15 | <%= button_to "Destroy this company", @company, method: :delete %> 16 |
17 | -------------------------------------------------------------------------------- /test/dummy/app/views/home/index.html.erb: -------------------------------------------------------------------------------- 1 |

Dummy app for mega_scaffold gem

2 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | <%= stylesheet_link_tag "application" %> 10 | <%= javascript_include_tag "application" %> 11 | 12 | 13 | 14 | <% if notice.present? %> 15 |

<%= notice %>

16 | <% end %> 17 | 18 | <%= link_to "Home", root_path rescue nil %> 19 | - 20 | <%= link_to "Users", users_path rescue nil %> 21 | - 22 | <%= link_to "Photos", photos_path rescue nil %> 23 | - 24 | <%= link_to "Accounts", accounts_path rescue nil %> 25 | - 26 | <%= link_to "Categories (in namespace)", secret_admin_categories_path rescue nil %> 27 | - 28 | <%= link_to "Companies", companies_path rescue nil %> 29 |
30 | <%= yield %> 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /test/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails/all" 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | require "mega_scaffold" 9 | 10 | module Dummy 11 | class Application < Rails::Application 12 | config.load_defaults Rails::VERSION::STRING.to_f 13 | 14 | # Configuration for the application, engines, and railties goes here. 15 | # 16 | # These settings can be overridden in specific environments using the files 17 | # in config/environments, which are processed later. 18 | # 19 | # config.time_zone = "Central Time (US & Canada)" 20 | # config.eager_load_paths << Rails.root.join("extras") 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) 3 | 4 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) 5 | $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__) 6 | -------------------------------------------------------------------------------- /test/dummy/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: dummy_production 11 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 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: <%= ENV.fetch("RAILS_MAX_THREADS") { 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 26 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # In the development environment your application's code is reloaded any time 7 | # it changes. This slows down response time but is perfect for development 8 | # since you don't have to restart the web server when you make code changes. 9 | config.cache_classes = false 10 | 11 | # Do not eager load code on boot. 12 | config.eager_load = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable server timing 18 | config.server_timing = true 19 | 20 | # Enable/disable caching. By default caching is disabled. 21 | # Run rails dev:cache to toggle caching. 22 | if Rails.root.join("tmp/caching-dev.txt").exist? 23 | config.action_controller.perform_caching = true 24 | config.action_controller.enable_fragment_cache_logging = true 25 | 26 | config.cache_store = :memory_store 27 | config.public_file_server.headers = { 28 | "Cache-Control" => "public, max-age=#{2.days.to_i}" 29 | } 30 | else 31 | config.action_controller.perform_caching = false 32 | 33 | config.cache_store = :null_store 34 | end 35 | 36 | # Store uploaded files on the local file system (see config/storage.yml for options). 37 | config.active_storage.service = :local 38 | 39 | # Don't care if the mailer can't send. 40 | config.action_mailer.raise_delivery_errors = false 41 | 42 | config.action_mailer.perform_caching = false 43 | 44 | # Print deprecation notices to the Rails logger. 45 | config.active_support.deprecation = :log 46 | 47 | # Raise exceptions for disallowed deprecations. 48 | config.active_support.disallowed_deprecation = :raise 49 | 50 | # Tell Active Support which deprecation messages to disallow. 51 | config.active_support.disallowed_deprecation_warnings = [] 52 | 53 | # Raise an error on page load if there are pending migrations. 54 | config.active_record.migration_error = :page_load 55 | 56 | # Highlight code that triggered database queries in logs. 57 | config.active_record.verbose_query_logs = true 58 | 59 | 60 | # Raises error for missing translations. 61 | # config.i18n.raise_on_missing_translations = true 62 | 63 | # Annotate rendered view with file names. 64 | # config.action_view.annotate_rendered_view_with_filenames = true 65 | 66 | # Uncomment if you wish to allow Action Cable access from any origin. 67 | # config.action_cable.disable_request_forgery_protection = true 68 | end 69 | -------------------------------------------------------------------------------- /test/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | Rails.application.configure do 4 | # Settings specified here will take precedence over those in config/application.rb. 5 | 6 | # Code is not reloaded between requests. 7 | config.cache_classes = true 8 | 9 | # Eager load code on boot. This eager loads most of Rails and 10 | # your application in memory, allowing both threaded web servers 11 | # and those relying on copy on write to perform better. 12 | # Rake tasks automatically ignore this option for performance. 13 | config.eager_load = true 14 | 15 | # Full error reports are disabled and caching is turned on. 16 | config.consider_all_requests_local = false 17 | config.action_controller.perform_caching = true 18 | 19 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 20 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 21 | # config.require_master_key = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? 26 | 27 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 28 | # config.asset_host = "http://assets.example.com" 29 | 30 | # Specifies the header that your server uses for sending files. 31 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache 32 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX 33 | 34 | # Store uploaded files on the local file system (see config/storage.yml for options). 35 | config.active_storage.service = :local 36 | 37 | # Mount Action Cable outside main process or domain. 38 | # config.action_cable.mount_path = nil 39 | # config.action_cable.url = "wss://example.com/cable" 40 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Include generic and useful information about system operation, but avoid logging too much 46 | # information to avoid inadvertent exposure of personally identifiable information (PII). 47 | config.log_level = :info 48 | 49 | # Prepend all log lines with the following tags. 50 | config.log_tags = [ :request_id ] 51 | 52 | # Use a different cache store in production. 53 | # config.cache_store = :mem_cache_store 54 | 55 | # Use a real queuing backend for Active Job (and separate queues per environment). 56 | # config.active_job.queue_adapter = :resque 57 | # config.active_job.queue_name_prefix = "dummy_production" 58 | 59 | config.action_mailer.perform_caching = false 60 | 61 | # Ignore bad email addresses and do not raise email delivery errors. 62 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 63 | # config.action_mailer.raise_delivery_errors = false 64 | 65 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 66 | # the I18n.default_locale when a translation cannot be found). 67 | config.i18n.fallbacks = true 68 | 69 | # Don't log any deprecations. 70 | config.active_support.report_deprecations = false 71 | 72 | # Use default logging formatter so that PID and timestamp are not suppressed. 73 | config.log_formatter = ::Logger::Formatter.new 74 | 75 | # Use a different logger for distributed setups. 76 | # require "syslog/logger" 77 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") 78 | 79 | if ENV["RAILS_LOG_TO_STDOUT"].present? 80 | logger = ActiveSupport::Logger.new(STDOUT) 81 | logger.formatter = config.log_formatter 82 | config.logger = ActiveSupport::TaggedLogging.new(logger) 83 | end 84 | 85 | # Do not dump schema after migrations. 86 | config.active_record.dump_schema_after_migration = false 87 | end 88 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # Turn false under Spring and add config.action_view.cache_template_loading = true. 12 | config.cache_classes = true 13 | 14 | # Eager loading loads your whole application. When running a single test locally, 15 | # this probably isn't necessary. It's a good idea to do in a continuous integration 16 | # system, or in some way before deploying your code. 17 | config.eager_load = ENV["CI"].present? 18 | 19 | # Configure public file server for tests with Cache-Control for performance. 20 | config.public_file_server.enabled = true 21 | config.public_file_server.headers = { 22 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 23 | } 24 | 25 | # Show full error reports and disable caching. 26 | config.consider_all_requests_local = true 27 | config.action_controller.perform_caching = false 28 | config.cache_store = :null_store 29 | 30 | # Raise exceptions instead of rendering exception templates. 31 | config.action_dispatch.show_exceptions = false 32 | 33 | # Disable request forgery protection in test environment. 34 | config.action_controller.allow_forgery_protection = false 35 | 36 | # Store uploaded files on the local file system in a temporary directory. 37 | config.active_storage.service = :test 38 | 39 | config.action_mailer.perform_caching = false 40 | 41 | # Tell Action Mailer not to deliver emails to the real world. 42 | # The :test delivery method accumulates sent emails in the 43 | # ActionMailer::Base.deliveries array. 44 | config.action_mailer.delivery_method = :test 45 | 46 | # Print deprecation notices to the stderr. 47 | config.active_support.deprecation = :stderr 48 | 49 | # Raise exceptions for disallowed deprecations. 50 | config.active_support.disallowed_deprecation = :raise 51 | 52 | # Tell Active Support which deprecation messages to disallow. 53 | config.active_support.disallowed_deprecation_warnings = [] 54 | 55 | # Raises error for missing translations. 56 | # config.i18n.raise_on_missing_translations = true 57 | 58 | # Annotate rendered view with file names. 59 | # config.action_view.annotate_rendered_view_with_filenames = true 60 | end 61 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy 4 | # For further information see the following documentation 5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 6 | 7 | # Rails.application.configure do 8 | # config.content_security_policy do |policy| 9 | # policy.default_src :self, :https 10 | # policy.font_src :self, :https, :data 11 | # policy.img_src :self, :https, :data 12 | # policy.object_src :none 13 | # policy.script_src :self, :https 14 | # policy.style_src :self, :https 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | # 19 | # # Generate session nonces for permitted importmap and inline scripts 20 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } 21 | # config.content_security_policy_nonce_directives = %w(script-src) 22 | # 23 | # # Report CSP violations to a specified URI. See: 24 | # # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 25 | # # config.content_security_policy_report_only = true 26 | # end 27 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure parameters to be filtered from the log file. Use this to limit dissemination of 4 | # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported 5 | # notations and behaviors. 6 | Rails.application.config.filter_parameters += [ 7 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 8 | ] 9 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, "\\1en" 8 | # inflect.singular /^(ox)en/i, "\\1" 9 | # inflect.irregular "person", "people" 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym "RESTful" 16 | # end 17 | -------------------------------------------------------------------------------- /test/dummy/config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # "true": "foo" 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /test/dummy/config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 9 | threads min_threads_count, max_threads_count 10 | 11 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 12 | # terminating a worker in development environments. 13 | # 14 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 15 | 16 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 17 | # 18 | port ENV.fetch("PORT") { 3000 } 19 | 20 | # Specifies the `environment` that Puma will run in. 21 | # 22 | environment ENV.fetch("RAILS_ENV") { "development" } 23 | 24 | # Specifies the `pidfile` that Puma will use. 25 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 26 | 27 | # Specifies the number of `workers` to boot in clustered mode. 28 | # Workers are forked web server processes. If using threads and workers together 29 | # the concurrency of the application would be max `threads` * `workers`. 30 | # Workers do not work on JRuby or Windows (both of which do not support 31 | # processes). 32 | # 33 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 34 | 35 | # Use the `preload_app!` method when specifying a `workers` number. 36 | # This directive tells Puma to first boot the application and load code 37 | # before forking the application. This takes advantage of Copy On Write 38 | # process behavior so workers use less memory. 39 | # 40 | # preload_app! 41 | 42 | # Allow puma to be restarted by `bin/rails restart` command. 43 | plugin :tmp_restart 44 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | mega_scaffold :export_lists 3 | 4 | resources :companies do 5 | mega_scaffold :attachments, 6 | parent: -> (controller) { Company.find(controller.params[:company_id]) }, 7 | collection: -> (controller) { controller.parent.attachments }, 8 | fields: [ 9 | { name: :id, view: :index }, 10 | { name: :file, type: :file_field, view: :all, value: -> (record, view) { view.link_to 'Download', record.file.url } }, 11 | { name: :created_at, view: :index }, 12 | ] 13 | end 14 | 15 | namespace :secret do 16 | namespace :admin do 17 | mega_scaffold :categories, fields: [ 18 | { name: :id, view: :index }, 19 | { name: :name, view: :all, value: -> (record, _) { record.name&.upcase } }, 20 | { name: :accounts, view: [:index, :show], value: -> (record, _) { record.accounts.count } }, 21 | { name: :created_at, view: [:index, :show], value: -> (record, _) { I18n.l record.created_at, format: :short } }, 22 | ] 23 | end 24 | end 25 | 26 | mega_scaffold :users, 27 | collection: -> (_) { User.ordered }, 28 | concerns: [Protected], 29 | only: [:id, :name, :age, :dob, :country, :created_at, :phone] 30 | 31 | mega_scaffold :photos, 32 | fields: [ 33 | { name: :user, column: :user_id, view: :all, type: :select, collection: -> { User.by_name.map{|e| [e.name, e.id]} }, value: -> (record, view) { view.link_to_if record.user, record.user&.name, record.user } }, 34 | { name: :photo, type: :file_field, view: :all, value: -> (record, view) { view.image_tag record.photo.url, style: 'width: 200px' } }, 35 | { name: :created_at, view: :index, value: -> (record, view) { view.l record.created_at, format: :long } }, 36 | ] 37 | 38 | mega_scaffold :accounts, 39 | collection: -> (controller) { controller.admin? ? Account.all : current_user.accounts }, 40 | fields: [ 41 | { name: :id, view: [:show] }, 42 | { name: :name, type: :text_field, view: :all, value: -> (record, view) { view.link_to record.name.to_s.upcase, record } }, 43 | { name: :email, type: :email_field, view: :all, value: -> (record, view) { view.mail_to record.email } }, 44 | { 45 | view: :all, 46 | name: :account_type, 47 | type: :collection_select, 48 | collection: -> { Account::TYPES }, 49 | options: [:to_s, :to_s, include_blank: true] 50 | }, 51 | { 52 | view: :all, 53 | name: :priority, 54 | type: :range_field, 55 | options: { min: 0, max: 100, step: 10 } 56 | }, 57 | { 58 | name: :categories, 59 | column: { 60 | name: :category_ids, 61 | permit: [], 62 | }, 63 | type: :collection_check_boxes, 64 | options: [:id, :name], 65 | view: :form, 66 | collection: -> { Category.by_name }, 67 | value: { 68 | index: -> (record, _) { record.categories.count }, 69 | show: -> (record, _) { record.categories.pluck(:name).join(", ") } 70 | } 71 | }, 72 | { name: 'VIRTUAL ATTR', type: :virtual, view: :index, value: -> (record, view) { "ID: #{record.id}" } }, 73 | { 74 | name: :owner_id, 75 | label: "Owner", 76 | view: :all, 77 | options: { include_blank: true }, 78 | type: :select, 79 | collection: -> { User.by_name.map{|e| [e.name, e.id]} }, 80 | value: -> (record, _) { record.owner&.name } 81 | }, 82 | { name: :created_at, view: [:index, :show], value: -> (record, _) { I18n.l(record.created_at, format: :long) } }, 83 | ] 84 | 85 | root "home#index" 86 | end 87 | -------------------------------------------------------------------------------- /test/dummy/config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket-<%= Rails.env %> 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket-<%= Rails.env %> 23 | 24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name-<%= Rails.env %> 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502094418_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :users do |t| 4 | t.string :name 5 | t.integer :age 6 | t.date :dob 7 | t.text :about 8 | t.string :country 9 | 10 | t.timestamps 11 | end 12 | 13 | 100.times do 14 | User.create( 15 | name: Faker::Name.name, 16 | age: rand(100), 17 | dob: rand(10000).days.ago, 18 | about: Faker::Lorem.paragraph, 19 | country: Faker::Address.country 20 | ) 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502124520_create_accounts.rb: -------------------------------------------------------------------------------- 1 | class CreateAccounts < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :accounts do |t| 4 | t.string :name 5 | t.integer :owner_id 6 | 7 | t.timestamps 8 | end 9 | 10 | 100.times do 11 | Account.create( 12 | name: Faker::Company.name, 13 | owner: User.all.sample 14 | ) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502155108_create_categories.rb: -------------------------------------------------------------------------------- 1 | class CreateCategories < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :categories do |t| 4 | t.string :name 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502185843_add_habtm.rb: -------------------------------------------------------------------------------- 1 | class AddHabtm < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :accounts_categories, id: false do |t| 4 | t.integer :account_id 5 | t.integer :category_id 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502195803_create_photos.rb: -------------------------------------------------------------------------------- 1 | class CreatePhotos < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :photos do |t| 4 | t.integer :user_id 5 | t.string :photo 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502201418_create_companies.rb: -------------------------------------------------------------------------------- 1 | class CreateCompanies < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :companies do |t| 4 | t.string :name 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220502201501_create_attachments.rb: -------------------------------------------------------------------------------- 1 | class CreateAttachments < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :attachments do |t| 4 | t.string :file 5 | t.integer :company_id 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220503184142_add_more_fields_to_user.rb: -------------------------------------------------------------------------------- 1 | class AddMoreFieldsToUser < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :users, :expected_salary, :bigint 4 | add_column :users, :avg_salary, :float 5 | add_column :users, :hireable, :boolean, default: false 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220503185215_add_more_fields_to_user2.rb: -------------------------------------------------------------------------------- 1 | class AddMoreFieldsToUser2 < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :users, :phone, :string 4 | add_column :users, :facebook_url, :string 5 | add_column :users, :favorite_color, :string 6 | add_column :users, :secret_password, :string 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220503191207_create_colors.rb: -------------------------------------------------------------------------------- 1 | class CreateColors < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :colors do |t| 4 | t.string :name 5 | 6 | t.timestamps 7 | end 8 | 9 | create_table :colors_users, id: false do |t| 10 | t.integer :color_id 11 | t.integer :user_id 12 | end 13 | 14 | Color.create(name: 'Black') 15 | Color.create(name: 'Red') 16 | Color.create(name: 'Green') 17 | Color.create(name: 'Yellow') 18 | Color.create(name: 'Orange') 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220504065200_add_r_ole_to_user.rb: -------------------------------------------------------------------------------- 1 | class AddROleToUser < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :users, :role, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220504065350_create_company_users.rb: -------------------------------------------------------------------------------- 1 | class CreateCompanyUsers < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :company_users do |t| 4 | t.integer :company_id 5 | t.integer :user_id 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220504065821_add_role_to_account_too.rb: -------------------------------------------------------------------------------- 1 | class AddRoleToAccountToo < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :accounts, :account_type, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220504073418_add_pritority_to_account.rb: -------------------------------------------------------------------------------- 1 | class AddPritorityToAccount < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :accounts, :priority, :integer 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220504192931_add_email_to_company.rb: -------------------------------------------------------------------------------- 1 | class AddEmailToCompany < ActiveRecord::Migration[7.0] 2 | def change 3 | add_column :accounts, :email, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/dummy/db/migrate/20220509173200_create_export_lists.rb: -------------------------------------------------------------------------------- 1 | class CreateExportLists < ActiveRecord::Migration[7.0] 2 | def change 3 | create_table :export_lists do |t| 4 | t.string :name 5 | t.integer :account_id 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/dummy/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `bin/rails 6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema[7.0].define(version: 2022_05_09_173200) do 14 | create_table "accounts", force: :cascade do |t| 15 | t.string "name" 16 | t.integer "owner_id" 17 | t.datetime "created_at", null: false 18 | t.datetime "updated_at", null: false 19 | t.string "account_type" 20 | t.integer "priority" 21 | t.string "email" 22 | end 23 | 24 | create_table "accounts_categories", id: false, force: :cascade do |t| 25 | t.integer "account_id" 26 | t.integer "category_id" 27 | end 28 | 29 | create_table "attachments", force: :cascade do |t| 30 | t.string "file" 31 | t.integer "company_id" 32 | t.datetime "created_at", null: false 33 | t.datetime "updated_at", null: false 34 | end 35 | 36 | create_table "categories", force: :cascade do |t| 37 | t.string "name" 38 | t.datetime "created_at", null: false 39 | t.datetime "updated_at", null: false 40 | end 41 | 42 | create_table "colors", force: :cascade do |t| 43 | t.string "name" 44 | t.datetime "created_at", null: false 45 | t.datetime "updated_at", null: false 46 | end 47 | 48 | create_table "colors_users", id: false, force: :cascade do |t| 49 | t.integer "color_id" 50 | t.integer "user_id" 51 | end 52 | 53 | create_table "companies", force: :cascade do |t| 54 | t.string "name" 55 | t.datetime "created_at", null: false 56 | t.datetime "updated_at", null: false 57 | end 58 | 59 | create_table "company_users", force: :cascade do |t| 60 | t.integer "company_id" 61 | t.integer "user_id" 62 | t.datetime "created_at", null: false 63 | t.datetime "updated_at", null: false 64 | end 65 | 66 | create_table "export_lists", force: :cascade do |t| 67 | t.string "name" 68 | t.integer "account_id" 69 | t.datetime "created_at", null: false 70 | t.datetime "updated_at", null: false 71 | end 72 | 73 | create_table "photos", force: :cascade do |t| 74 | t.integer "user_id" 75 | t.string "photo" 76 | t.datetime "created_at", null: false 77 | t.datetime "updated_at", null: false 78 | end 79 | 80 | create_table "users", force: :cascade do |t| 81 | t.string "name" 82 | t.integer "age" 83 | t.date "dob" 84 | t.text "about" 85 | t.string "country" 86 | t.datetime "created_at", null: false 87 | t.datetime "updated_at", null: false 88 | t.bigint "expected_salary" 89 | t.float "avg_salary" 90 | t.boolean "hireable", default: false 91 | t.string "phone" 92 | t.string "facebook_url" 93 | t.string "favorite_color" 94 | t.string "secret_password" 95 | t.string "role" 96 | end 97 | 98 | end 99 | -------------------------------------------------------------------------------- /test/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /test/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/log/.keep -------------------------------------------------------------------------------- /test/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /test/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /test/dummy/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /test/dummy/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/public/apple-touch-icon.png -------------------------------------------------------------------------------- /test/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/railsjazz/mega_scaffold/6b1a265dc49fd92829bc8fba8f090f7401cc2160/test/dummy/public/favicon.ico -------------------------------------------------------------------------------- /test/mega_scaffold_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class MegaScaffoldTest < ActiveSupport::TestCase 4 | test "it has a version number" do 5 | assert MegaScaffold::VERSION 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # Configure Rails Environment 2 | ENV["RAILS_ENV"] = "test" 3 | 4 | require_relative "../test/dummy/config/environment" 5 | ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] 6 | require "rails/test_help" 7 | 8 | # Load fixtures from the engine 9 | if ActiveSupport::TestCase.respond_to?(:fixture_path=) 10 | ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) 11 | ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path 12 | ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" 13 | ActiveSupport::TestCase.fixtures :all 14 | end 15 | --------------------------------------------------------------------------------