This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
forked from propublica/timeline-setter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
timeline_setter_spec.rb
103 lines (87 loc) · 3.44 KB
/
timeline_setter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "TimelineSetter core" do
it 'should build a hash from a spreadsheet' do
TimelineSetter::Parser.new(TEST_CSV).events[0][:date].should eql("Feb. 18, 2003")
end
it 'should create json from an events hash' do
events = TimelineSetter::Parser.new(TEST_CSV)
j = TimelineSetter::Timeline.new({
:events => events.events
}).to_json
JSON.parse(j)[0]['date'].should eql "Feb. 18, 2003"
end
it 'should create html from an events hash' do
events = TimelineSetter::Parser.new(TEST_CSV)
html = TimelineSetter::Timeline.new({
:events => events.events
}).timeline.to_s
html.should =~ /"timestamp":1045544400/
end
it 'should create custom intervals' do
events = TimelineSetter::Parser.new(TEST_CSV)
html = TimelineSetter::Timeline.new({
:events => events.events,
:interval => "FullYear"
}).timeline.to_s
html.should =~ /"interval":"FullYear"/
end
it 'should create minified timelines' do
events = TimelineSetter::Parser.new(TEST_CSV)
html = TimelineSetter::Timeline.new({
:events => events.events
}).timeline_min.to_s
# test to see we've compiled all the assets
# test CSS
html.should =~ /#timeline/
# test timeline
html.should =~ /"timestamp":1045544400/
# test underscore
html.should =~ /Underscore\.js/
# test jQuery
html.should =~ /jQuery JavaScript Library/
# test timeline-setter.js
html.should =~ /INTERVAL_ORDER/
end
end
describe "TimelineSetter CLI" do
it 'should drop just timeline.html into tmp' do
`mkdir /tmp/ts_test_1`
%x[ #{TS_BINARY} -c #{TEST_CSV_PATH} -o /tmp/ts_test_1/ -a ]
Dir.glob("/tmp/ts_test_1/*").should include("/tmp/ts_test_1/timeline.html")
file = File.open("/tmp/ts_test_1/timeline.html").read
file.should =~ /"timestamp":1045544400/
end
it 'should drop timeline.html and associated assets into tmp' do
`mkdir /tmp/ts_test_2`
%x[ #{TS_BINARY} -c #{TEST_CSV_PATH} -o /tmp/ts_test_2/ ]
Dir.glob("/tmp/ts_test_2/*").should include("/tmp/ts_test_2/timeline.html")
Dir.glob("/tmp/ts_test_2/javascripts/*").should include("/tmp/ts_test_2/javascripts/timeline-setter.js")
Dir.glob("/tmp/ts_test_2/javascripts/vendor/*").should include("/tmp/ts_test_2/javascripts/vendor/jquery-min.js")
Dir.glob("/tmp/ts_test_2/javascripts/vendor/*").should include("/tmp/ts_test_2/javascripts/vendor/underscore-min.js")
Dir.glob("/tmp/ts_test_2/stylesheets/*").should include("/tmp/ts_test_2/stylesheets/timeline-setter.css")
end
it 'should create a minified timeline in tmp' do
`mkdir /tmp/ts_test_3`
%x[ #{TS_BINARY} -c #{TEST_CSV_PATH} -o /tmp/ts_test_3/ -m ]
file = File.open("/tmp/ts_test_3/timeline.html").read
file.should =~ /"timestamp":1045544400/
# test to see we've compiled all the assets
# test CSS
file.should =~ /#timeline/
# test timeline
file.should =~ /"timestamp":1045544400/
# test underscore
file.should =~ /Underscore\.js/
# test jQuery
file.should =~ /jQuery JavaScript Library/
# test timeline-setter.js
file.should =~ /INTERVAL_ORDER/
# check to see that we DID NOT generate the assets
Dir.glob("/tmp/ts_test_3/*").should_not include("/tmp/ts_test_3/javascripts/timeline-setter.js")
end
after :all do
`rm -rf /tmp/ts_test_1`
`rm -rf /tmp/ts_test_2`
`rm -rf /tmp/ts_test_3`
end
end