Skip to content

Commit c913697

Browse files
committed
test(dummy-app): add ransackable attrs and associations
Now required in AA v3 / Ransack v4
1 parent 070c754 commit c913697

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

spec/dummy/app/models/category.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
class Category < ActiveRecord::Base
22
has_many :invoices
3+
34
def shiny_name
45
"My shiny #{name}"
56
end
7+
8+
def self.ransackable_attributes(_auth_object = nil)
9+
["created_at", "description", "id", "name", "updated_at"]
10+
end
11+
12+
def self.ransackable_associations(_auth_object = nil)
13+
["invoices"]
14+
end
615
end

spec/dummy/app/models/city.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
class City < ActiveRecord::Base
22
belongs_to :region
3+
has_many :departments_cities, dependent: :destroy
4+
has_many :departments, through: :departments_cities
5+
6+
def self.ransackable_attributes(_auth_object = nil)
7+
["created_at", "id", "information", "name", "region_id", "updated_at"]
8+
end
9+
10+
def self.ransackable_associations(_auth_object = nil)
11+
["region", "deparments_cities", "departments"]
12+
end
313
end

spec/dummy/app/models/country.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
class Country < ActiveRecord::Base
2+
has_many :regions, dependent: :destroy
3+
has_many :cities, through: :regions
4+
5+
def self.ransackable_attributes(_auth_object = nil)
6+
["created_at", "id", "information", "name", "updated_at"]
7+
end
8+
9+
def self.ransackable_associations(_auth_object = nil)
10+
["regions", "cities"]
11+
end
212
end

spec/dummy/app/models/invoice.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,18 @@ def self.colors
9292
def set_default_state
9393
self.state ||= 'pending'
9494
end
95+
96+
def self.ransackable_attributes(_auth_object = nil)
97+
[
98+
"aasm_state", "active", "amount", "attachment_content_type", "attachment_file_name",
99+
"attachment_file_size", "attachment_updated_at", "category_id", "city_id", "client_id",
100+
"color", "created_at", "description", "id", "legal_date", "number", "paid",
101+
"photo_content_type", "photo_file_name", "photo_file_size", "photo_updated_at",
102+
"picture_data", "position", "shipping_status", "state", "status", "updated_at"
103+
]
104+
end
105+
106+
def self.ransackable_associations(_auth_object = nil)
107+
["category", "city", "items", "other_items"]
108+
end
95109
end

spec/dummy/app/models/item.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ class Item < ActiveRecord::Base
44
def full_name
55
"##{id} - #{name}"
66
end
7+
8+
def self.ransackable_attributes(_auth_object = nil)
9+
["created_at", "description", "id", "name", "updated_at"]
10+
end
11+
12+
def self.ransackable_associations(_auth_object = nil)
13+
["invoices"]
14+
end
715
end

spec/dummy/app/models/region.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
class Region < ActiveRecord::Base
22
belongs_to :country
3+
has_many :cities, dependent: :destroy
4+
5+
def self.ransackable_attributes(_auth_object = nil)
6+
["country_id", "created_at", "id", "information", "name", "updated_at"]
7+
end
8+
9+
def self.ransackable_associations(_auth_object = nil)
10+
["country", "cities"]
11+
end
312
end

0 commit comments

Comments
 (0)