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..c5dc61d 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 @@ -105,6 +107,3 @@ DEPENDENCIES shoulda-matchers sinatra sinatra-contrib - -BUNDLED WITH - 1.10.3 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/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 new file mode 100644 index 0000000..e3811d4 --- /dev/null +++ b/spec/user_spec.rb @@ -0,0 +1,79 @@ +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" + 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"}) + @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} + # 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 + + 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 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 + + 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