-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added regexp for validating postgres arrays and specs for the regexp
- Loading branch information
Showing
8 changed files
with
80 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
*.gem | ||
.bundle | ||
Gemfile.lock |
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,2 @@ | ||
--color | ||
--format progress |
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,3 @@ | ||
source :rubygems | ||
|
||
gemspec |
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,13 @@ | ||
#!/usr/bin/env rake | ||
begin | ||
require 'bundler/setup' | ||
rescue LoadError | ||
puts 'You must `gem install bundler` and `bundle install` to run rake tasks' | ||
end | ||
|
||
Bundler::GemHelper.install_tasks | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new | ||
|
||
task :default => :spec |
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,5 @@ | ||
RSpec.configure do |config| | ||
config.treat_symbols_as_metadata_keys_with_true_values = true | ||
config.run_all_when_everything_filtered = true | ||
config.filter_run :focus | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'spec_helper' | ||
require 'activerecord-postgres-array/string' | ||
|
||
describe "String" do | ||
describe "#valid_postgres_array?" do | ||
it 'returns true for an empty string' do | ||
"".should be_valid_postgres_array | ||
end | ||
|
||
it 'returns true for a string consisting only of whitespace' do | ||
" ".should be_valid_postgres_array | ||
end | ||
|
||
it 'returns true for a valid postgres integer array' do | ||
"{10000, 10000, 10000, 10000}".should be_valid_postgres_array | ||
end | ||
|
||
it 'returns true for a valid postgres float array' do | ||
"{10000.2, .5, 10000, 10000.9}".should be_valid_postgres_array | ||
end | ||
|
||
it 'returns true for a valid postgres numerical array with irregular whitespace' do | ||
"{ 10000, 10000 , 10000,10000}".should be_valid_postgres_array | ||
end | ||
|
||
it 'returns false for an array with invalid commas' do | ||
"{213,}".should_not be_valid_postgres_array | ||
end | ||
|
||
it 'returns false for an array without enclosing curly brackets' do | ||
"213, 1234".should_not be_valid_postgres_array | ||
end | ||
|
||
it 'returns true for a valid postgres string array' do | ||
'{"ruby", "on", "rails"}'.should be_valid_postgres_array | ||
end | ||
|
||
it 'returns true for a valid postgres string array with single quotes' do | ||
"{'ruby', 'on', 'rails'}".should be_valid_postgres_array | ||
end | ||
|
||
it 'returns false for string array without quotes' do | ||
"{ruby, on, rails}".should_not be_valid_postgres_array | ||
end | ||
|
||
it 'returns false for concatenated strings' do | ||
'{"ruby""on""rails"}'.should_not be_valid_postgres_array | ||
end | ||
end | ||
end |