apicasso 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +226 -223
  3. data/Rakefile +23 -23
  4. data/app/controllers/apicasso/apidocs_controller.rb +309 -299
  5. data/app/controllers/apicasso/application_controller.rb +170 -147
  6. data/app/controllers/apicasso/crud_controller.rb +246 -245
  7. data/app/controllers/concerns/orderable.rb +45 -45
  8. data/app/models/apicasso/ability.rb +38 -38
  9. data/app/models/apicasso/application_record.rb +6 -6
  10. data/app/models/apicasso/key.rb +25 -25
  11. data/app/models/apicasso/request.rb +8 -8
  12. data/config/routes.rb +14 -14
  13. data/lib/apicasso/active_record_extension.rb +0 -44
  14. data/lib/apicasso/engine.rb +13 -13
  15. data/lib/apicasso/version.rb +3 -3
  16. data/lib/apicasso.rb +15 -13
  17. data/lib/generators/apicasso/install/install_generator.rb +25 -25
  18. data/lib/generators/apicasso/install/templates/create_apicasso_tables.rb +20 -20
  19. data/spec/dummy/Gemfile +56 -0
  20. data/spec/dummy/Gemfile.lock +237 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  22. data/spec/dummy/app/models/used_model.rb +42 -0
  23. data/spec/dummy/app/serializers/used_model_serializer.rb +3 -0
  24. data/spec/dummy/bin/rails +5 -0
  25. data/spec/dummy/bin/rake +5 -0
  26. data/spec/dummy/bin/setup +0 -3
  27. data/spec/dummy/bin/spring +17 -0
  28. data/spec/dummy/bin/update +0 -3
  29. data/spec/dummy/config/application.rb +14 -10
  30. data/spec/dummy/config/cable.yml +1 -1
  31. data/spec/dummy/config/credentials.yml.enc +1 -0
  32. data/spec/dummy/config/database.yml +5 -14
  33. data/spec/dummy/config/environments/development.rb +6 -10
  34. data/spec/dummy/config/environments/production.rb +1 -10
  35. data/spec/dummy/config/initializers/cors.rb +16 -0
  36. data/spec/dummy/config/locales/en.yml +7 -32
  37. data/spec/dummy/config/routes.rb +1 -1
  38. data/{db/migrate/20180826141433_create_apicasso_tables.rb → spec/dummy/db/migrate/20180918134607_create_apicasso_tables.rb} +1 -0
  39. data/spec/dummy/db/migrate/20180918141254_create_used_models.rb +44 -0
  40. data/spec/dummy/db/migrate/20180919130152_create_active_storage_tables.active_storage.rb +26 -0
  41. data/spec/dummy/db/migrate/20180920133933_change_used_model_to_validates.rb +7 -0
  42. data/spec/dummy/db/schema.rb +98 -0
  43. data/spec/dummy/db/seeds.rb +56 -0
  44. data/spec/factories/used_model.rb +28 -0
  45. data/spec/models/used_model_spec.rb +35 -0
  46. data/spec/rails_helper.rb +66 -0
  47. data/spec/requests/requests_spec.rb +227 -0
  48. data/spec/spec_helper.rb +7 -9
  49. data/spec/support/factory_bot.rb +3 -0
  50. metadata +83 -64
  51. data/spec/controllers/apicasso/aplication_controller_spec.rb +0 -18
  52. data/spec/controllers/apicasso/crud_controller_spec.rb +0 -107
  53. data/spec/dummy/app/assets/config/manifest.js +0 -3
  54. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  55. data/spec/dummy/app/assets/javascripts/cable.js +0 -13
  56. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  57. data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
  58. data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
  59. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  60. data/spec/dummy/app/jobs/application_job.rb +0 -2
  61. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  62. data/spec/dummy/app/views/layouts/application.html.erb +0 -15
  63. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  64. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  65. data/spec/dummy/bin/yarn +0 -11
  66. data/spec/dummy/config/initializers/assets.rb +0 -14
  67. data/spec/dummy/config/initializers/content_security_policy.rb +0 -25
  68. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
  69. data/spec/dummy/log/development.log +0 -0
  70. data/spec/dummy/public/404.html +0 -67
  71. data/spec/dummy/public/422.html +0 -67
  72. data/spec/dummy/public/500.html +0 -66
  73. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  74. data/spec/dummy/public/apple-touch-icon.png +0 -0
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/factories/apicasso_key.rb +0 -9
  77. data/spec/factories/object.rb +0 -5
  78. data/spec/models/apicasso/key.rb +0 -5
  79. data/spec/routing/appointments_routing_spec.rb +0 -38
