diff --git a/Gemfile b/Gemfile index a8b499edc..30dbfa979 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,8 @@ group :development, :test do gem 'factory_girl_rails' gem 'capybara' gem 'launchy' + gem 'selenium-webdriver' + gem 'database_cleaner' gem 'coveralls', require: false gem 'fuubar' end diff --git a/Gemfile.lock b/Gemfile.lock index e85919f7f..a7861385d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,6 +132,7 @@ GEM crass (0.2.1) daemons (1.1.9) dalli (2.7.2) + database_cleaner (1.3.0) delayed_job (4.0.2) activesupport (>= 3.0, < 4.2) delayed_job_active_record (4.0.1) @@ -358,6 +359,11 @@ GEM tilt (~> 1.3) scrollToFixed_rails (1.0.5) railties (>= 3.1) + selenium-webdriver (2.35.1) + childprocess (>= 0.2.5) + multi_json (~> 1.0) + rubyzip (< 1.0.0) + websocket (~> 1.0.4) simplecov (0.9.1) docile (~> 1.1.0) multi_json (~> 1.0) @@ -404,6 +410,7 @@ GEM uuidtools (2.1.5) warden (1.2.3) rack (>= 1.0) + websocket (1.0.7) win32-process (0.7.4) ffi (>= 1.0.0) win32console (1.3.2-x86-mingw32) @@ -442,6 +449,7 @@ DEPENDENCIES coveralls daemons dalli + database_cleaner delayed_job_active_record devise (= 3.0) exception_notification @@ -480,6 +488,7 @@ DEPENDENCIES sanitize sass-rails (~> 3.2.3) scrollToFixed_rails (~> 1.0.0) + selenium-webdriver simple_form! slugged (~> 2.0) spork-rails diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7b5b13da5..0855be853 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -8,13 +8,6 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| - # ## Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - # - # config.mock_with :mocha - # config.mock_with :flexmock - # config.mock_with :rr # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" @@ -22,7 +15,7 @@ # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. - config.use_transactional_fixtures = true + config.use_transactional_fixtures = false # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of @@ -35,8 +28,13 @@ config.include Warden::Test::Helpers config.include Capybara::DSL + Capybara.default_wait_time = 3 + Capybara.register_driver :selenium_chrome do |app| + Capybara::Selenium::Driver.new(app, :browser => :chrome) + end + config.before(:each) { Warden.test_mode! } diff --git a/spec/requests/announcement_pages_copy_spec.rb b/spec/requests/announcement_pages_copy_spec.rb new file mode 100644 index 000000000..cc0e10eef --- /dev/null +++ b/spec/requests/announcement_pages_copy_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe "AnnouncementPages", :type => :request do + + let(:admin) {FactoryGirl.create(:admin)} + let(:course) { FactoryGirl.create(:course) } + before do + sign_in admin + create_course course + end + + describe "Announcement Creation", :js => true do + before do + visit course_announcements_path(course) + end + + describe "Test 1" do + it "shows the new button" do + expect(page).to have_link('New', href: new_course_announcement_path(course)) + end + end + + describe "create action" do + before do + click_link 'New' + end + + it "displays the content" do + expect(page).to have_field("announcement_title") + expect(page).to have_selector("iframe.wysihtml5-sandbox") + end + + describe "with valid information" do + let(:announcement) {FactoryGirl.build(:announcement)} + before do + fill_in 'announcement_title', with: announcement.title + page.execute_script("$('#announcement_description').attr('value','abcd');") + end + + it "should create an announcement", :js => true do + expect(page).to have_selector("textarea[value='abcd']", visible: false) + expect { click_button 'Create'}.to change(Announcement, :count).by(1) + end + end + end + end +end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 000000000..b1ebc5d1a --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,36 @@ +RSpec.configure do |config| + + config.before(:suite) do + DatabaseCleaner.clean_with(:truncation) + load Rails.root + "db/seeds.rb" + # puts "before suite" + end + + config.before(:each) do + DatabaseCleaner.strategy = :transaction + # puts "Before Normal" + end + + config.before(:each, :js => true) do + Capybara.current_driver = :selenium_chrome + DatabaseCleaner.strategy = :truncation + # puts "Before JS" + end + + config.before(:each) do + DatabaseCleaner.start + # puts "Before all" + end + + config.after(:each, :js => true) do + load Rails.root + "db/seeds.rb" + Capybara.use_default_driver + # puts "After JS" + end + + config.after(:each) do + DatabaseCleaner.clean + # puts "After all" + end + +end