-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user_unique_id to free domain reservation
- Add user_unique_id to ReservedDomain.reserve_domains_without_payment response - Create FreeDomainReservationHolder with unique ID for free domain reservations - Add error handling for case when no domains are available - Update tests to cover new functionality and error cases - Increase unique ID length from 8 to 10 characters This change adds tracking of free domain reservations through unique IDs and improves error handling when no domains are available for reservation.
- Loading branch information
1 parent
f739781
commit 9467854
Showing
9 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class FreeDomainReservationHolder < ApplicationRecord | ||
before_validation :set_user_unique_id | ||
validates :user_unique_id, presence: true, uniqueness: true | ||
|
||
def reserved_domains | ||
ReservedDomain.where(name: domain_names) | ||
end | ||
|
||
private | ||
|
||
def set_user_unique_id | ||
self.user_unique_id = SecureRandom.uuid[0..9] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
db/migrate/20241206085817_create_free_domain_reservation_holders.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateFreeDomainReservationHolders < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :free_domain_reservation_holders do |t| | ||
t.string :user_unique_id, null: false, unique: true | ||
t.string :domain_names, array: true, default: [] | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'test_helper' | ||
|
||
class FreeDomainReservationHolderTest < ActiveSupport::TestCase | ||
def setup | ||
@holder = FreeDomainReservationHolder.create!(domain_names: ['example1.test', 'example2.test']) | ||
end | ||
|
||
test "should be valid with valid attributes" do | ||
holder = FreeDomainReservationHolder.new( | ||
domain_names: ['example1.test', 'example2.test'] | ||
) | ||
assert holder.valid? | ||
end | ||
|
||
test "should generate user_unique_id before create" do | ||
holder = FreeDomainReservationHolder.create( | ||
domain_names: ['example.test'] | ||
) | ||
assert_not_nil holder.user_unique_id | ||
assert_equal 10, holder.user_unique_id.length | ||
end | ||
|
||
|
||
test "should have many reserved domains" do | ||
holder = FreeDomainReservationHolder.create( | ||
domain_names: ['example.test'] | ||
) | ||
reserved_domain = ReservedDomain.create( | ||
name: 'example.test', | ||
) | ||
assert_includes holder.reserved_domains, reserved_domain | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters