footing 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,12 +1,8 @@
1
1
  source :rubygems
2
2
 
3
3
  group :development do
4
- gem "pry"
5
- gem "yard"
6
- end
7
-
8
- group :test do
9
- gem "rspec"
10
- gem "grumpy_old_man"
4
+ gem "micro_test"
11
5
  gem "micro_mock"
6
+ gem "pry"
7
+ # gem "pry-stack_explorer"
12
8
  end
@@ -1,32 +1,29 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- coderay (1.0.7)
5
- diff-lcs (1.1.3)
6
- grumpy_old_man (0.1.3)
7
- method_source (0.8)
8
- micro_mock (0.0.1)
4
+ coderay (1.0.8)
5
+ method_source (0.8.1)
6
+ micro_mock (0.1.1)
7
+ micro_test (0.3.1)
8
+ os
9
+ os (0.9.6)
9
10
  pry (0.9.10)
10
11
  coderay (~> 1.0.5)
11
12
  method_source (~> 0.8)
12
13
  slop (~> 3.3.1)
13
- rspec (2.11.0)
14
- rspec-core (~> 2.11.0)
15
- rspec-expectations (~> 2.11.0)
16
- rspec-mocks (~> 2.11.0)
17
- rspec-core (2.11.1)
18
- rspec-expectations (2.11.2)
19
- diff-lcs (~> 1.1.3)
20
- rspec-mocks (2.11.1)
21
- slop (3.3.2)
22
- yard (0.8.2.1)
14
+ pry (0.9.10-java)
15
+ coderay (~> 1.0.5)
16
+ method_source (~> 0.8)
17
+ slop (~> 3.3.1)
18
+ spoon (~> 0.0)
19
+ slop (3.3.3)
20
+ spoon (0.0.1)
23
21
 
24
22
  PLATFORMS
23
+ java
25
24
  ruby
26
25
 
27
26
  DEPENDENCIES
28
- grumpy_old_man
29
27
  micro_mock
28
+ micro_test
30
29
  pry
31
- rspec
32
- yard
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nathan Hopkins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), "footing", "version")
2
+
1
3
  module Footing
2
4
 
3
5
  def self.modules
@@ -41,5 +41,15 @@ module Footing
41
41
  end
42
42
  alias :titlecase :titleize
43
43
 
44
+ # Indicates if this string represents a number.
45
+ def numeric?
46
+ !!(self =~ /\A[0-9]+\.*[0-9]*\z/)
47
+ end
48
+
49
+ # Indicates if this string represents a boolean value.
50
+ def boolean?
51
+ !!(self =~ /\A(true|false)\z/i)
52
+ end
53
+
44
54
  end
45
55
  end
