jgdavey-movable_erb 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,173 +0,0 @@
1
-
2
- require File.join(File.dirname(__FILE__), %w[spec_helper])
3
-
4
- describe MovableErb::MTImport do
5
-
6
- it "should exist" do
7
- MovableErb::MTImport.should_not be_nil
8
- end
9
-
10
- describe "initialization" do
11
- before(:each) do
12
- @mt = MovableErb::MTImport.new(:csv => {:file => 'does_not_exist.csv'})
13
- @mt.csv.stub!(:header).and_return(['Title','Body'])
14
- @mt.setup_column_nums
15
- end
16
-
17
- it "should have a title column in first column by default" do
18
- @mt.columns[:title].should eql([0])
19
- end
20
-
21
- it "should have a body column in second column by default" do
22
- @mt.columns[:body].should eql([1])
23
- end
24
- end
25
-
26
- describe "with non-default order of header rows" do
27
- before(:each) do
28
- @mt = MovableErb::MTImport.new(:csv => {:file => 'does_not_exist.csv'})
29
- @mt.csv.stub!(:header).and_return(['Body','Title'])
30
- @mt.setup_column_nums
31
- end
32
-
33
- it "should find and correctly assign the title column" do
34
- @mt.columns[:title].should eql([1])
35
- end
36
-
37
- it "should find and correctly assign the body column" do
38
- @mt.columns[:body].should eql([0])
39
- end
40
- end
41
-
42
- describe "joining field titles with same name" do
43
- before(:each) do
44
- @mt = MovableErb::MTImport.new(:csv => {:file => 'does_not_exist.csv'})
45
- @mt.csv.stub!(:header).and_return(['Title','Body','Body'])
46
- @mt.csv.stub!(:body).and_return([['A Title', 'Part of the body','is right here'],['Title 2', 'Body 2','is right here']])
47
- @mt.setup_column_nums
48
- end
49
-
50
- it "should find more than one element with Body if given" do
51
- @mt.columns[:body].should eql([1,2])
52
- @mt.content_for('body',0).should eql(['Part of the body','is right here'])
53
- @mt.content_for('body',1).should eql(['Body 2','is right here'])
54
- end
55
-
56
-
57
- it "should render with a template file" do
58
- @mt.render_with_template.should eql(
59
- %q{TITLE: A Title
60
- -----
61
- BODY:
62
-
63
- Part of the body
64
- is right here
65
-
66
- --------
67
- TITLE: Title 2
68
- -----
69
- BODY:
70
-
71
- Body 2
72
- is right here
73
-
74
- }.gsub(/^ +/,'') )
75
- end
76
- end
77
-
78
- describe "non-default fields" do
79
- before(:each) do
80
- @mt = MovableErb::MTImport.new(:csv => {:file => 'spec/fixtures/example.csv'})
81
- @mt.csv.stub!(:header).and_return(['Title','Body','Category',"Extended"])
82
- @mt.csv.stub!(:body).and_return([['A Title', 'Part of the body','Articles','Another field'],['Title 2', 'Body 2','Articles','field 2']])
83
- @mt.setup_column_nums
84
- end
85
-
86
- it "should recognize an extended field" do
87
- @mt.columns[:extended].should_not be_nil
88
- @mt.columns[:extended].should be_instance_of(Array)
89
- @mt.columns[:extended].should eql([3])
90
- end
91
-
92
- it "should recognize the category field" do
93
- @mt.columns[:category].should_not be_nil
94
- @mt.columns[:category].should be_instance_of(Array)
95
- @mt.columns[:category].should eql([2])
96
- end
97
-
98
- it "should correctly render" do
99
- @mt.render_with_template.should eql(
100
- %q{TITLE: A Title
101
- CATEGORY: Articles
102
- -----
103
- BODY:
104
-
105
- Part of the body
106
-
107
- -----
108
- EXTENDED:
109
-
110
- Another field
111
-
112
- --------
113
- TITLE: Title 2
114
- CATEGORY: Articles
115
- -----
116
- BODY:
117
-
118
- Body 2
119
-
120
- -----
121
- EXTENDED:
122
-
123
- field 2
124
-
125
- }.gsub(/^ +/,''))
126
- end
127
- end
128
-
129
- describe "tags" do
130
- before(:each) do
131
- @mt = MovableErb::MTImport.new(:csv => {:file => 'spec/fixtures/example.csv'})
132
- @mt.csv.stub!(:header).and_return(['Title','Body','Tags'])
133
- @mt.csv.stub!(:body).and_return([['A Title', 'Body content','dog, cats, mice']])
134
- @mt.setup_column_nums
135
- end
136
-
137
- it "should recognize tags" do
138
- @mt.columns[:tags].should_not be_nil
139
- end
140
-
141
- it "should render correctly" do
142
- @mt.render_with_template.should eql(
143
- %q{TITLE: A Title
144
- TAGS: dog, cats, mice
145
- -----
146
- BODY:
147
-
148
- Body content
149
-
150
- }.gsub(/^ +/,''))
151
- end
152
- end
153
-
154
- describe "when header column is not named/misnamed" do
155
- before(:each) do
156
- @mt = MovableErb::MTImport.new(:csv => {:file => 'spec/fixtures/example.csv'})
157
- @mt.csv.stub!(:header).and_return(['Name','Address','Nothing'])
158
- @mt.csv.stub!(:body).and_return([['John Boy', '123 Nowhere Lane','dog, cats, mice']])
159
- @mt.setup_column_nums
160
- end
161
-
162
- it "should default the first field to title" do
163
- @mt.columns[:title].should_not be_nil
164
- @mt.columns[:title].should eql([0])
165
- end
166
-
167
- it "should default the second field to body" do
168
- @mt.columns[:body].should_not be_nil
169
- @mt.columns[:body].should eql([1])
170
- end
171
- end
172
-
173
- end
File without changes