data/spec/dummy/bin/rake CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
2
7
  require_relative '../config/boot'
3
8
  require 'rake'
4
9
  Rake.application.run
data/spec/dummy/bin/setup CHANGED
@@ -17,9 +17,6 @@ chdir APP_ROOT do
17
17
  system! 'gem install bundler --conservative'
18
18
  system('bundle check') || system!('bundle install')
19
19
 
20
- # Install JavaScript dependencies if using Yarn
21
- # system('bin/yarn')
22
-
23
20
  # puts "\n== Copying sample files =="
24
21
  # unless File.exist?('config/database.yml')
25
22
  # cp 'config/database.yml.sample', 'config/database.yml'
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast.
4
+ # It gets overwritten when you run the `spring binstub` command.
5
+
6
+ unless defined?(Spring)
7
+ require 'rubygems'
8
+ require 'bundler'
9
+
10
+ lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11
+ spring = lockfile.specs.detect { |spec| spec.name == "spring" }
12
+ if spring
13
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
14
+ gem 'spring', spring.version
15
+ require 'spring/binstub'
16
+ end
17
+ end
@@ -17,9 +17,6 @@ chdir APP_ROOT do
17
17
  system! 'gem install bundler --conservative'
18
18
  system('bundle check') || system!('bundle install')
19
19
 
20
- # Install JavaScript dependencies if using Yarn
21
- # system('bin/yarn')
22
-
23
20
  puts "\n== Updating database =="
24
21
  system! 'bin/rails db:migrate'
25
22
 
@@ -1,19 +1,23 @@
1
1
  require_relative 'boot'
2
2
 
3
- require 'rails/all'
3
+ require "rails"
4
+ # Pick the frameworks you want:
5
+ require "active_model/railtie"
6
+ require "active_job/railtie"
7
+ require "active_record/railtie"
8
+ require "active_storage/engine"
9
+ require "action_controller/railtie"
10
+ require "action_mailer/railtie"
11
+ require "action_view/railtie"
12
+ require "action_cable/engine"
13
+ # require "sprockets/railtie"
14
+ require "rails/test_unit/railtie"
4
15
 
5
16
  Bundler.require(*Rails.groups)
6
- require 'apicasso'
7
17
 
8
- module Dummy
18
+ module UsedModels
9
19
  class Application < Rails::Application
10
- # Initialize configuration defaults for originally generated Rails version.
11
20
  config.load_defaults 5.2
12
-
13
- # Settings in config/environments/* take precedence over those specified here.
14
- # Application configuration can go into files in config/initializers
15
- # -- all .rb files in that directory are automatically loaded after loading
16
- # the framework and any gems in your application.
21
+ config.api_only = true
17
22
  end
18
23
  end
19
-
@@ -7,4 +7,4 @@ test:
7
7
  production:
8
8
  adapter: redis
9
9
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
- channel_prefix: dummy_production
10
+ channel_prefix: used_models_production
@@ -0,0 +1 @@
1
+ GQaOV9BY0QLAlZrSF7Pclv2dwO/eaOsRB+39n6uTBOuwHpHlBuyXud8YUl1d7HM8rZnCjpRue+PBHE/r6eMHJ0xZJOAi2JtGHMyYziEEcQhPBWe3IWpCqVqVg5lcepcKoKKBeU+61NIMA0ssyweQJyu2BHUI8lQ/vF3GJ/AnD4upKeT7LyCWHWTnI8x/iMLOC+l5FTElfCbzGzTCrIu6UMZS93QeyDIrJe7HpA03Zj+4U98tnKVksm1uRwgMR4sLsHSKiP33knmM6hiP9inOAKtqIxVG6t5c8cXsSeRuMwAmsw9xVqCaJFpy27MXFLeE+rX3ODM+cPgg9C4dwQE5puZorxHlh+6uouOD4EwkXiVtbvYzQRqX/HVMHLElBSUy/+W9gpIKmgKQLqPf62i2IztHxihn46EcoPNx--W9Zqnfkakzg+tPnD--XL0cnKNTdBgPsl9vsTPVbw==
@@ -1,25 +1,16 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- #
7
1
  default: &default
8
- adapter: sqlite3
2
+ adapter: postgresql
3
+ encoding: unicode
9
4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
- timeout: 5000
11
5
 
