theman 0.0.5 → 0.1.0
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/.rspec +1 -0
- data/README.rdoc +64 -44
- data/lib/theman/agency/columns.rb +95 -0
- data/lib/theman/agency/table.rb +24 -0
- data/lib/theman/agency.rb +98 -90
- data/lib/theman/object.rb +22 -0
- data/lib/theman/version.rb +1 -1
- data/lib/theman.rb +7 -0
- data/spec/agency_spec.rb +246 -0
- data/spec/columns_spec.rb +75 -0
- data/spec/fixtures/temp_eight.csv +249 -0
- data/spec/fixtures/temp_seven.csv +4 -0
- data/spec/object_spec.rb +37 -0
- data/spec/table_spec.rb +5 -0
- data/theman.gemspec +0 -1
- metadata +14 -18
- data/spec/theman_spec.rb +0 -212
data/spec/theman_spec.rb
DELETED
@@ -1,212 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Theman::Agency, "instance object" do
|
4
|
-
before do
|
5
|
-
@instance = ::Theman::Agency.new.instance
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should superclass active record" do
|
9
|
-
@instance.superclass.should == ActiveRecord::Base
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have connection" do
|
13
|
-
@instance.connection.class.should == ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should have a table name" do
|
17
|
-
@instance.table_name.should match /agent[0-9]{10}/
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should have an ispect method" do
|
21
|
-
@instance.inspect.should match /Agent/
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe Theman::Agency, "instance methods" do
|
26
|
-
it "should downcase and symbolize" do
|
27
|
-
Theman::Agency.new.symbolize("STRANGE NAME").should == :strange_name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe Theman::Agency, "basic" do
|
32
|
-
before do
|
33
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_one.csv'))
|
34
|
-
@agent = ::Theman::Agency.new @csv
|
35
|
-
@instance = @agent.instance
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should have all the records from the csv" do
|
39
|
-
@instance.count.should == 4
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe Theman::Agency, "sed chomp" do
|
44
|
-
before do
|
45
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_two.csv'))
|
46
|
-
@agent = ::Theman::Agency.new @csv do |agent|
|
47
|
-
agent.seds "-n -e :a -e '1,15!{P;N;D;};N;ba'"
|
48
|
-
end
|
49
|
-
@instance = @agent.instance
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should have all the records from the csv" do
|
53
|
-
@instance.count.should == 5
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe Theman::Agency, "data types" do
|
58
|
-
before do
|
59
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_one.csv'))
|
60
|
-
@agent = ::Theman::Agency.new @csv do |agent|
|
61
|
-
agent.nulls /"N"/, /"UNKNOWN"/, /""/
|
62
|
-
agent.table do |t|
|
63
|
-
t.date :col_date
|
64
|
-
t.boolean :col_four
|
65
|
-
t.float :col_five
|
66
|
-
end
|
67
|
-
end
|
68
|
-
@instance = @agent.instance
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should create date col" do
|
72
|
-
@instance.first.col_date.class.should == Date
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should create boolean col" do
|
76
|
-
@instance.where(:col_four => true).count.should == 2
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should create float col" do
|
80
|
-
@instance.where("col_five > 10.0").count.should == 2
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should have an array of nulls" do
|
84
|
-
@agent.nulls_to_sed.should == ["-e 's/\"N\"//g'", "-e 's/\"UNKNOWN\"//g'", "-e 's/\"\"//g'"]
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should have nulls not strings" do
|
88
|
-
@instance.where(:col_two => nil).count.should == 2
|
89
|
-
@instance.where(:col_three => nil).count.should == 2
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe Theman::Agency, "european date styles" do
|
94
|
-
before do
|
95
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_three.csv'))
|
96
|
-
@agent = ::Theman::Agency.new @csv do |smith|
|
97
|
-
smith.datestyle 'European'
|
98
|
-
smith.table do |t|
|
99
|
-
t.date :col_date
|
100
|
-
end
|
101
|
-
end
|
102
|
-
@instance = @agent.instance
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should have correct date" do
|
106
|
-
date = @instance.first.col_date
|
107
|
-
date.day.should == 25
|
108
|
-
date.month.should == 12
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe Theman::Agency, "US date styles" do
|
113
|
-
before do
|
114
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_four.csv'))
|
115
|
-
@agent = ::Theman::Agency.new @csv do |smith|
|
116
|
-
smith.datestyle 'US'
|
117
|
-
smith.table do |t|
|
118
|
-
t.date :col_date
|
119
|
-
end
|
120
|
-
end
|
121
|
-
@instance = @agent.instance
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should have correct date" do
|
125
|
-
date = @instance.first.col_date
|
126
|
-
date.day.should == 25
|
127
|
-
date.month.should == 12
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe Theman::Agency, "ISO date styles" do
|
132
|
-
before do
|
133
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_five.csv'))
|
134
|
-
@agent = ::Theman::Agency.new @csv do |smith|
|
135
|
-
smith.datestyle 'ISO'
|
136
|
-
smith.table do |t|
|
137
|
-
t.date :col_date
|
138
|
-
end
|
139
|
-
end
|
140
|
-
@instance = @agent.instance
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should have correct date" do
|
144
|
-
date = @instance.first.col_date
|
145
|
-
date.day.should == 25
|
146
|
-
date.month.should == 12
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe Theman::Agency, "procedural" do
|
151
|
-
before do
|
152
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_two.csv'))
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should be able to be called procedural" do
|
156
|
-
smith = ::Theman::Agency.new
|
157
|
-
smith.stream @csv
|
158
|
-
smith.datestyle "European"
|
159
|
-
smith.seds "-n -e :a -e '1,15!{P;N;D;};N;ba'"
|
160
|
-
smith.nulls /"XXXX"/
|
161
|
-
smith.date :date
|
162
|
-
smith.create_table
|
163
|
-
smith.pipe_it
|
164
|
-
my_model = smith.instance
|
165
|
-
my_model.first.date.class.should == Date
|
166
|
-
my_model.first.org_code.class.should == NilClass
|
167
|
-
my_model.count.should == 5
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe Theman::Agency, "create table" do
|
172
|
-
before do
|
173
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_one.csv'))
|
174
|
-
@agent = ::Theman::Agency.new @csv do |agent|
|
175
|
-
agent.nulls /"N"/, /"UNKNOWN"/, /""/
|
176
|
-
agent.table do |t|
|
177
|
-
t.string :col_two, :limit => 50
|
178
|
-
end
|
179
|
-
end
|
180
|
-
@instance = @agent.instance
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should have" do
|
184
|
-
@instance.first.col_two.should == "some \\text\\"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe Theman::Agency, "add primary key" do
|
189
|
-
before do
|
190
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_one.csv'))
|
191
|
-
@agent = ::Theman::Agency.new @csv, ActiveRecord::Base, :primary_key => true
|
192
|
-
@instance = @agent.instance
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should have serial primary key" do
|
196
|
-
@instance.first.agents_pkey.should == 1
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe Theman::Agency, "delimiters" do
|
201
|
-
before do
|
202
|
-
@csv = File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'temp_six.txt'))
|
203
|
-
@agent = ::Theman::Agency.new @csv do |agent|
|
204
|
-
agent.delimiter "|"
|
205
|
-
end
|
206
|
-
@instance = @agent.instance
|
207
|
-
end
|
208
|
-
|
209
|
-
it "should have imported pipe delimited txt file" do
|
210
|
-
@instance.count.should == 4
|
211
|
-
end
|
212
|
-
end
|