Skip to content

Commit 63aff0f

Browse files
committed
Merge pull request #16 from workgena/spec
RSpec and Travis
2 parents 94d92f0 + c4464a1 commit 63aff0f

13 files changed

+317
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
/tmp/
1010
/.idea
1111
.DS_Store
12+
/spec/rails

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
script: bundle exec rspec spec
2+
rvm:
3+
- 2.1.5
4+
- 2.2.0
5+
- 2.3.0
6+
before_install:
7+
- gem install bundler -v '= 1.9.3'
8+
- gem update --system
9+
- gem --version

Gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,16 @@ source 'https://rubygems.org'
22

33
# Specify your gem's dependencies in activeadmin_scoped_collection_actions.gemspec
44
gemspec
5+
group :test do
6+
gem 'sprockets-rails', '2.3.3'
7+
gem 'rails', '4.2.0'
8+
gem 'rspec-rails'
9+
gem 'activeadmin', github: 'activeadmin', ref: 'd787029e5523be2eb2ed99816eb0cecca2b72862'
10+
gem 'sass-rails'
11+
gem 'sqlite3'
12+
gem 'launchy'
13+
gem 'database_cleaner'
14+
gem 'capybara'
15+
gem 'selenium-webdriver'
16+
gem 'poltergeist'
17+
end

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
f# ActiveAdmin Scoped Collection Actions
1+
[![Build Status](https://img.shields.io/travis/activeadmin-plugins/active_admin_scoped_collection_actions.svg)](https://travis-ci.org/activeadmin-plugins/active_admin_scoped_collection_actions)
2+
3+
# ActiveAdmin Scoped Collection Actions
24
Plugin for ActiveAdmin. Provides batch Update and Delete for scoped_collection (Filters + Scope) across all pages.
35

46
![Step 1](/screenshots/sidebar.png)

Rakefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
require "bundler/gem_tasks"
1+
require "bundler"
2+
require 'rake'
3+
Bundler.setup
4+
Bundler::GemHelper.install_tasks
5+
6+
# Import all our rake tasks
7+
FileList['tasks/**/*.rake'].each { |task| import task }

active_admin_scoped_collection_actions.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ Gem::Specification.new do |spec|
1717
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
1818
spec.require_paths = ["lib"]
1919

20-
spec.add_development_dependency "bundler", "~> 1.10"
20+
spec.add_development_dependency "bundler", "~> 1.8"
2121
spec.add_development_dependency "rake", "~> 10.0"
2222
end

lib/active_admin_scoped_collection_actions.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'activeadmin'
12
require 'active_admin_scoped_collection_actions/engine'
23
require 'active_admin_scoped_collection_actions/version'
34
require 'active_admin_scoped_collection_actions/dsl'

spec/authors_actions_spec.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
require 'spec_helper'
2+
3+
describe 'authors index', type: :feature, js: true do
4+
5+
before do
6+
Author.create!(name: 'John', last_name: 'Doe')
7+
Author.create!(name: 'Jane', last_name: 'Roe')
8+
end
9+
10+
before do
11+
add_author_resource
12+
end
13+
14+
before do
15+
visit '/admin/authors'
16+
end
17+
18+
context 'show scoped collection action in sidebar' do
19+
20+
it 'page has collection_actions_sidebar_section' do
21+
expect(page.find('#collection_actions_sidebar_section'))
22+
.to have_css('h3', text: 'Collection Actions')
23+
expect(page.find('#collection_actions_sidebar_section'))
24+
.to have_css('button', text: 'Update')
25+
expect(page.find('#collection_actions_sidebar_section'))
26+
.to have_css('button', text: 'Delete')
27+
end
28+
29+
end
30+
31+
32+
context 'scoped collection action UPDATE' do
33+
before do
34+
@today = Date.today
35+
36+
page.find('#collection_actions_sidebar_section button', text: 'Update').click
37+
page.within ('body>.active_admin_dialog_mass_update_by_filter') do
38+
page.find('input#mass_update_dialog_birthday').click
39+
page.find('input[name="birthday"]').click
40+
end
41+
page.find('.ui-datepicker .ui-datepicker-days-cell-over.ui-datepicker-today', visible: true).click
42+
page.within ('body>.active_admin_dialog_mass_update_by_filter') do
43+
page.find('button', text: 'OK').click
44+
end
45+
end
46+
47+
it 'new birthday was set for all authors' do
48+
expect(page).to have_css('.flashes .flash.flash_notice')
49+
expect(Author.all.map(&:birthday).uniq.count).to eq(1)
50+
expect(Author.take.birthday).to eq(@today)
51+
end
52+
end
53+
54+
55+
context 'scoped collection action DELETE' do
56+
before do
57+
page.find('#collection_actions_sidebar_section button', text: 'Delete').click
58+
end
59+
60+
context 'title' do
61+
it 'has predefined confirmation title' do
62+
expect(page).to have_css('.active_admin_dialog_mass_update_by_filter', text: 'Delete all?')
63+
end
64+
end
65+
66+
context 'action' do
67+
before do
68+
page.within ('body>.active_admin_dialog_mass_update_by_filter') do
69+
page.find('button', text: 'OK').click
70+
end
71+
end
72+
73+
it 'delete all authors' do
74+
expect(page).to have_css('.flashes .flash.flash_notice')
75+
expect(Author.count).to eq(0)
76+
end
77+
end
78+
end
79+
80+
81+
context
82+
83+
end

spec/posts_actions_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'spec_helper'
2+
3+
describe 'posts index', type: :feature, js: true do
4+
5+
before do
6+
@john = Author.create!(name: 'John', last_name: 'Doe')
7+
@jane = Author.create!(name: 'Jane', last_name: 'Roe')
8+
9+
Post.create!(title: 'John Post', body: '...', author: @john)
10+
Post.create!(title: 'Jane Post', body: '...', author: @jane)
11+
end
12+
13+
before do
14+
add_post_resource
15+
end
16+
17+
before do
18+
visit '/admin/posts'
19+
end
20+
21+
context 'update posts body and author fields' do
22+
let(:new_body_text) { 'Text here...' }
23+
let(:new_author) { @jane }
24+
25+
before do
26+
page.find('#collection_actions_sidebar_section button', text: 'Update').click
27+
page.within ('body>.active_admin_dialog_mass_update_by_filter') do
28+
page.find('input#mass_update_dialog_body').click
29+
page.find('input[name="body"]').set(new_body_text)
30+
31+
page.find('input#mass_update_dialog_author_id').click
32+
page.find('select[name="author_id"]').select(new_author.name)
33+
page.find('button', text: 'OK').click
34+
end
35+
end
36+
37+
it 'update successfully' do
38+
expect(page).to have_css('.flashes .flash.flash_notice')
39+
expect(Post.all.map(&:body).uniq).to match_array([new_body_text])
40+
expect(Post.all.map(&:author).uniq).to match_array([new_author])
41+
end
42+
end
43+
44+
end

spec/spec_helper.rb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
$LOAD_PATH.unshift(File.dirname(__FILE__))
2+
$LOAD_PATH << File.expand_path('../support', __FILE__)
3+
4+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5+
require "bundler"
6+
Bundler.setup
7+
8+
ENV['RAILS_ENV'] = 'test'
9+
# Ensure the Active Admin load path is happy
10+
require 'rails'
11+
ENV['RAILS'] = Rails.version
12+
ENV['RAILS_ROOT'] = File.expand_path("../rails/rails-#{ENV['RAILS']}", __FILE__)
13+
# Create the test app if it doesn't exists
14+
unless File.exists?(ENV['RAILS_ROOT'])
15+
system 'rake setup'
16+
end
17+
18+
require 'active_model'
19+
# require ActiveRecord to ensure that Ransack loads correctly
20+
require 'active_record'
21+
require 'active_admin'
22+
ActiveAdmin.application.load_paths = [ENV['RAILS_ROOT'] + "/app/admin"]
23+
require ENV['RAILS_ROOT'] + '/config/environment.rb'
24+
# Disabling authentication in specs so that we don't have to worry about
25+
# it allover the place
26+
ActiveAdmin.application.authentication_method = false
27+
ActiveAdmin.application.current_user_method = false
28+
29+
require 'rspec/rails'
30+
require 'support/admin'
31+
require 'capybara/rails'
32+
require 'capybara/rspec'
33+
require 'capybara/poltergeist'
34+
35+
36+
RSpec.configure do |config|
37+
config.use_transactional_fixtures = false
38+
39+
config.before(:suite) do
40+
DatabaseCleaner.strategy = :truncation
41+
DatabaseCleaner.clean_with(:truncation)
42+
end
43+
config.before(:each) do
44+
DatabaseCleaner.strategy = :truncation
45+
DatabaseCleaner.start
46+
end
47+
config.after(:each) do
48+
DatabaseCleaner.clean
49+
end
50+
51+
end
52+
53+
# RSpec.configure do |config|
54+
# config.before(:each, js: true) do
55+
# page.driver.browser.manage.window.maximize if page.driver.browser.respond_to?(:manage)
56+
# end
57+
# end
58+
# Capybara.javascript_driver = :selenium
59+
60+
Capybara.register_driver :poltergeist do |app|
61+
Capybara::Poltergeist::Driver.new(app, {
62+
js_errors: true,
63+
timeout: 80,
64+
debug: true,
65+
:phantomjs_options => ['--debug=no', '--load-images=no']
66+
})
67+
end
68+
Capybara.javascript_driver = :poltergeist

0 commit comments

Comments
 (0)