12
6
  development:
13
7
  <<: *default
14
- database: db/development.sqlite3
8
+ database: used_models_development
15
9
 
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
10
  test:
20
11
  <<: *default
21
- database: db/test.sqlite3
12
+ database: used_models_test
22
13
 
23
14
  production:
24
15
  <<: *default
25
- database: db/production.sqlite3
16
+ database: used_models_production
@@ -17,7 +17,11 @@ Rails.application.configure do
17
17
  if Rails.root.join('tmp', 'caching-dev.txt').exist?
18
18
  config.action_controller.perform_caching = true
19
19
 
20
- config.cache_store = :memory_store
20
+ config.cache_store = :redis_store, {
21
+ expires_in: 1.hour,
22
+ namespace: 'cache',
23
+ redis: { host: 'localhost', port: 6379, db: 0 }
24
+ }
21
25
  config.public_file_server.headers = {
22
26
  'Cache-Control' => "public, max-age=#{2.days.to_i}"
23
27
  }
@@ -44,18 +48,10 @@ Rails.application.configure do
44
48
  # Highlight code that triggered database queries in logs.
45
49
  config.active_record.verbose_query_logs = true
46
50
 
47
- # Debug mode disables concatenation and preprocessing of assets.
48
- # This option may cause significant delays in view rendering with a large
49
- # number of complex assets.
50
- config.assets.debug = true
51
-
52
- # Suppress logger output for asset requests.
53
- config.assets.quiet = true
54
-
55
51
  # Raises error for missing translations
56
52
  # config.action_view.raise_on_missing_translations = true
57
53
 
58
54
  # Use an evented file watcher to asynchronously detect changes in source code,
59
55
  # routes, locales, etc. This feature depends on the listen gem.
60
- # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
56
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
61
57
  end
@@ -22,15 +22,6 @@ Rails.application.configure do
22
22
  # Apache or NGINX already handles this.
23
23
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
24
24
 
25
- # Compress JavaScripts and CSS.
26
- config.assets.js_compressor = :uglifier
27
- # config.assets.css_compressor = :sass
28
-
29
- # Do not fallback to assets pipeline if a precompiled asset is missed.
30
- config.assets.compile = false
31
-
32
- # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
33
-
34
25
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
35
26
  # config.action_controller.asset_host = 'http://assets.example.com'
36
27
 
@@ -61,7 +52,7 @@ Rails.application.configure do
61
52
 
62
53
  # Use a real queuing backend for Active Job (and separate queues per environment)
63
54
  # config.active_job.queue_adapter = :resque
64
- # config.active_job.queue_name_prefix = "dummy_#{Rails.env}"
55
+ # config.active_job.queue_name_prefix = "used_models_#{Rails.env}"
65
56
 
66
57
  config.action_mailer.perform_caching = false
67
58
 
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Avoid CORS issues when API is called from the frontend app.
4
+ # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.
5
+
6
+ # Read more: https://github.com/cyu/rack-cors
7
+
8
+ # Rails.application.config.middleware.insert_before 0, Rack::Cors do
9
+ # allow do
10
+ # origins 'example.com'
11
+ #
12
+ # resource '*',
13
+ # headers: :any,
14
+ # methods: [:get, :post, :put, :patch, :delete, :options, :head]
15
+ # end
16
+ # end
@@ -1,33 +1,8 @@
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 http://guides.rubyonrails.org/i18n.html.
31
-
32
1
  en:
33
- hello: "Hello world"
2
+ application:
3
+ version: 1.0
4
+ name: "UsedModel Module"
5
+ description: "A module to manage UsedModel"
6
+ terms_of_service: "None"
7
+ contact_name: "AutoForce"
8
+ license: "MIT"
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- mount Apicasso::Engine => "/apicasso"
2
+ mount Apicasso::Engine, at: '/api/v1'
3
3
  end
@@ -3,6 +3,7 @@ class CreateApicassoTables < ActiveRecord::Migration[5.0]
3
3
  execute <<-SQL
4
4
  CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
5
5
  SQL
6
+
6
7
  create_table :apicasso_keys, id: :uuid do |t|
7
8
  t.json :scope
8
9
  t.integer :scope_type
