Skip to content

Commit

Permalink
Ensure the EssencePage id regexp matches only numbers
Browse files Browse the repository at this point in the history
The former regexp matches any string containing a number, but
we want to only match numbers.
  • Loading branch information
tvdeyen committed Oct 16, 2019
1 parent ae4eb9e commit 8f4a8e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/models/alchemy/essence_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Alchemy
class EssencePage < BaseRecord
PAGE_ID = /\A\d+\z/

acts_as_essence(
ingredient_column: :page,
preview_text_method: :name
Expand All @@ -11,7 +13,7 @@ class EssencePage < BaseRecord

def ingredient=(page)
case page
when /\d/
when PAGE_ID
self.page = Alchemy::Page.new(id: page)
when Alchemy::Page
self.page = page
Expand Down
6 changes: 3 additions & 3 deletions spec/models/alchemy/essence_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
describe 'ingredient=' do
subject(:ingredient) { essence.page }

context 'when value is a String matching a number' do
context 'when String value is only a number' do
let(:value) { '101' }

before do
Expand All @@ -39,8 +39,8 @@
end
end

context 'when value is something else' do
let(:value) { 'something' }
context 'when value is not only a number' do
let(:value) { 'page1' }

it do
expect {
Expand Down

0 comments on commit 8f4a8e6

Please sign in to comment.