From c354d816b6a28260ca6c55a71d35549c761700cd Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 14:43:57 +0200 Subject: [PATCH 01/10] add ffaker gem --- Gemfile | 1 + Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 13d32d1d..ce920daf 100644 --- a/Gemfile +++ b/Gemfile @@ -67,6 +67,7 @@ group :development, :test do gem "launchy", "~> 2.4.2" gem "minitest", "~> 4.2.0" gem "quiet_assets", "~> 1.0.0" + gem "ffaker" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 8a46b313..7e131bb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,6 +109,7 @@ GEM fabrication (1.2.0) faraday (0.9.0) multipart-post (>= 1.2, < 3) + ffaker (2.0.0) ffi (1.9.3) fssm (0.2.10) haml (3.1.8) @@ -302,6 +303,7 @@ DEPENDENCIES draper (~> 0.11.1) exceptional (~> 2.0.32) fabrication (~> 1.2.0) + ffaker haml (~> 3.1.4) haml-rails (~> 0.3.4) i18n (~> 0.6.0) From 7d49c6c1a07005ee52bc9a6cc3e7680e03302e0e Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 14:44:20 +0200 Subject: [PATCH 02/10] add seeds --- db/seeds.rb | 2 ++ db/seeds/development.rb | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 db/seeds.rb create mode 100644 db/seeds/development.rb diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 00000000..792d25a5 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,2 @@ +seed_file = "#{Rails.root}/db/seeds/#{Rails.env}.rb" +require seed_file if File.exists?(seed_file) diff --git a/db/seeds/development.rb b/db/seeds/development.rb new file mode 100644 index 00000000..5841c79e --- /dev/null +++ b/db/seeds/development.rb @@ -0,0 +1,23 @@ +include FFaker + +author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost', email: 'johndoe@example.com') +user_john = User.create(username: 'johndoe', password: 'password', author: author_john) + +5.times do + name = Name.name + username = name.downcase.gsub(' ', '') + password = Internet.password + domain = Internet.domain_name + email = Internet.email + author = Author.create(username: username, name: name, password: password, domain: domain, email: email) + User.create(username: username, password: password, author: author, email: email) +end + +authors = Author.all +authors.each { |a| Feed.create(author: authors.sample) } + +100.times do |n| + Update.create(author: authors.sample, + text: n%10 == 0 ? '@johndoe ' + Lorem.sentence : Lorem.sentence, + feed: Feed.first) +end From 8ee65c8a5de81b9eb06b169155c47664e4fc0039 Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 14:52:32 +0200 Subject: [PATCH 03/10] add avatars to seeds --- db/seeds/development.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/seeds/development.rb b/db/seeds/development.rb index 5841c79e..7f8758af 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -1,6 +1,7 @@ include FFaker -author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost', email: 'johndoe@example.com') +author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost', + email: 'johndoe@example.com', image_url: 'http://robohash.org/johndoe.png?size=300x300') user_john = User.create(username: 'johndoe', password: 'password', author: author_john) 5.times do @@ -9,7 +10,8 @@ password = Internet.password domain = Internet.domain_name email = Internet.email - author = Author.create(username: username, name: name, password: password, domain: domain, email: email) + author = Author.create(username: username, name: name, password: password, domain: domain, email: email, + image_url: "http://robohash.org/#{username}.png?size=300x300") User.create(username: username, password: password, author: author, email: email) end From 112cb3c8b8059b1061b4c0f5f1297174ea5345ed Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 16:40:36 +0200 Subject: [PATCH 04/10] fix domain for johndoe --- db/seeds/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/development.rb b/db/seeds/development.rb index 7f8758af..4cbda7ff 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -1,6 +1,6 @@ include FFaker -author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost', +author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost:3000', email: 'johndoe@example.com', image_url: 'http://robohash.org/johndoe.png?size=300x300') user_john = User.create(username: 'johndoe', password: 'password', author: author_john) From b58f49bca6bddecbe3d7dfdcbcbe53a1d48fb45b Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 16:40:57 +0200 Subject: [PATCH 05/10] enable adding new users after seeding db --- db/seeds/development.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/seeds/development.rb b/db/seeds/development.rb index 4cbda7ff..d486ff3c 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -2,7 +2,8 @@ author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost:3000', email: 'johndoe@example.com', image_url: 'http://robohash.org/johndoe.png?size=300x300') -user_john = User.create(username: 'johndoe', password: 'password', author: author_john) +user_john = User.create(username: 'johndoe', password: 'password', author: author_john, admin: true) +Admin.create(multiuser: true) 5.times do name = Name.name From 16372797501a2b975188b188c67703df332d4247 Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 16:58:23 +0200 Subject: [PATCH 06/10] add email to john_user --- db/seeds/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/development.rb b/db/seeds/development.rb index d486ff3c..0407b8a1 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -2,7 +2,7 @@ author_john = Author.create(username: 'johndoe', name: 'John Doe', password: 'password', domain: 'localhost:3000', email: 'johndoe@example.com', image_url: 'http://robohash.org/johndoe.png?size=300x300') -user_john = User.create(username: 'johndoe', password: 'password', author: author_john, admin: true) +user_john = User.create(username: 'johndoe', password: 'password', author: author_john, admin: true, email: 'johndoe@example.com') Admin.create(multiuser: true) 5.times do From 083087019e4065d0708a8b29cf7183554eaed208 Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 17:01:38 +0200 Subject: [PATCH 07/10] add info about seeds to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 6c804413..728499ba 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,12 @@ secret from Twitter. Here are the steps to do that: Now you should be able to sign in to your development version with Twitter! +### Adding sample data + +While developing you can seed your database with a sample data: + + $ rake db:seed + ### Running the tests To run the tests you may want to make use of `bundle exec` so you don't get From 8ab7715ca7b8a14fc8843288c27d40a340d83f38 Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 17:03:36 +0200 Subject: [PATCH 08/10] add bundle exec to the command in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 728499ba..55e85fc9 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ Now you should be able to sign in to your development version with Twitter! While developing you can seed your database with a sample data: - $ rake db:seed + $ bundle exec rake db:seed ### Running the tests From bb56bcc6f733f6b31602718041a071e368ce3ff1 Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 17:08:25 +0200 Subject: [PATCH 09/10] add info about default user's credentials --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 55e85fc9..252954d3 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,11 @@ While developing you can seed your database with a sample data: $ bundle exec rake db:seed +Default user credentials: + + username: johndoe + password: password + ### Running the tests To run the tests you may want to make use of `bundle exec` so you don't get From c0c1bf17cdbdbf931188296e399319f6337e29bf Mon Sep 17 00:00:00 2001 From: Mateusz Palyz Date: Thu, 21 May 2015 17:51:40 +0200 Subject: [PATCH 10/10] improve username creation --- db/seeds/development.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/development.rb b/db/seeds/development.rb index 0407b8a1..efb3838b 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -7,7 +7,7 @@ 5.times do name = Name.name - username = name.downcase.gsub(' ', '') + username = name.downcase.gsub(/\.|\s/, '') password = Internet.password domain = Internet.domain_name email = Internet.email