@@ -0,0 +1,3 @@
1
+ module Footing
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class FootingTest < MicroTest::Test
4
+
5
+ test "patch a class" do
6
+ class Foo; end
7
+ module FooClassPatch
8
+ def foo
9
+ :foo
10
+ end
11
+ end
12
+
13
+ Footing.patch! Foo, FooClassPatch
14
+ o = Foo.new
15
+ assert o.respond_to? :foo
16
+ assert o.foo == :foo
17
+ end
18
+
19
+ test "patch an instance" do
20
+ module FooInstancePatch
21
+ def foo
22
+ :foo
23
+ end
24
+ end
25
+
26
+ o = Object.new
27
+ Footing.patch! o, FooInstancePatch
28
+ assert o.respond_to? :foo
29
+ assert o.foo == :foo
30
+ end
31
+
32
+ test "setup util methods" do
33
+ module FooUtil
34
+ def foo(arg)
35
+ "foo#{arg}"
36
+ end
37
+ end
38
+
39
+ Footing.util! FooUtil
40
+ assert FooUtil.respond_to? :foo
41
+ assert FooUtil.foo("bar") == "foobar"
42
+ end
43
+
44
+ end
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class HashTest < MicroTest::Test
4
+
5
+ test ".adjust_values!" do
6
+ dict = {:a => 1, :b => 2, :c => 3}
7
+ Footing.patch! dict, Footing::Hash
8
+ dict.adjust_values! { |v| v.to_s }
9
+ assert dict == {:a=>"1", :b=>"2", :c=>"3"}
10
+ end
11
+
12
+ end
@@ -0,0 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ # class KernelTest < MicroTest::Test
4
+
5
+ # test ".safe_eval" do
6
+ # assert false
7
+ # end
8
+
9
+ # end
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class NilTest < MicroTest::Test
4
+
5
+ test "[]" do
6
+ Footing.patch! NilClass, Footing::NilClass
7
+ assert nil[:foo] == nil
8
+ end
9
+
10
+ test "deeply nested [] on Hash" do
11
+ Footing.patch! NilClass, Footing::NilClass
12
+ dict = {}
13
+ assert dict[:foo][:bar][:baz] == nil
14
+ end
15
+
16
+ end
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class NumericTest < MicroTest::Test
4
+ Footing.patch! Numeric, Footing::Numeric
5
+
6
+ test ".positive" do
7
+ assert -10.positive == 10
8
+ end
9
+
10
+ test ".negative" do
11
+ assert 10.negative == -10
12
+ end
13
+
14
+ test ".flip_sign" do
15
+ assert 10.flip_sign == -10
16
+ assert -10.flip_sign == 10
17
+ end
18
+
19
+ test ".percent_of" do
20
+ assert 10.percent_of(100) == 10
21
+ assert 50.percent_of(100) == 50
22
+ assert 70.percent_of(100) == 70
23
+ assert 10.percent_of(1000) == 1
24
+ assert 100.percent_of(1000) == 10
25
+ assert 1000.percent_of(1000) == 100
26
+ end
27
+
28
+ test ".round_to" do
29
+ assert 1.0009.round_to(2) == 1
30
+ assert 1.066.round_to(2) == 1.07
31
+ assert 1.867.round_to(2) == 1.87
32
+ assert 1.789259.round_to(5) == 1.78926
33
+ end
34
+
35
+ end
@@ -0,0 +1,72 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class SchemaStatementsTest < MicroTest::Test
4
+
5
+ before do
6
+ @precisions = %w(
7
+ microseconds
8
+ milliseconds
9
+ second
10
+ minute *default
11
+ hour
12
+ day
13
+ week
14
+ month
15
+ quarter
16
+ year
17
+ decade
18
+ century
19
+ millennium
20
+ )
21
+
22
+ @mock = MicroMock.make.new
23
+ Footing.patch! @mock, Footing::PGSchemaStatements
24
+ @mock.stub(:quote_table_name) { |name| "\"#{name}\"" }
25
+ @mock.stub(:quote_column_name) { |name| "\"#{name}\"" }
26
+ @mock.stub(:execute) { |sql| @sql = sql }
27
+ @mock.stub(:sql) { @sql }
28
+ end
29
+
30
+ test "create a datetime index with default precision of minute" do
31
+ @mock.add_datetime_index :foo, :bar
32
+ assert @mock.sql == "create index index_foo_on_bar_by_minute on \"foo\" (date_trunc('minute', \"bar\"))"
33
+ end
34
+
35
+ test "create datetime index with all precisions" do
36
+ @precisions.each do |precision|
37
+ @mock.add_datetime_index :foo, :bar, :precision => precision
38
+ assert @mock.sql == "create index index_foo_on_bar_by_#{precision} on \"foo\" (date_trunc('#{precision}', \"bar\"))"
39
+ end
40
+ end
41
+
42
+ test "remove a datetime index" do
43
+ @mock.remove_datetime_index :foo, :bar
44
+ assert @mock.sql == "drop index if exists index_foo_on_bar_by_minute"
45
+ end
46
+
47
+ test "remove a datetime index for all precisions" do
48
+ @precisions.each do |precision|
49
+ @mock.remove_datetime_index :foo, :bar, :precision => precision
50
+ assert @mock.sql == "drop index if exists index_foo_on_bar_by_#{precision}"
51
+ end
52
+ end
53
+
54
+ test "add timestamp indexes" do
55
+ @mock.stub(:execute) { |sql| @sql << sql }
56
+ @mock.stub(:sql) { @sql }
57
+ @mock.instance_eval { @sql = [] }
58
+ @mock.add_timestamp_indexes :foo
59
+ assert @mock.sql.include? "create index index_foo_on_created_at_by_day on \"foo\" (date_trunc('day', \"created_at\"))"
60
+ assert @mock.sql.include? "create index index_foo_on_updated_at_by_day on \"foo\" (date_trunc('day', \"updated_at\"))"
61
+ end
62
+
63
+ test "remove timestamp indexes" do
64
+ @mock.stub(:execute) { |sql| @sql << sql }
65
+ @mock.stub(:sql) { @sql }
66
+ @mock.instance_eval { @sql = [] }
67
+ @mock.remove_timestamp_indexes :foo
68
+ assert @mock.sql.include? "drop index if exists index_foo_on_created_at_by_day"
69
+ assert @mock.sql.include? "drop index if exists index_foo_on_updated_at_by_day"
70
+ end
71
+
72
+ end
@@ -0,0 +1,95 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class StringTest < MicroTest::Test
4
+ Footing.util! Footing::String
5
+
6
+ test "patch a string instance" do
7
+ s = ""
8
+ Footing.patch! s, Footing::String
9
+ assert s.respond_to? :escape
10
+ assert s.respond_to? :humanize
11
+ assert s.respond_to? :titleize
12
+ assert s.respond_to? :titlecase
13
+ end
14
+
15
+ test ".util!" do
16
+ assert Footing::String.respond_to? :random
17
+ assert Footing::String.respond_to? :escape
18
+ assert Footing::String.respond_to? :humanize
19
+ assert Footing::String.respond_to? :titleize
20
+ assert Footing::String.respond_to? :titlecase
21
+ end
22
+
23
+ test ".random" do
24
+ key = Footing::String.random(100)
25
+ assert key.length == 100 # expected length
26
+ assert (key =~ /\W/).nil? # no non-word chars
27
+ end
28
+
29
+ test ".random with rejected chars" do
30
+ key = Footing::String.random(100, :upcase => true, :reject => [0, 1, 'I', 'O'])
31
+ assert key.length == 100 # expected length
32
+ assert (key =~ /\W/).nil? # no non-word chars
33
+ assert (key =~ /[a-z]/).nil? # no lowercase chars
34
+ assert (key =~ /[01IO]/).nil? # skipped rejected chars
35
+ end
36
+
37
+ test ".escape" do
38
+ s = "foobar"
39
+ Footing.patch! s, Footing::String
40
+ assert s.escape("b") == "foo\\bar"
41
+ end
42
+
43
+ test ".titleize" do
44
+ s = "foobar test"
45
+ Footing.patch! s, Footing::String
46
+ assert s.titleize == "Foobar test"
47
+ end
48
+
49
+ test ".humanize" do
50
+ s = "foo_bar"
51
+ Footing.patch! s, Footing::String
52
+ assert s.humanize == "Foo bar"
53
+ end
54
+
55
+ test ".numeric? integers" do
56
+ (0..100).each do |i|
57
+ s = i.to_s
58
+ Footing.patch! s, Footing::String
59
+ assert s.numeric?
60
+ end
61
+ end
62
+
63
+ test ".numeric? floats" do
64
+ (0..100).each do |i|
65
+ s = i.to_f.to_s
66
+ Footing.patch! s, Footing::String
67
+ assert s.numeric?
68
+ end
69
+ s = "7843.7897389"
70
+ Footing.patch! s, Footing::String
71
+ assert s.numeric?
72
+ s = "7843.789.7389"
73
+ Footing.patch! s, Footing::String
74
+ assert !s.numeric?
75
+ end
76
+
77
+ test ".boolean?" do
78
+ s = "true"
79
+ Footing.patch! s, Footing::String
80
+ assert s.boolean?
81
+
82
+ s = "false"
83
+ Footing.patch! s, Footing::String
84
+ assert s.boolean?
85
+
86
+ s = " true"
87
+ Footing.patch! s, Footing::String
88
+ assert !s.boolean?
89
+
90
+ s = "false "
91
+ Footing.patch! s, Footing::String
92
+ assert !s.boolean?
93
+ end
94
+
95
+ end
@@ -0,0 +1,4 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.require :default, :development
4
+ require File.join(File.dirname(__FILE__), "..", "lib", "footing")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-23 00:00:00.000000000 Z
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Footing is a utillity belt library that employs sane monkey patching.
15
15
 
