I’m playing with dynamic test fixtures and seeing what seems to be odd
behavior. I’m fairly new to ruby and rails so it could be something
simple. I have the following fixture:
<%COUNTRY_MAX=10%>
<%0.upto(COUNTRY_MAX) do |number| %>
country<%=number%>:
id: <%=number%>
code: <%=format("%03d", number)%>
name: country<%=format("%03d", number)%>
<% end %>
which produces:
DELETE FROM countries
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country003’, 3,
3)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country004’, 4,
4)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country005’, 5,
5)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country006’, 6,
6)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country007’, 7,
7)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country008’,
‘008’, 8)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country009’,
‘009’, 9)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country000’, 0,
0)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country001’, 1,
1)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country010’, 8,
10)
INSERT INTO countries (“name”, “code”, “id”) VALUES (‘country002’, 2,
2)
I have several questions about this.
- why does the code get out of sync with the name and id?
- why aren’t they in order as expected?
- why is the code not always formatted to be length 3?