@@ -0,0 +1,44 @@
1
+ class CreateUsedModels < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :used_models do |t|
4
+ t.boolean :active, default: true
5
+ t.integer :account_id
6
+ t.integer :unit_id
7
+ t.string :brand
8
+ t.string :name
9
+ t.string :slug
10
+ t.string :model
11
+ t.string :version
12
+ t.integer :model_year
13
+ t.string :production_year
14
+ t.string :kind
15
+ t.boolean :new_vehicle, default: false
16
+ t.string :old_price
17
+ t.integer :price_value
18
+ t.string :price
19
+ t.string :category
20
+ t.string :transmission
21
+ t.integer :km_value
22
+ t.string :km
23
+ t.string :plate
24
+ t.string :color
25
+ t.integer :doors
26
+ t.integer :fuel
27
+ t.string :fuel_text
28
+ t.text :note
29
+ t.string :chassis
30
+ t.boolean :shielded, default: false
31
+ t.boolean :featured, default: false
32
+ t.string :integrator
33
+ t.integer :ordination, default: 0
34
+ t.integer :visits, default: 0
35
+ t.integer :bait_id, default: 6
36
+ t.integer :fipe_id
37
+ t.string :identifier
38
+ t.string :synced_at
39
+ t.datetime :deleted_at
40
+
41
+ t.timestamps
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ # This migration comes from active_storage (originally 20170806125915)
2
+ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
3
+ def change
4
+ create_table :active_storage_blobs do |t|
5
+ t.string :key, null: false
6
+ t.string :filename, null: false
7
+ t.string :content_type
8
+ t.text :metadata
9
+ t.bigint :byte_size, null: false
10
+ t.string :checksum, null: false
11
+ t.datetime :created_at, null: false
12
+
13
+ t.index [ :key ], unique: true
14
+ end
15
+
16
+ create_table :active_storage_attachments do |t|
17
+ t.string :name, null: false
18
+ t.references :record, null: false, polymorphic: true, index: false
19
+ t.references :blob, null: false
20
+
21
+ t.datetime :created_at, null: false
22
+
23
+ t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ class ChangeUsedModelToValidates < ActiveRecord::Migration[5.2]
2
+ def change
3
+ change_column :used_models, :account_id, :integer, null: false
4
+ change_column :used_models, :unit_id, :integer, null: false
5
+ change_column :used_models, :slug, :string, null: false, unique: true
6
+ end
7
+ end
@@ -0,0 +1,98 @@
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
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2018_09_20_133933) do
14
+
15
+ # These are extensions that must be enabled in order to support this database
16
+ enable_extension "plpgsql"
17
+ enable_extension "uuid-ossp"
18
+
19
+ create_table "active_storage_attachments", force: :cascade do |t|
20
+ t.string "name", null: false
21
+ t.string "record_type", null: false
22
+ t.bigint "record_id", null: false
23
+ t.bigint "blob_id", null: false
24
+ t.datetime "created_at", null: false
25
+ t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
26
+ t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
27
+ end
28
+
29
+ create_table "active_storage_blobs", force: :cascade do |t|
30
+ t.string "key", null: false
31
+ t.string "filename", null: false
32
+ t.string "content_type"
33
+ t.text "metadata"
34
+ t.bigint "byte_size", null: false
35
+ t.string "checksum", null: false
36
+ t.datetime "created_at", null: false
37
+ t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
38
+ end
39
+
40
+ create_table "apicasso_keys", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t|
41
+ t.json "scope"
42
+ t.integer "scope_type"
43
+ t.json "request_limiting"
44
+ t.text "token"
45
+ t.datetime "deleted_at"
46
+ t.datetime "created_at", null: false
47
+ t.datetime "updated_at", null: false
48
+ end
49
+
50
+ create_table "apicasso_requests", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t|
51
+ t.text "api_key_id"
52
+ t.json "object"
53
+ t.datetime "created_at", null: false
54
+ t.datetime "updated_at", null: false
55
+ end
56
+
57
+ create_table "used_models", force: :cascade do |t|
58
+ t.boolean "active", default: true
59
+ t.integer "account_id", null: false
60
+ t.integer "unit_id", null: false
61
+ t.string "brand"
62
+ t.string "name"
63
+ t.string "slug", null: false
64
+ t.string "model"
65
+ t.string "version"
66
+ t.integer "model_year"
67
+ t.string "production_year"
68
+ t.string "kind"
69
+ t.boolean "new_vehicle", default: false
70
+ t.string "old_price"
71
+ t.integer "price_value"
72
+ t.string "price"
73
+ t.string "category"
74
+ t.string "transmission"
75
+ t.integer "km_value"
76
+ t.string "km"
77
+ t.string "plate"
78
+ t.string "color"
79
+ t.integer "doors"
80
+ t.integer "fuel"
81
+ t.string "fuel_text"
82
+ t.text "note"
83
+ t.string "chassis"
84
+ t.boolean "shielded", default: false
85
+ t.boolean "featured", default: false
86
+ t.string "integrator"
87
+ t.integer "ordination", default: 0
88
+ t.integer "visits", default: 0
89
+ t.integer "bait_id", default: 6
90
+ t.integer "fipe_id"
91
+ t.string "identifier"
92
+ t.string "synced_at"
93
+ t.datetime "deleted_at"
94
+ t.datetime "created_at", null: false
95
+ t.datetime "updated_at", null: false
96
+ end
97
+
98
+ end
@@ -0,0 +1,56 @@
1
+ require 'faker'
2
+
3
+ 9.times { UsedModel.create(
4
+ active: Faker::Boolean.boolean,
5
+ account_id: Faker::Number.number(1),
6
+ unit_id: Faker::Number.number(1),
7
+ brand: Faker::Vehicle.make,
8
+ name: Faker::Vehicle.model,
9
+ model: Faker::Vehicle.model,
10
+ version: Faker::Number.decimal(1, 1),
11
+ model_year: Faker::Vehicle.year,
12
+ production_year: Faker::Vehicle.year,
13
+ kind: 'car',
14
+ new_vehicle: Faker::Boolean.boolean,
15
+ old_price: Faker::Number.decimal(4, 2).to_s,
16
+ price_value: Faker::Number.decimal(4, 2),
17
+ price: Faker::Number.decimal(4, 2).to_s,
18
+ category: Faker::Vehicle.car_type,
19
+ transmission: Faker::Vehicle.transmission,
20
+ km_value: Faker::Number.number(8),
21
+ km: Faker::Number.number(8).to_s,
22
+ plate: Faker::Number.number(4),
23
+ color: Faker::Vehicle.color,
24
+ doors: Faker::Number.number(1),
25
+ fuel: Faker::Number.number(1),
26
+ fuel_text: Faker::Vehicle.fuel_type,
27
+ shielded: Faker::Boolean.boolean
28
+ )}
29
+
30
+ 1.times { UsedModel.create(
31
+ active: Faker::Boolean.boolean,
32
+ account_id: Faker::Number.number(1),
33
+ unit_id: Faker::Number.number(1),
34
+ slug: 'cr-v',
35
+ brand: Faker::Vehicle.make,
36
+ name: Faker::Vehicle.model,
37
+ model: Faker::Vehicle.model,
38
+ version: Faker::Number.decimal(1, 1),
39
+ model_year: Faker::Vehicle.year,
40
+ production_year: Faker::Vehicle.year,
41
+ kind: 'car',
42
+ new_vehicle: Faker::Boolean.boolean,
43
+ old_price: Faker::Number.decimal(4, 2).to_s,
44
+ price_value: Faker::Number.decimal(4, 2),
45
+ price: Faker::Number.decimal(4, 2).to_s,
46
+ category: Faker::Vehicle.car_type,
47
+ transmission: Faker::Vehicle.transmission,
48
+ km_value: Faker::Number.number(8),
49
+ km: Faker::Number.number(8).to_s,
50
+ plate: Faker::Number.number(4),
51
+ color: Faker::Vehicle.color,
52
+ doors: Faker::Number.number(1),
53
+ fuel: Faker::Number.number(1),
54
+ fuel_text: Faker::Vehicle.fuel_type,
55
+ shielded: Faker::Boolean.boolean
56
+ )}
@@ -0,0 +1,28 @@
1
+ FactoryBot.define do
2
+ factory :used_model do
3
+ active { Faker::Boolean.boolean }
4
+ account_id { Faker::Number.number(1) }
5
+ unit_id { Faker::Number.number(1) }
6
+ brand { Faker::Vehicle.make }
7
+ name { Faker::Vehicle.make_and_model }
8
+ model { Faker::Vehicle.model }
9
+ version { Faker::Number.decimal(1, 1) }
10
+ model_year { Faker::Vehicle.year }
11
+ production_year { Faker::Vehicle.year }
12
+ kind { 'car' }
13
+ new_vehicle { Faker::Boolean.boolean }
14
+ old_price { Faker::Number.decimal(4, 2) }.to_s
15
+ price_value { Faker::Number.decimal(4, 2) }
16
+ price { Faker::Number.decimal(4, 2) }.to_s
17
+ category { Faker::Vehicle.car_type }
18
+ transmission { Faker::Vehicle.transmission }
19
+ km_value { Faker::Number.number(8) }
20
+ km { Faker::Number.number(8) }
21
+ plate { Faker::Number.number(4) }
22
+ color { Faker::Vehicle.color }
23
+ doors { Faker::Number.number(1) }
24
+ fuel { Faker::Number.number(1) }
25
+ fuel_text { Faker::Vehicle.fuel_type }
26
+ shielded { Faker::Boolean.boolean }
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe UsedModel, type: :model do
6
+ context 'validations' do
7
+ it 'is valid with valid attributes' do
8
+ expect(build :used_model).to be_valid
9
+ end
10
+ it 'is invalid with slug duplicate' do
11
+ used_model = build(:used_model)
12
+ used_model.slug = 'duplicate'
13
+ used_model.save
14
+
15
+ used_model_dup = build(:used_model)
16
+ used_model_dup.slug = 'duplicate'
17
+ expect { used_model_dup.save! }.to raise_exception ActiveRecord::RecordInvalid
18
+ end
19
+ it 'is invalid without valid slug attribute' do
20
+ used_model = build(:used_model)
21
+ used_model.slug = ''
22
+ expect { used_model.save! }.to raise_exception ActiveRecord::RecordInvalid
23
+ end
24
+ it 'is invalid without valid account_id attribute' do
25
+ used_model = build(:used_model)
26
+ used_model.account_id = nil
27
+ expect { used_model.save! }.to raise_exception ActiveRecord::RecordInvalid
28
+ end
29
+ it 'is invalid without valid unit_id attribute' do
30
+ used_model = build(:used_model)
31
+ used_model.unit_id = nil
32
+ expect { used_model.save! }.to raise_exception ActiveRecord::RecordInvalid
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,66 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+
4
+ ENV['RAILS_ENV'] ||= 'test'
5
+ require File.expand_path('../../spec/dummy/config/environment', __FILE__)
6
+ # Prevent database truncation if the environment is production
7
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
8
+ require 'rspec/rails'
9
+ # # Add additional requires below this line. Rails is not loaded until this point!
10
+ # RSpec.configure do |config|
11
+ # config.include FactoryBot::Syntax::Methods
12
+ # end
13
+ # Requires supporting ruby files with custom matchers and macros, etc, in
14
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
15
+ # run as spec files by default. This means that files in spec/support that end
16
+ # in _spec.rb will both be required and run as specs, causing the specs to be
17
+ # run twice. It is recommended that you do not name files matching this glob to
18
+ # end with _spec.rb. You can configure this pattern with the --pattern
19
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
20
+ #
21
+ # The following line is provided for convenience purposes. It has the downside
22
+ # of increasing the boot-up time by auto-requiring all files in the support
23
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
24
+ # require only the support files necessary.
25
+ #
26
+ # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
27
+
28
+ # Checks for pending migrations and applies them before tests are run.
29
+ # # If you are not using ActiveRecord, you can remove these lines.
30
+
31
+ # begin
32
+ # ActiveRecord::Migration.maintain_test_schema!
33
+ # rescue ActiveRecord::PendingMigrationError => e
34
+ # puts e.to_s.strip
35
+ # exit 1
36
+ # end
37
+ RSpec.configure do |config|
38
+ # config.include ApicassoHelper
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
+ # RSpec Rails can automatically mix in different behaviours to your tests
48
+ # based on their file location, for example enabling you to call `get` and
49
+ # `post` in specs under `spec/controllers`.
50
+ #
51
+ # You can disable this behaviour by removing the line below, and instead
52
+ # explicitly tag your specs with their type, e.g.:
53
+ #
54
+ # RSpec.describe UsersController, :type => :controller do
55
+ # # ...
56
+ # end
57
+ #
58
+ # The different available types are documented in the features, such as in
59
+ # https://relishapp.com/rspec/rspec-rails/docs
60
+ config.infer_spec_type_from_file_location!
61
+
62
+ # Filter lines from Rails gems in backtraces.
63
+ config.filter_rails_from_backtrace!
64
+ # arbitrary gems may also be filtered via:
65
+ # config.filter_gems_from_backtrace("gem name")
66
+ end