Skip to content

Commit ef8866f

Browse files
authored
add possibility to customize the name of the menu (Issue: #155) (#140)
* merged master * Revert "merged master" This reverts commit dc73e8f. * add menu_alias for companies and remove menu alias attribute from owners, adjust tests * change migration to add nod default value and update schema.rb * change migration to migrate existing menu_alias data
1 parent 33c9d56 commit ef8866f

File tree

9 files changed

+47
-29
lines changed

9 files changed

+47
-29
lines changed

app/controllers/owners/companies_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def stats
4343
private
4444

4545
def company_params
46-
params.require(:company).permit(:name, :street, :zip, :city, :menu_link, :menu_pdf, :remove_menu_pdf, :privacy_policy_link, :need_to_show_corona_test, :location_type, :cwa_link_enabled, :cwa_crypto_seed)
46+
params.require(:company).permit(:name, :street, :zip, :city, :menu_link, :menu_alias, :menu_pdf, :remove_menu_pdf, :privacy_policy_link, :need_to_show_corona_test, :location_type, :cwa_link_enabled, :cwa_crypto_seed)
4747
end
4848

4949
def authenticate_owner_with_api_token

app/models/area.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Area < ApplicationRecord
22
include ApiSerializable
33
include RailsAdminConfig::ForArea
44

5-
EXPOSED_ATTRIBUTES = %i[id name menu_link checkin_link company_id company_name company_need_to_show_corona_test company_cwa_link_enabled affiliate_logo owner_is_blocked menu_alias frontend_url public_key privacy_policy_link test_exemption].freeze
5+
EXPOSED_ATTRIBUTES = %i[id name menu_link menu_alias checkin_link company_id company_name company_need_to_show_corona_test company_cwa_link_enabled affiliate_logo owner_is_blocked frontend_url public_key privacy_policy_link test_exemption].freeze
66

77
belongs_to :company
88
has_many :tickets, dependent: :destroy

app/models/company.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ class Company < ApplicationRecord
55

66
enum location_type: [
77
:other,
8-
:retail,
9-
:food_service,
10-
:craft,
11-
:workplace,
12-
:educational_institution,
8+
:retail,
9+
:food_service,
10+
:craft,
11+
:workplace,
12+
:educational_institution,
1313
:public_building
1414
], _prefix: 'location'
1515

@@ -19,7 +19,8 @@ class Company < ApplicationRecord
1919
street
2020
zip
2121
city
22-
menu_link
22+
menu_link
23+
menu_alias
2324
areas
2425
menu_pdf_link
2526
privacy_policy_link
@@ -45,7 +46,7 @@ class Company < ApplicationRecord
4546
joins(:owner).where("coalesce(companies.zip, '') = '' and coalesce(owners.affiliate, '') = ''")
4647
}
4748

48-
delegate :menu_alias, :frontend_url, :public_key, to: :owner
49+
delegate :frontend_url, :public_key, to: :owner
4950
delegate :affiliate_logo, to: :owner
5051
delegate :auto_checkout_time, to: :owner
5152
delegate :affiliate, to: :owner, allow_nil: true
@@ -88,7 +89,7 @@ def address
8889
"#{street}, #{zip} #{city}"
8990
end
9091

91-
def affiliate=(code)
92+
def affiliate=(code)
9293
self.owner.update(affiliate: code)
9394
end
9495

app/models/concerns/rails_admin_config/for_owner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module ForOwner
55
included do
66
rails_admin do
77
fields :id, :email, :created_at, :name, :street, :zip, :city, :companies, :affiliate, :phone, :company_name, :can_use_for_free, :trial_ends_at,
8-
:block_at, :frontend, :stripe_subscription_id, :stripe_customer_id, :menu_alias
8+
:block_at, :frontend, :stripe_subscription_id, :stripe_customer_id
99

1010
field :stripe_subscription_status do
1111
read_only true

app/models/owner.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ class Owner < ApplicationRecord
33
include RailsAdminConfig::ForOwner
44

55
EXPOSED_ATTRIBUTES = %i[id email name phone company_name street zip city public_key affiliate stripe_subscription_status
6-
can_use_for_free trial_ends_at frontend_url block_at menu_alias]
6+
can_use_for_free trial_ends_at frontend_url block_at]
77

