<commit_before>require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'

describe Input do
 it 'can be given a fixed value' do
   i=Input.new{fixed 6}
   i.value.should eql 6
   i.fixed?.should be_true
   lambda{i.value 7}.should raise_error Exceptions::FixedValueInterference
 end
 it 'raises exception when invalid' do
   i=Input.new{validation /bark/}
   i.value 'barking'
   lambda{i.validate!}.should_not raise_error
   i.value.should eql 'barking'
   i.value 'marking'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
   j=Input.new{}
   j.value 'marking'
   j.value.should eql 'marking'
 end
 it "can accept a numeric symbol validation" do
   i=Input.new{validation :numeric}
   i.value 3
   lambda{i.validate!}.should_not raise_error
   i.value '3'
   lambda{i.validate!}.should_not raise_error
   i.value 'e'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
 end
 it "can accept a date symbol validation" do
   i=Input.new{validation :date}
   i.value Date.today
   lambda{i.validate!}.should_not raise_error
   i.value '2011-01-01'
   lambda{i.validate!}.should_not raise_error
   i.value 'e'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
 end

 it "can accept a time symbol validation" do
   i=Input.new{validation :datetime}
   i.value DateTime.now
   lambda{i.validate!}.should_not raise_error
   i.value '2011-01-01 09:00:00'
   lambda{i.validate!}.should_not raise_error
   i.value 'e'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
 end
 it 'can have custom validation message' do
   i=Input.new{label :woof; validation /bark/; validation_message {"#{value} does not match pattern /bark/"}}
   i.value 'marking'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"marking does not match pattern /bark/"
   j=Input.new{}
   j.value 'marking'
   j.value.should eql 'marking'
 end
 it 'can have default validation message' do
   i=Input.new{label :woof; validation /bark/}
   i.value 'barking'
   lambda{i.validate!}.should_not raise_error
   i.value.should eql 'barking'
   i.value 'marking'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"Woof is invalid."
   j=Input.new{}
   j.value 'marking'
   j.value.should eql 'marking'
 end
 it 'is always valid if it is fixed' do
   i=Input.new{fixed 5; validation /7/}
   lambda{i.validate!}.should_not raise_error
   i.value.should eql 5
 end
 it 'is always disabled if it is fixed' do
   i=Input.new{fixed 5}
   i.disabled?.should eql true
 end
end<commit_msg>Add specs to cover dirty tracking on input [AC-150]<commit_after>require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'

describe Input do
 it 'can be given a fixed value' do
   i=Input.new{fixed 6}
   i.value.should eql 6
   i.fixed?.should be_true
   lambda{i.value 7}.should raise_error Exceptions::FixedValueInterference
 end
 it 'raises exception when invalid' do
   i=Input.new{validation /bark/}
   i.value 'barking'
   lambda{i.validate!}.should_not raise_error
   i.value.should eql 'barking'
   i.value 'marking'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
   j=Input.new{}
   j.value 'marking'
   j.value.should eql 'marking'
 end
 it "can accept a numeric symbol validation" do
   i=Input.new{validation :numeric}
   i.value 3
   lambda{i.validate!}.should_not raise_error
   i.value '3'
   lambda{i.validate!}.should_not raise_error
   i.value 'e'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
 end
 it "can accept a date symbol validation" do
   i=Input.new{validation :date}
   i.value Date.today
   lambda{i.validate!}.should_not raise_error
   i.value '2011-01-01'
   lambda{i.validate!}.should_not raise_error
   i.value 'e'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
 end

 it "can accept a time symbol validation" do
   i=Input.new{validation :datetime}
   i.value DateTime.now
   lambda{i.validate!}.should_not raise_error
   i.value '2011-01-01 09:00:00'
   lambda{i.validate!}.should_not raise_error
   i.value 'e'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
 end
 it 'can have custom validation message' do
   i=Input.new{label :woof; validation /bark/; validation_message {"#{value} does not match pattern /bark/"}}
   i.value 'marking'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"marking does not match pattern /bark/"
   j=Input.new{}
   j.value 'marking'
   j.value.should eql 'marking'
 end
 it 'can have default validation message' do
   i=Input.new{label :woof; validation /bark/}
   i.value 'barking'
   lambda{i.validate!}.should_not raise_error
   i.value.should eql 'barking'
   i.value 'marking'
   lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"Woof is invalid."
   j=Input.new{}
   j.value 'marking'
   j.value.should eql 'marking'
 end
 it 'is always valid if it is fixed' do
   i=Input.new{fixed 5; validation /7/}
   lambda{i.validate!}.should_not raise_error
   i.value.should eql 5
 end
 it 'is always disabled if it is fixed' do
   i=Input.new{fixed 5}
   i.disabled?.should eql true
 end
 it "should start with dirty set as false" do
   i=Input.new{fixed 5}
   i.dirty?.should eql false
 end
 it "should be dirty when the value is changed" do
   i=Input.new
   i.value 5
   i.dirty?.should eql true
 end
end
{'fraction_non_alphanumeric': 0.11181277860326895, 'fraction_numerical': 0.012444279346210995, 'mean_word_length': 3.931318681318681, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3856844', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1808, 'n_words': 495}