inflection 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/inflection.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{inflection}
5
- s.version = "0.1"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.authors = ["Dan Kubb", "Simon Hafner"]
8
8
  s.description = %q{Support library for inflections}
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- version: "0.1"
8
+ - 1
9
+ version: 0.1.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - Dan Kubb
@@ -34,8 +35,6 @@ files:
34
35
  - VERSION
35
36
  - inflection.gemspec
36
37
  - lib/inflection.rb
37
- - spec/inflection_extras_spec.rb
38
- - spec/string_spec.rb
39
38
  - test/setup.rb
40
39
  - test/suite/lib/inflection
41
40
  - test/suite/lib/inflection.rb
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
- require 'extlib/inflection'
3
-
4
- describe Extlib::Inflection do
5
- describe "#classify" do
6
- it 'classifies data_mapper as DataMapper' do
7
- Extlib::Inflection.classify('data_mapper').should == 'DataMapper'
8
- end
9
-
10
- it "classifies enlarged_testes as EnlargedTestis" do
11
- Extlib::Inflection.classify('enlarged_testes').should == 'EnlargedTestis'
12
- end
13
-
14
- it "singularizes string first: classifies data_mappers as egg_and_hams as EggAndHam" do
15
- Extlib::Inflection.classify('egg_and_hams').should == 'EggAndHam'
16
- end
17
- end
18
-
19
- describe "#camelize" do
20
- it 'camelizes data_mapper as DataMapper' do
21
- Extlib::Inflection.camelize('data_mapper').should == 'DataMapper'
22
- end
23
-
24
- it "camelizes merb as Merb" do
25
- Extlib::Inflection.camelize('merb').should == 'Merb'
26
- end
27
-
28
- it "camelizes data_mapper/resource as DataMapper::Resource" do
29
- Extlib::Inflection.camelize('data_mapper/resource').should == 'DataMapper::Resource'
30
- end
31
-
32
- it "camelizes data_mapper/associations/one_to_many as DataMapper::Associations::OneToMany" do
33
- Extlib::Inflection.camelize('data_mapper/associations/one_to_many').should == 'DataMapper::Associations::OneToMany'
34
- end
35
- end
36
-
37
- describe "#underscore" do
38
- it 'underscores DataMapper as data_mapper' do
39
- Extlib::Inflection.underscore('DataMapper').should == 'data_mapper'
40
- end
41
-
42
- it 'underscores Merb as merb' do
43
- Extlib::Inflection.underscore('Merb').should == 'merb'
44
- end
45
-
46
- it 'underscores DataMapper::Resource as data_mapper/resource' do
47
- Extlib::Inflection.underscore('DataMapper::Resource').should == 'data_mapper/resource'
48
- end
49
-
50
- it 'underscores Merb::BootLoader::Rackup as merb/boot_loader/rackup' do
51
- Extlib::Inflection.underscore('Merb::BootLoader::Rackup').should == 'merb/boot_loader/rackup'
52
- end
53
- end
54
-
55
- describe "#humanize" do
56
- it 'replaces _ with space: humanizes employee_salary as Employee salary' do
57
- Extlib::Inflection.humanize('employee_salary').should == 'Employee salary'
58
- end
59
-
60
- it "strips _id endings: humanizes author_id as Author" do
61
- Extlib::Inflection.humanize('author_id').should == 'Author'
62
- end
63
- end
64
-
65
- describe "#demodulize" do
66
- it 'demodulizes module name: DataMapper::Inflector => Inflector' do
67
- Extlib::Inflection.demodulize('DataMapper::Inflector').should == 'Inflector'
68
- end
69
-
70
- it 'demodulizes module name: A::B::C::D::E => E' do
71
- Extlib::Inflection.demodulize('A::B::C::D::E').should == 'E'
72
- end
73
- end
74
-
75
- describe "#tableize" do
76
- it 'pluralizes last word in snake_case strings: fancy_category => fancy_categories' do
77
- Extlib::Inflection.tableize('fancy_category').should == 'fancy_categories'
78
- end
79
-
80
- it 'underscores CamelCase strings before pluralization: enlarged_testis => enlarged_testes' do
81
- Extlib::Inflection.tableize('enlarged_testis').should == 'enlarged_testes'
82
- end
83
-
84
- it 'underscores CamelCase strings before pluralization: FancyCategory => fancy_categories' do
85
- Extlib::Inflection.tableize('FancyCategory').should == 'fancy_categories'
86
- end
87
-
88
- it 'underscores CamelCase strings before pluralization: EnlargedTestis => enlarged_testes' do
89
- Extlib::Inflection.tableize('EnlargedTestis').should == 'enlarged_testes'
90
- end
91
-
92
- it 'replaces :: with underscores: Fancy::Category => fancy_categories' do
93
- Extlib::Inflection.tableize('Fancy::Category').should == 'fancy_categories'
94
- end
95
-
96
- it 'underscores CamelCase strings before pluralization: Enlarged::Testis => enlarged_testes' do
97
- Extlib::Inflection.tableize('Enlarged::Testis').should == 'enlarged_testes'
98
- end
99
-
100
- end
101
-
102
- describe "#foreign_key" do
103
- it 'adds _id to downcased string: Message => message_id' do
104
- Extlib::Inflection.foreign_key('Message').should == 'message_id'
105
- end
106
-
107
- it "demodulizes string first: Admin::Post => post_id" do
108
- Extlib::Inflection.foreign_key('Admin::Post').should == 'post_id'
109
- end
110
- end
111
- end
data/spec/string_spec.rb DELETED
@@ -1,222 +0,0 @@
1
- require 'spec_helper'
2
- require 'extlib/string'
3
-
4
- describe String, "#to_const_string" do
5
- it "swaps slashes with ::" do
6
- "foo/bar".to_const_string.should == "Foo::Bar"
7
- end
8
-
9
- it "replaces snake_case with CamelCase" do
10
- "foo/bar/baz_bat".to_const_string.should == "Foo::Bar::BazBat"
11
- end
12
-
13
- it "leaves constant string as is" do
14
- "Merb::Test".to_const_string.should == "Merb::Test"
15
- end
16
- end
17
-
18
-
19
-
20
- describe String, "#to_const_path" do
21
- it "swaps :: with slash" do
22
- "Foo::Bar".to_const_path.should == "foo/bar"
23
- end
24
-
25
- it "snake_cases string" do
26
- "Merb::Test::ViewHelper".to_const_path.should == "merb/test/view_helper"
27
- end
28
-
29
- it "leaves slash-separated snake case string as is" do
30
- "merb/test/view_helper".to_const_path.should == "merb/test/view_helper"
31
- end
32
- end
33
-
34
-
35
-
36
- describe String, "#camel_case" do
37
- it "handles lowercase without underscore" do
38
- "merb".camel_case.should == "Merb"
39
- end
40
-
41
- it "handles lowercase with 1 underscore" do
42
- "merb_core".camel_case.should == "MerbCore"
43
- end
44
-
45
- it "handles lowercase with more than 1 underscore" do
46
- "so_you_want_contribute_to_merb_core".camel_case.should == "SoYouWantContributeToMerbCore"
47
- end
48
-
49
- it "handles lowercase with more than 1 underscore in a row" do
50
- "__python__is__like__this".camel_case.should == "PythonIsLikeThis"
51
- end
52
-
53
- it "handle first capital letter with underscores" do
54
- "Python__Is__Like__This".camel_case.should == "PythonIsLikeThis"
55
- end
56
-
57
- it "leaves CamelCase as is" do
58
- "TestController".camel_case.should == "TestController"
59
- end
60
- end
61
-
62
-
63
-
64
- describe String, "#snake_case" do
65
- it "lowercases one word CamelCase" do
66
- "Merb".snake_case.should == "merb"
67
- end
68
-
69
- it "makes one underscore snake_case two word CamelCase" do
70
- "MerbCore".snake_case.should == "merb_core"
71
- end
72
-
73
- it "handles CamelCase with more than 2 words" do
74
- "SoYouWantContributeToMerbCore".snake_case.should == "so_you_want_contribute_to_merb_core"
75
- end
76
-
77
- it "handles CamelCase with more than 2 capital letter in a row" do
78
- "CNN".snake_case.should == "cnn"
79
- "CNNNews".snake_case.should == "cnn_news"
80
- "HeadlineCNNNews".snake_case.should == "headline_cnn_news"
81
- "NameACRONYM".snake_case.should == "name_acronym"
82
- end
83
-
84
- it "does NOT change one word lowercase" do
85
- "merb".snake_case.should == "merb"
86
- end
87
-
88
- it "leaves snake_case as is" do
89
- "merb_core".snake_case.should == "merb_core"
90
- end
91
- end
92
-
93
-
94
-
95
- describe String, "#escape_regexp" do
96
- it "escapes all * in a string" do
97
- "*and*".escape_regexp.should == "\\*and\\*"
98
- end
99
-
100
- it "escapes all ? in a string" do
101
- "?and?".escape_regexp.should == "\\?and\\?"
102
- end
103
-
104
- it "escapes all { in a string" do
105
- "{and{".escape_regexp.should == "\\{and\\{"
106
- end
107
-
108
- it "escapes all } in a string" do
109
- "}and}".escape_regexp.should == "\\}and\\}"
110
- end
111
-
112
- it "escapes all . in a string" do
113
- ".and.".escape_regexp.should == "\\.and\\."
114
- end
115
-
116
- it "escapes all regexp special characters used in a string" do
117
- "*?{}.".escape_regexp.should == "\\*\\?\\{\\}\\."
118
- end
119
- end
120
-
121
-
122
-
123
- describe String, "#unescape_regexp" do
124
- it "unescapes all \\* in a string" do
125
- "\\*and\\*".unescape_regexp.should == "*and*"
126
- end
127
-
128
- it "unescapes all \\? in a string" do
129
- "\\?and\\?".unescape_regexp.should == "?and?"
130
- end
131
-
132
- it "unescapes all \\{ in a string" do
133
- "\\{and\\{".unescape_regexp.should == "{and{"
134
- end
135
-
136
- it "unescapes all \\} in a string" do
137
- "\\}and\\}".unescape_regexp.should == "}and}"
138
- end
139
-
140
- it "unescapes all \\. in a string" do
141
- "\\.and\\.".unescape_regexp.should == ".and."
142
- end
143
-
144
- it "unescapes all regexp special characters used in a string" do
145
- "\\*\\?\\{\\}\\.".unescape_regexp.should == "*?{}."
146
- end
147
- end
148
-
149
-
150
-
151
- describe String, "#/" do
152
- it "concanates operands with File::SEPARATOR" do
153
- ("merb" / "core").should == "merb#{File::SEPARATOR}core"
154
- end
155
- end
156
-
157
-
158
- require 'rbconfig'
159
- describe String, "#relative_path_from" do
160
- it "uses other operand as base for path calculation" do
161
- site_dir = Config::CONFIG["sitedir"]
162
-
163
- two_levels_up = site_dir.split(File::SEPARATOR)
164
- 2.times { two_levels_up.pop } # remove two deepest directories
165
- two_levels_up = two_levels_up.join(File::SEPARATOR)
166
-
167
- two_levels_up.relative_path_from(site_dir).should == "../.."
168
- end
169
- end
170
-
171
-
172
- describe String, ".translate" do
173
- before(:each) do
174
- String.stub!(:translations).and_return({ "on snakes and rubies" => "a serpenti e rubini" })
175
- end
176
-
177
- it 'looks up for translation in translations dictionary' do
178
- String.translate("on snakes and rubies").should == "a serpenti e rubini"
179
- end
180
-
181
- it 'returns string that has no translations as it is' do
182
- String.translate("shapes").should == "shapes"
183
- String.translate("kalopsia").should == "kalopsia"
184
- String.translate("holding on to nothing").should == "holding on to nothing"
185
- end
186
- end
187
-
188
- describe String, ".t" do
189
- before(:each) do
190
- String.stub!(:translations).and_return({ '%s must not be blank' => "%s moet ingevuld worden",
191
- 'username' => 'gebruikersnaam',
192
- '%s must be between %s and %s characters long' => '%s moet tussen %s en %s tekens lang zijn'})
193
- end
194
-
195
- it 'looks up for translation in translations dictionary and translates parameters as well' do
196
- "%s must not be blank".t(:username).should == "gebruikersnaam moet ingevuld worden"
197
- "%s must not be blank".t('username').should == "gebruikersnaam moet ingevuld worden"
198
- "%s must be between %s and %s characters long".t(:password, 5, 9).should == "password moet tussen 5 en 9 tekens lang zijn"
199
- end
200
-
201
- it 'returns string that has no translations as it is' do
202
- "password".t.should == "password"
203
- end
204
-
205
- it 'should not translate when freezed' do
206
- "%s must not be blank".t('username'.freeze).should == "username moet ingevuld worden"
207
- end
208
- end
209
-
210
- describe String, ".translations" do
211
- before(:each) do
212
-
213
- end
214
-
215
- it 'returns empty hash by default' do
216
- String.translations.should == {}
217
- end
218
-
219
- it 'returns @translations if set' do
220
- pending "is it @translations on metaclass or @@translations? leaving it out for now"
221
- end
222
- end