88
devise :database_authenticatable, :jwt_authenticatable, :registerable,
99
:confirmable, :recoverable, jwt_revocation_strategy: JwtDenylist
1010

1111
validates :email, uniqueness: true, presence: true
12-
validates :password,
13-
presence: true,
14-
length: { in: Devise.password_length },
15-
confirmation: true,
16-
on: :create
17-
18-
validates :password,
19-
allow_nil: true,
20-
length: { in: Devise.password_length },
21-
confirmation: true,
12+
validates :password,
13+
presence: true,
14+
length: { in: Devise.password_length },
15+
confirmation: true,
16+
on: :create
17+
18+
validates :password,
19+
allow_nil: true,
20+
length: { in: Devise.password_length },
21+
confirmation: true,
2222
on: :update
2323

2424
scope :affiliate, -> { where.not(affiliate: [nil, '']).order(affiliate: :asc) }
@@ -50,7 +50,7 @@ def blocked?
5050

5151
def affiliate_logo
5252
return unless affiliate
53-
53+
5454
Affiliate.find_by(code: affiliate)&.logo_url
5555
end
5656

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class AddMenuNameForCompany < ActiveRecord::Migration[6.1]
2+
def up
3+
add_column :companies, :menu_alias, :string
4+
Owner.all.each do|owner|
5+
owner.companies.each { |company| company.update(menu_alias: owner.menu_alias) } if owner.menu_alias
6+
end
7+
remove_column :owners, :menu_alias
8+
end
9+
def down
10+
add_column :owners, :menu_alias, :string
11+
Owner.all.each do|owner|
12+
companies_with_menu_alias = owner.companies.filter{ |company| company.menu_alias.present? }
13+
owner.update(menu_alias: companies_with_menu_alias.first.menu_alias) if companies_with_menu_alias.present?
14+
end
15+
remove_column :companies, :menu_alias, :string
16+
end
17+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2021_06_10_105453) do
13+
ActiveRecord::Schema.define(version: 2021_07_05_084018) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "pgcrypto"
@@ -76,6 +76,7 @@
7676
t.integer "location_type", default: 0
7777
t.boolean "cwa_link_enabled", default: false
7878
t.string "cwa_crypto_seed"
79+
t.string "menu_alias"
7980
t.index ["owner_id"], name: "index_companies_on_owner_id"
8081
end
8182

@@ -126,7 +127,6 @@
126127
t.bigint "frontend_id"
127128
t.string "api_token"
128129
t.integer "auto_checkout_minutes"
129-
t.string "menu_alias"
130130
t.string "phone"
131131
t.string "company_name"
132132
t.string "street"

spec/requests/owners/companies_request_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
include_context 'api request authentication'
55

66
let(:owner) { FactoryBot.create(:owner) }
7-
7+
88
before do
99
sign_in(owner)
1010
end
@@ -14,7 +14,7 @@
1414
FactoryBot.create(:company, owner: owner)
1515
#FactoryBot.create(:company)
1616

17-
get(owners_companies_path)
17+
get(owners_companies_path)
1818
end
1919

2020
it 'Has the correct http status' do
@@ -34,7 +34,7 @@
3434
end
3535

3636
subject do
37-
-> { post owners_companies_path, params: { company: {name: "Acme Inc", street: "Strasse 1", zip: "12345", city: "Exampletown", need_to_show_corona_test: 24}} }
37+
-> { post owners_companies_path, params: { company: {name: "Acme Inc", street: "Strasse 1", zip: "12345", city: "Exampletown", menu_alias: "Speisekarte", need_to_show_corona_test: 24}} }
3838
end
3939

4040
it "creates a new company" do
@@ -48,6 +48,7 @@
4848
expect(company.street).to eq("Strasse 1")
4949
expect(company.zip).to eq("12345")
5050
expect(company.city).to eq("Exampletown")
51+
expect(company.menu_alias).to eq("Speisekarte")
5152
expect(company.need_to_show_corona_test).to be(24)
5253
end
5354

spec/requests/owners/owner_request_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
expect(json["trial_ends_at"]).to eq(owner.trial_ends_at)
3131
expect(json["block_at"]).to eq(owner.block_at)
3232
expect(json["can_use_for_free"]).to eq(owner.can_use_for_free)
33-
expect(json["menu_alias"]).to eq(owner.menu_alias)
3433
end
3534
end
3635

0 commit comments

Comments
 (0)