Skip to content

Commit

Permalink
Merge pull request #1134 from internetee/create-auction-whois-record-…
Browse files Browse the repository at this point in the history
…if-they-do-not-exist

On status update, create WHOIS records for domains in auction
  • Loading branch information
vohmar authored Apr 1, 2019
2 parents f35b2dc + e9a39bd commit 26dac12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/controllers/api/v1/auctions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def serializable_hash_for_update_action(auction)
end

def update_whois_from_auction(auction)
whois_record = Whois::Record.find_by!(name: auction.domain)
whois_record = Whois::Record.find_or_create_by(name: auction.domain) do |record|
record.json = {}
end

whois_record.update_from_auction(auction)
end
end
Expand Down
1 change: 0 additions & 1 deletion db/whois_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

create_table "whois_records", force: :cascade do |t|
t.string "name"
t.text "body"
t.json "json"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down
15 changes: 14 additions & 1 deletion test/integration/api/v1/auctions/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ def test_updates_whois
assert_equal Time.zone.parse('2010-07-05 10:00'), @whois_record.updated_at
end

def test_creates_whois_record_if_does_not_exist
travel_to Time.zone.parse('2010-07-05 10:00')
assert_equal 'auction.test', @auction.domain
@whois_record.delete

patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
.to_json, 'Content-Type' => Mime::JSON.to_s

new_whois_record = Whois::Record.find_by(name: @auction.domain)
assert_equal Time.zone.parse('2010-07-05 10:00'), new_whois_record.updated_at
assert_equal ['PendingRegistration'], new_whois_record.json['status']
end

def test_inaccessible_when_ip_address_is_not_allowed
ENV['auction_api_allowed_ips'] = ''

Expand All @@ -113,4 +126,4 @@ def test_auction_not_found
'Content-Type' => Mime::JSON.to_s
end
end
end
end

0 comments on commit 26dac12

Please sign in to comment.