diff --git a/lib/discourse_data_explorer/parameter.rb b/lib/discourse_data_explorer/parameter.rb index b34d4ec..da9a260 100644 --- a/lib/discourse_data_explorer/parameter.rb +++ b/lib/discourse_data_explorer/parameter.rb @@ -4,7 +4,7 @@ module ::DiscourseDataExplorer class Parameter attr_accessor :identifier, :type, :default, :nullable - def initialize(identifier, type, default, nullable) + def initialize(identifier, type, default, nullable, validate: true) unless identifier raise ValidationError.new("Parameter declaration error - identifier is missing") end @@ -25,7 +25,7 @@ module ::DiscourseDataExplorer @default = default @nullable = nullable begin - cast_to_ruby default if default.present? + cast_to_ruby default if default.present? && validate rescue ValidationError raise ValidationError.new( "Parameter declaration error - the default value is not a valid #{type}", @@ -89,7 +89,7 @@ module ::DiscourseDataExplorer type = type.strip begin - ret_params << Parameter.new(ident, type, default, nullable) + ret_params << Parameter.new(ident, type, default, nullable, validate: opts[:strict]) rescue StandardError raise if opts[:strict] end diff --git a/spec/lib/parameter_spec.rb b/spec/lib/parameter_spec.rb index 5acbded..20cd170 100644 --- a/spec/lib/parameter_spec.rb +++ b/spec/lib/parameter_spec.rb @@ -77,4 +77,22 @@ RSpec.describe DiscourseDataExplorer::Parameter do end end end + + describe ".create_from_sql" do + it "should not validate default value" do + TEST_SQL = <<~SQL + -- [params] + -- user_id :user_id = user_not_exists + -- post_id :post_id = /t/should-not-exist/33554432/1 + -- topic_id :topic_id = /t/should-not-exist/2147483646 + -- category_id :category_id = category_not_exists + -- group_id :group_id = group_not_exists + -- group_list :group_list = group_not_exists1,group_not_exists1 + -- user_list :mul_users = user_not_exists1,user_not_exists2 + SELECT 1 + SQL + + expect(described_class.create_from_sql(TEST_SQL).length).to eq(7) + end + end end