standardapi 6.0.0.24 → 6.0.0.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,100 @@
1
+ # = Models
2
+
3
+ class Account < ActiveRecord::Base
4
+ has_many :photos
5
+ belongs_to :property
6
+ end
7
+
8
+ class Photo < ActiveRecord::Base
9
+ belongs_to :account, :counter_cache => true
10
+ has_and_belongs_to_many :properties
11
+ end
12
+
13
+ class Document < ActiveRecord::Base
14
+ attr_accessor :file
15
+ end
16
+
17
+ class Pdf < Document
18
+ end
19
+
20
+ class Property < ActiveRecord::Base
21
+ has_and_belongs_to_many :landlords
22
+ has_and_belongs_to_many :photos
23
+ has_many :accounts
24
+ has_one :landlord, class_name: 'Account'
25
+
26
+
27
+ validates :name, presence: true
28
+ accepts_nested_attributes_for :photos
29
+
30
+ def english_name
31
+ 'A Name'
32
+ end
33
+ end
34
+
35
+ # TODO: Remove, not sure why this is here and not just using account.
36
+ class Landlord < ActiveRecord::Base
37
+ has_and_belongs_to_many :properties
38
+ end
39
+
40
+ class Reference < ActiveRecord::Base
41
+ belongs_to :subject, polymorphic: true
42
+ end
43
+
44
+ # = Migration
45
+
46
+ class CreateModelTables < ActiveRecord::Migration[5.2]
47
+
48
+ def self.up
49
+
50
+ create_table "accounts", force: :cascade do |t|
51
+ t.string 'name', limit: 255
52
+ t.integer 'property_id'
53
+ t.integer 'photos_count', null: false, default: 0
54
+ end
55
+
56
+ create_table "landlords", force: :cascade do |t|
57
+ t.string "name"
58
+ end
59
+
60
+ create_table "photos", force: :cascade do |t|
61
+ t.integer "account_id"
62
+ t.integer "property_id"
63
+ t.string "format", limit: 255
64
+ end
65
+
66
+ create_table "properties", force: :cascade do |t|
67
+ t.string "name", limit: 255
68
+ t.string "aliases", default: [], array: true
69
+ t.text "description"
70
+ t.integer "constructed"
71
+ t.decimal "size"
72
+ t.datetime "created_at", null: false
73
+ t.boolean "active", default: false
74
+ end
75
+
76
+ create_table "references", force: :cascade do |t|
77
+ t.integer "subject_id"
78
+ t.string "subject_type", limit: 255
79
+ t.string "key"
80
+ t.string "value"
81
+ end
82
+
83
+ create_table "photos_properties", force: :cascade do |t|
84
+ t.integer "photo_id"
85
+ t.integer "property_id"
86
+ end
87
+
88
+ create_table "landlords_properties", force: :cascade do |t|
89
+ t.integer "landlord_id"
90
+ t.integer "property_id"
91
+ end
92
+
93
+ create_table "documents", force: :cascade do |t|
94
+ t.string 'type'
95
+ end
96
+ end
97
+
98
+ end
99
+ ActiveRecord::Migration.verbose = false
100
+ CreateModelTables.up
@@ -0,0 +1,50 @@
1
+ FactoryBot.define do
2
+ factory :account do
3
+ name { Faker::Name.name }
4
+
5
+ trait(:nested) { }
6
+ trait(:invalid) do
7
+ name { nil }
8
+ end
9
+ end
10
+
11
+ factory :landlord do
12
+ name { Faker::Name.name }
13
+ end
14
+
15
+ factory :photo do
16
+ format { ['jpg', 'png', 'tiff'].sample }
17
+ end
18
+
19
+ factory :document do
20
+ file { fixture_file_upload(Rails.root + 'test/fixtures/photo.png', 'image/png') }
21
+ end
22
+
23
+ factory :pdf do
24
+ type { 'Pdf' }
25
+ file { fixture_file_upload(Rails.root + 'test/fixtures/photo.png', 'image/png') }
26
+ end
27
+
28
+ factory :reference do
29
+ subject_type { 'Photo' }
30
+ subject_id { create(:photo).id }
31
+ end
32
+
33
+ factory :property do
34
+ name { Faker::Lorem.words(number: Kernel.rand(1..4)).join(' ') }
35
+ description { Faker::Lorem.paragraphs.join("\n\n") }
36
+ constructed { Kernel.rand(1800..(Time.now.year - 2)) }
37
+ size { Kernel.rand(1000..10000000).to_f / 100 }
38
+ active { [true, false].sample }
39
+ photos { [create(:photo)] }
40
+
41
+ trait(:nested) do
42
+ photos_attributes { [attributes_for(:photo)] }
43
+ end
44
+
45
+ trait(:invalid) do
46
+ name { nil }
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,15 @@
1
+ json.set! :id, photo.id
2
+ json.set! :account_id, photo.account_id
3
+ json.set! :property_id, photo.property_id
4
+ json.set! :format, photo.format
5
+ json.set! :template, 'photos/_photo'
6
+
7
+ if includes[:account]
8
+ json.set! :account do
9
+ if photo.account
10
+ json.partial! 'application/record', record: photo.account, includes: includes[:account]
11
+ else
12
+ json.null!
13
+ end
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ json.set! 'template', 'photos/schema'
@@ -0,0 +1 @@
1
+ properties#edit.html
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standardapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.24
4
+ version: 6.0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bracy
@@ -273,6 +273,17 @@ files:
273
273
  - lib/standard_api/views/application/schema.streamer
274
274
  - lib/standard_api/views/application/show.json.jbuilder
275
275
  - lib/standard_api/views/application/show.streamer
276
+ - test/standard_api/test_app.rb
277
+ - test/standard_api/test_app/config/database.yml
278
+ - test/standard_api/test_app/controllers.rb
279
+ - test/standard_api/test_app/log/test.log
280
+ - test/standard_api/test_app/models.rb
281
+ - test/standard_api/test_app/test/factories.rb
282
+ - test/standard_api/test_app/test/fixtures/photo.png
283
+ - test/standard_api/test_app/views/photos/_photo.json.jbuilder
284
+ - test/standard_api/test_app/views/photos/schema.json.jbuilder
285
+ - test/standard_api/test_app/views/properties/edit.html.erb
286
+ - test/standard_api/test_app/views/sessions/new.html.erb
276
287
  homepage: https://github.com/waratuman/standardapi
277
288
  licenses:
278
289
  - MIT
@@ -283,6 +294,7 @@ rdoc_options:
283
294
  - README.md
284
295
  require_paths:
285
296
  - lib
297
+ - test
286
298
  required_ruby_version: !ruby/object:Gem::Requirement
287
299
  requirements:
288
300
  - - ">="