Skip to content

Commit c9affa2

Browse files
committed
adding seeds
1 parent bf84113 commit c9affa2

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

db/seeds.rb

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
Program.all.each(&:destroy)
2+
Question.all.each(&:destroy)
3+
Answer.all.each(&:destroy)
4+
User.all.each(&:destroy)
5+
6+
require 'faker'
7+
8+
users = (0..5).to_a.collect do
9+
username = Faker::Internet.user_name
10+
user = User.create!(:username => username,
11+
:email => "#{username}@example.com",
12+
:password => (0...50).map{ ('a'..'z').to_a[rand(26)] }.join[0,12]
13+
)
14+
user
15+
end
16+
17+
titles = [
18+
%Q{Variables?},
19+
%Q{What is Rails?},
20+
%Q{Shoes help!},
21+
%Q{Other programs?},
22+
%Q{Reading list question...}]
23+
24+
questions = []
25+
questions << %Q{Hello! I have a question! How come I can do this:
26+
a = 5
27+
a = "hello"
28+
29+
Shouldn't that not work? Why can a be five and then a String?
30+
}
31+
questions << %Q{What is 'ruby on rails?' I've seen stuff about it when I google for Ruby.
32+
}
33+
questions << %Q{I have a program that looks like this:
34+
35+
edit_line
36+
button "Repeat" do
37+
alert("You said '#{??}'")
38+
end
39+
40+
What do I do for the ??s?
41+
}
42+
questions << %Q{Does anyone have some programs to share?
43+
}
44+
questions << %Q{I've done all the Lessons! What should I check out next?
45+
}
46+
47+
answers = []
48+
answers << [%Q{Ruby is really flexible, it doesn't care what kind of thing your variables are! Don't worry about it.}]
49+
answers << [%Q{It's a way to make websites with Ruby.}]
50+
answers << [%Q{Try this:
51+
52+
line = edit_line
53+
54+
and then
55+
56+
alert("You said '\#{line.text}'")}, %Q{Hmm, I think you need a variable...}]
57+
answers << [%Q{Check out [the programs page](/programs).}]
58+
answers << [%Q{I like [_why's poignant guide to ruby](http://mislav.uniqpath.com/poignant-guide/).},
59+
%Q{Check out [Learn To Program](http://pine.fm/LearnToProgram/)!!!},
60+
%Q{There's a bunch of things [on Google](http://www.google.com/search?client=safari&rls=en&q=ruby+tutorial&ie=UTF-8&oe=UTF-8), explore them and try a bunch!},
61+
%Q{I love [Try Ruby](http://tryruby.org).}]
62+
63+
5.times do |i|
64+
question = Question.new(
65+
:title => titles[i],
66+
:description => questions[i]
67+
)
68+
question.user = users[i]
69+
question.save!
70+
answers[i].collect! do |answer|
71+
answer = Answer.new(:description => answer)
72+
answer.question = question
73+
answer.user = users[(i + 1) % 5]
74+
answer.save
75+
answer
76+
end
77+
question.solution_id = answers[i].first.id
78+
question.save!
79+
questions[i] = question
80+
end

0 commit comments

Comments
 (0)