From 6c5d740c467afbb3f9445c5bfa5f4b6cacccd11c Mon Sep 17 00:00:00 2001 From: Joseph Fields Date: Sun, 14 Jun 2015 15:46:26 -0400 Subject: [PATCH 1/3] adding user and round tests --- spec/round_spec.rb | 5 +++++ spec/user_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 spec/round_spec.rb create mode 100644 spec/user_spec.rb diff --git a/spec/round_spec.rb b/spec/round_spec.rb new file mode 100644 index 0000000..eaba0da --- /dev/null +++ b/spec/round_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Round do + pending "add some examples to (or delete) /Users/apprentice/Desktop/web_flash_cards/Rakefile" +end diff --git a/spec/user_spec.rb b/spec/user_spec.rb new file mode 100644 index 0000000..9d4d813 --- /dev/null +++ b/spec/user_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + + + +describe User do + # pending "add some examples to (or delete) /Users/apprentice/Desktop/web_flash_cards/Rakefile" + before(:all) do + @giovanna = User.create({email: 'gigi@hotmail.com', name: "Giovanna", password: "1234"}) + @joseph = User.create({email: 'jfizi@hotmail.com', name: "Joseph", password: "1234"}) + @jordan = User.create({email: 'jojo@hotmail.com', name: "Jordan", password: "1234"}) + @sheldon = User.create({email: 'sheldor@hotmail.com', name: "Sheldon", password: "1234"}) + end + + after(:all) do + User.all.each {|user| user.destroy} + end + + it 'should show all users in an array' do + expect(User.all.size).to eq (4) + end + + it 'should show the email of the user' do + expect(@sheldon.email).to eq ('sheldor@hotmail.com') + end + + it 'should show the the name of the user' do + expect(@sheldon.name).to eq("Sheldon") + end + + it 'show a user password' do + expect(@sheldon.password).to exist + end + +end From d8278675c4b669609e920c3731052357151035c9 Mon Sep 17 00:00:00 2001 From: Joseph Fields Date: Sun, 14 Jun 2015 18:56:28 -0400 Subject: [PATCH 2/3] added capybara --- Gemfile | 1 + Gemfile.lock | 2 ++ spec/spec_helper.rb | 15 +++++++++++++++ spec/user_spec.rb | 39 ++++++++++++++++++++++++++++++++------- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 80ddcbb..66a1d64 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ group :test do gem 'rack-test' gem 'rspec', '~>3.0' gem 'capybara' + gem 'database_cleaner' end group :test, :development do diff --git a/Gemfile.lock b/Gemfile.lock index 8c6134d..cc36046 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,6 +25,7 @@ GEM rack-test (>= 0.5.4) xpath (~> 2.0) coderay (1.1.0) + database_cleaner (1.4.1) diff-lcs (1.2.5) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -94,6 +95,7 @@ DEPENDENCIES activesupport (~> 4.2.0) bcrypt capybara + database_cleaner factory_girl faker pg diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6081f82..7fc8c02 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,22 @@ require 'capybara/rspec' RSpec.configure do |config| + require 'database_cleaner' config.include Rack::Test::Methods + + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:all) do + DatabaseCleaner.start + end + + config.after(:all) do + DatabaseCleaner.clean + end + end def app diff --git a/spec/user_spec.rb b/spec/user_spec.rb index 9d4d813..72e816b 100644 --- a/spec/user_spec.rb +++ b/spec/user_spec.rb @@ -2,23 +2,35 @@ -describe User do +describe User, :type => :feature do # pending "add some examples to (or delete) /Users/apprentice/Desktop/web_flash_cards/Rakefile" before(:all) do - @giovanna = User.create({email: 'gigi@hotmail.com', name: "Giovanna", password: "1234"}) - @joseph = User.create({email: 'jfizi@hotmail.com', name: "Joseph", password: "1234"}) - @jordan = User.create({email: 'jojo@hotmail.com', name: "Jordan", password: "1234"}) - @sheldon = User.create({email: 'sheldor@hotmail.com', name: "Sheldon", password: "1234"}) + @giovanna = User.create({email: 'gigi@hotmail.com', name: "Giovanna", password: "1234"}) + @joseph = User.create({email: 'jfizi@hotmail.com', name: "Joseph", password: "1234"}) + @jordan = User.create({email: 'jojo@hotmail.com', name: "Jordan", password: "1234"}) + @sheldon = User.create({email: 'sheldor@hotmail.com', name: "Sheldon", password: "1234"}) + @pokemon_deck = Deck.create({name: 'pokemon', creator_id: 1, category_id: 1}) + @pikachu = Card.create({question: 'name the pokemon that looks like an electric mouse', answer: 'pikachu',deck_id: 1}) + @bulbasaur = Card.create({question: 'name the first pokemon',answer: 'bulbasaur',deck_id: 1}) + @anime = Category.create(name: 'anime') + @round_1 = Round.create(player_id: 1, deck_id: 1) end after(:all) do - User.all.each {|user| user.destroy} + # User.all.each {|user| user.destroy} + # Card.all.each {|card| card.destroy} + # Category.all.each {|category| category.destroy} + # Deck.all.each {|deck| deck.destroy} + # Round.all.each {|round| round.destroy} + + # How do I rollback all of these transactions? I know that deleteing everything is not the best route to take. end it 'should show all users in an array' do expect(User.all.size).to eq (4) end + it 'should show the email of the user' do expect(@sheldon.email).to eq ('sheldor@hotmail.com') end @@ -28,7 +40,20 @@ end it 'show a user password' do - expect(@sheldon.password).to exist + expect(@sheldon.password).to be_truthy + end + + it 'should find the user based of his/her id' do + p User.find(2) + expect(@joseph).to eq(User.find(2)) end + it 'should show the round for the user' do + expect(@giovanna.rounds.count).to eq(1) + end + + it 'should visit the home page' do + visit '/' + expect(page).to have_content 'Welcome to our site' + end end From cec2020a1ebf524a44af0c77daea32dd21b2b1f6 Mon Sep 17 00:00:00 2001 From: Joseph Fields Date: Sun, 14 Jun 2015 19:35:30 -0400 Subject: [PATCH 3/3] added capybara tests and schema tests --- Gemfile.lock | 3 --- spec/user_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index cc36046..c5dc61d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,3 @@ DEPENDENCIES shoulda-matchers sinatra sinatra-contrib - -BUNDLED WITH - 1.10.3 diff --git a/spec/user_spec.rb b/spec/user_spec.rb index 72e816b..e3811d4 100644 --- a/spec/user_spec.rb +++ b/spec/user_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' +# How do I run this all in the config. How do I run controllers with out a class? Do I simply run tests for routes in the global scope? describe User, :type => :feature do # pending "add some examples to (or delete) /Users/apprentice/Desktop/web_flash_cards/Rakefile" @@ -56,4 +57,23 @@ visit '/' expect(page).to have_content 'Welcome to our site' end + + it 'should redirect to login from the home page' do + visit '/' + click_link('Login') + # fill_in('Name',with: 'Sheldon') + fill_in('Email',with: 'sheldor@hotmail.com') + fill_in('Password', with: '1234') + click_button('Login') + expect(page).to have_content 'Sheldon Decks' + end + it 'should post invalid user for invalid login attempts' do + visit '/' + click_link('Login') + # fill_in('Name',with: 'Sheldon') + fill_in('Email',with: 'sheldor@hotmail.com') + fill_in('Password', with: '4444') + click_button('Login') + expect(page).to_not have_content('Sheldon Decks') + end end