Skip to content

Commit

Permalink
Added random_topics rake task
Browse files Browse the repository at this point in the history
* Run 'rake myapp:load:random_topics'
* Bundle file update (ffaker, random_data)
  • Loading branch information
lottadot committed Feb 9, 2012
1 parent 2840b4d commit 8e91e75
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,35 @@ Quick Start (aka TL;DR)

(clone the repo):

* cd lottadot-restkit-ios-rails3-1-advanced
```console
cd lottadot-restkit-ios-rails3-1-advanced
```console

(update the git submodule that points to Restkit):

* git submodule update --init --recursive
```console
git submodule update --init --recursive
```console

(start the rails app in a terminal window):

* cd ldtrkpoc2svr
```console
cd ldtrkpoc2svr
```console

(if you use RVM:)
* rvm use ruby-1.9.2-p290@ldtrkpoc2svr
```console
rvm use ruby-1.9.2-p290@ldtrkpoc2svr
```console

(If you see something like 'report_activate_error' you'll have to do 'gem install rails'. If you see something about gemset doesn't exist, then follow rvm's instructions to install the new gemset (ie rvm --create use ruby-1.9.2-p290@ldtrkpoc2svr ), and don't forget to 'gem install rails' when it's finished.)

* bundle install
* rake db:migrate
* rake db:seed
* rails s
```console
bundle install
rake db:migrate
rake db:seed
rails s
```console

Open a web browser and open [http://lvh.me:3000/](http://lvh.me:3000/)

Expand All @@ -58,6 +69,15 @@ You should see

If you press the 'add one' button it should contact the website, create a new Topic on the website. After creating it should update the UITableView so you see the new Topic.

---
###Optional

If you'd like to "load test", you can generate random-topic-data (default is 150 records) Run:

```console
rake myapp:load:random_topics
```console

---
###TODO

Expand Down
3 changes: 3 additions & 0 deletions ldtrkpoc2svr/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ group :test do
gem 'turn', :require => false
gem "minitest"
end

gem 'ffaker'
gem 'random_data'
4 changes: 4 additions & 0 deletions ldtrkpoc2svr/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ GEM
erubis (2.7.0)
execjs (1.2.12)
multi_json (~> 1.0)
ffaker (1.12.1)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.19)
Expand Down Expand Up @@ -81,6 +82,7 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
random_data (1.5.2)
rdoc (3.12)
json (~> 1.4)
sass (3.1.12)
Expand Down Expand Up @@ -111,9 +113,11 @@ PLATFORMS

DEPENDENCIES
coffee-rails (~> 3.1.1)
ffaker
jquery-rails
minitest
rails (= 3.1.1)
random_data
sass-rails (~> 3.1.4)
sqlite3
turn
Expand Down
39 changes: 39 additions & 0 deletions ldtrkpoc2svr/lib/tasks/load.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# http://stackoverflow.com/questions/3782177/rake-task-to-add-default-data
# RAILS_ENV="development" rake myapp:data:load
# problems? try RAILS_ENV="development" rake myapp:data:load --trace
require File.join(File.dirname(__FILE__), '../../config/environment')

namespace :myapp do
namespace :load do

# Swiped from ActiveRecord migrations.rb
def announce(message)
length = [0, 75 - message.length].max
puts "== %s %s" % [message, "=" * length]
end

desc "Creates n number random topics using the Random Data gem, defaults to 150"
task :random_topics, [:n] => :environment do |t, args|
begin
n = args.n.to_i < 1 ? 150 : args.n.to_i
require 'ffaker'
require 'random_data'
time = Benchmark.measure do
n.times do |i|
topictitle = Faker::Company.name
topicbody = Faker::Lorem.paragraph

catch do
t = Topic.new(:title => topictitle, :body => topicbody)
t.save!
puts "%6d: %15s" % [(i+1), t.title]
end
end
end
announce "Loaded %6d topics in (%2dm %2.0fs)" % [n, *time.real.divmod(60)]
rescue LoadError
puts "This rake task requires random_data. To install, run this command:\n\n sudo gem install random_data\n\n"
end
end
end
end

0 comments on commit 8e91e75

Please sign in to comment.