@@ -20,19 +20,29 @@ executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
- - lib/extensions/array.rb
24
- - lib/extensions/hash.rb
25
- - lib/extensions/kernel.rb
26
- - lib/extensions/nil_class.rb
27
- - lib/extensions/numeric.rb
28
- - lib/extensions/object.rb
29
- - lib/extensions/postgresql_adapter.rb
30
- - lib/extensions/schema_statements.rb
31
- - lib/extensions/string.rb
23
+ - lib/footing/extensions/array.rb
24
+ - lib/footing/extensions/hash.rb
25
+ - lib/footing/extensions/kernel.rb
26
+ - lib/footing/extensions/nil_class.rb
27
+ - lib/footing/extensions/numeric.rb
28
+ - lib/footing/extensions/object.rb
29
+ - lib/footing/extensions/postgresql_adapter.rb
30
+ - lib/footing/extensions/schema_statements.rb
31
+ - lib/footing/extensions/string.rb
32
+ - lib/footing/version.rb
32
33
  - lib/footing.rb
33
34
  - Gemfile
34
35
  - Gemfile.lock
36
+ - LICENSE.txt
35
37
  - README.md
38
+ - test/footing_test.rb
39
+ - test/hash_test.rb
40
+ - test/kernel_test.rb
41
+ - test/nil_test.rb
42
+ - test/numeric_test.rb
43
+ - test/schema_statements_test.rb
44
+ - test/string_test.rb
45
+ - test/test_helper.rb
36
46
  homepage: https://github.com/hopsoft/footing
37
47
  licenses:
38
48
  - MIT
@@ -54,9 +64,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
64
  version: '0'
55
65
  requirements: []
56
66
  rubyforge_project:
57
- rubygems_version: 1.8.24
67
+ rubygems_version: 1.8.23
58
68
  signing_key:
59
69
  specification_version: 3
60
- summary: A utility belt library.
70
+ summary: A utility belt lib.
61
71
  test_files: []
62
72
  has_rdoc: