Skip to content

Commit

Permalink
run specs with engine_cart
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Jul 9, 2014
1 parent aa4dab0 commit 785f24c
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ Gemfile.lock
test/dummy/log
*.sqlite3
.rvmrc
spec/internal
tmp
coverage
pkg
.bundle
27 changes: 18 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
source "http://rubygems.org"

# Declare your gem's dependencies in blacklight-hierarchy-facets.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use debugger
# gem 'ruby-debug'
# sprockets 2.11.0 required by blacklight test app generated by engine_cart
# If we don't specify it here, we'll end up with a conflict with version in Gemfile.lock
gem 'sprockets', '2.11.0'

# sass 3.2.0 required by blacklight test app generated by engine_cart
# If we don't specify it here, we'll end up with a conflict with version in Gemfile.lock
gem 'sass', '~> 3.2.0'
gem 'bootstrap-sass', ">= 3.1.1.1"

# load local rails test instance Gemfile (engine cart adds this automagically)
#file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
#if File.exists?(file)
# puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
# instance_eval File.read(file)
#end

gem 'sqlite3'
gem 'fakeweb'
if File.exists?('spec/test_app_templates/Gemfile.extra')
eval File.read('spec/test_app_templates/Gemfile.extra'), nil, 'spec/test_app_templates/Gemfile.extra'
end
41 changes: 24 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
Bundler::GemHelper.install_tasks
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'engine_cart/rake_task'
TEST_APP_TEMPLATES = 'spec/test_app_templates'
TEST_APP = 'spec/internal'
#ZIP_URL = "https://github.com/projectblacklight/blacklight-jetty/archive/v4.0.0.zip"
APP_ROOT = File.expand_path("..", __FILE__)

task :default => :ci


require 'rspec/core/rake_task'

desc "Run specs"
RSpec::Core::RakeTask.new(:rspec) do |spec|
spec.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
end
task :spec => :rspec


desc "Execute Continuous Integration Build"
task :ci => ['engine_cart:clean', 'engine_cart:generate', 'rspec']

begin
require 'rdoc/task'
rescue LoadError
Expand All @@ -12,27 +35,11 @@ rescue LoadError
RDoc::Task = Rake::RDocTask
end

desc "Create rdoc"
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Blacklight::Hierarchy'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end




Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end


task :default => :test
3 changes: 2 additions & 1 deletion lib/blacklight/hierarchy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'blacklight/hierarchy/engine'
require 'blacklight/hierarchy/version'

module Blacklight
module Hierarchy
require 'blacklight/hierarchy/engine'
end
end
2 changes: 2 additions & 0 deletions lib/blacklight/hierarchy/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'blacklight'

module Blacklight
module Hierarchy
class Engine < Rails::Engine
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/blacklight_hierarchy/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rails/generators'

module BlacklightHierarchy
class Install < Rails::Generators::Base
end
end
4 changes: 0 additions & 4 deletions lib/tasks/blacklight_hierarchy_tasks.rake

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
require 'spec_helper'

describe "catalog" do
use_vcr_cassette "solr"

before(:each) do
CatalogController.blacklight_config = Blacklight::Configuration.new
CatalogController.configure_blacklight do |config|
config.index.show_link = 'title_display'
config.index.title_field = 'title_display'
config.default_solr_params = {
:rows => 10
}
response = "{'responseHeader'=>{'status'=>0,'QTime'=>4,'params'=>{'wt'=>'ruby','rows'=>'0'}},'response'=>{'numFound'=>30,'start'=>0,'maxScore'=>1.0,'docs' => [{'id' => '1', 'title_display'=>'title'}]},'facet_counts'=>{'facet_queries'=>{},'facet_fields'=>{'tag_facet'=>['a:b:c',30,'a:b:d', 25, 'a:c:d', 5, 'p:r:q', 25, 'x:y', 5, 'n', 1] }, 'facet_dates'=>{},'facet_ranges'=>{}}}"

config.add_facet_field 'tag_facet', :label => 'Tag', :partial => 'blacklight/hierarchy/facet_hierarchy'
config.facet_display = {
:hierarchy => {
'tag' => [nil]
}
}

config.facet_display = {
:hierarchy => {
'tag' => [nil]
}
}
end
end

it "should display the hierarchy" do
visit '/'

page.should have_selector('li.h-node', :content => 'a')
page.should have_selector('li.h-node > ul > li.h-node', :content => 'b')
page.should have_selector('li.h-node li.h-leaf', :content => 'c (30)')
Expand All @@ -39,3 +40,7 @@
page.all(:css, 'li.h-leaf a').map { |a| a[:href].to_s }.should include(catalog_index_path('f' => { 'tag_facet' => ['x:y'] }))
end
end




47 changes: 47 additions & 0 deletions spec/features/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'spec_helper'

describe "Facet Hierarchy", :vcr => {:cassette_name => "solr"} do

before(:each) do
CatalogController.blacklight_config = Blacklight::Configuration.new
CatalogController.configure_blacklight do |config|
# config.index.title_field = 'title_display'
# config.default_solr_params = {
# :rows => 10
# }
config.add_facet_field 'tag_facet', :label => 'Tag', :partial => 'blacklight/hierarchy/facet_hierarchy'
config.facet_display = {
:hierarchy => {
'tag' => [nil]
}
}
config.default_solr_params[:'facet.field'] = config.facet_fields.keys
end
end

it 'uses the solr cassette' do
expect(VCR.current_cassette.name).to eql "solr"
end

it "should display the hierarchy" do
visit '/'
#p page.source
expect(page).to have_selector('li.h-node', :text => 'a')
expect(page).to have_selector('li.h-node > ul > li.h-node', :text => 'b')
expect(page).to have_selector('li.h-node li.h-leaf', :text => 'c (30)')
expect(page).to have_selector('li.h-node li.h-leaf', :text => 'd (25)')
expect(page).to have_selector('li.h-node > ul > li.h-node', :text => 'c')
expect(page).to have_selector('li.h-node li.h-leaf', :text => 'd (5)')
expect(page).to have_selector('.facet-hierarchy > li.h-leaf', :text => 'n (1)')
expect(page).to have_selector('li.h-node li.h-leaf', :text => 'q (25)')
expect(page).to have_selector('li.h-node li.h-leaf', :text => 'x (5)')
end

it "should properly link the hierarchy" do
visit '/'
#p page.all(:css, 'li.h-leaf a')
expect(page.all(:css, 'li.h-leaf a').map { |a| a[:href].to_s }).to include(catalog_index_path('f' => { 'tag_facet' => ['n'] }))
expect(page.all(:css, 'li.h-leaf a').map { |a| a[:href].to_s }).to include(catalog_index_path('f' => { 'tag_facet' => ['a:b:c'] }))
expect(page.all(:css, 'li.h-leaf a').map { |a| a[:href].to_s }).to include(catalog_index_path('f' => { 'tag_facet' => ['x:y'] }))
end
end
32 changes: 21 additions & 11 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
require 'rubygems'
#require 'rubygems'
#require 'bundler/setup'

ENV["RAILS_ENV"] ||= "test"

require 'blacklight'
require 'blacklight/hierarchy'

require 'engine_cart'
EngineCart.load_application!

require 'coveralls'
Coveralls.wear!

require 'combustion'
require 'blacklight/engine'
require 'blacklight/hierarchy/engine'
require 'rsolr'
require 'rsolr-ext'
require 'rsolr-ext/response'
#require 'rsolr-ext'
#require 'rsolr-ext/response'
require 'capybara/rails'
require 'capybara/rspec'
Combustion.initialize!
require 'rspec/rails'


# Setup blacklight environment
Expand All @@ -17,16 +27,16 @@

VCR.configure do |config|
config.hook_into :fakeweb
# config.hook_into :webmock
config.cassette_library_dir = 'spec/vcr_cassettes'
config.configure_rspec_metadata!
config.default_cassette_options = {
:serialize_with => :psych
}
end

require 'rspec/rails'
require 'capybara/rails'

RSpec.configure do |config|
config.extend VCR::RSpec::Macros

config.infer_spec_type_from_file_location!
config.include Capybara::DSL
end
5 changes: 5 additions & 0 deletions spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
group :test do
gem 'generator_spec'
end

gem 'blacklight'
25 changes: 25 additions & 0 deletions spec/test_app_templates/lib/generators/test_app_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rails/generators'

class TestAppGenerator < Rails::Generators::Base
source_root File.expand_path("../../../../test_app_templates", __FILE__)

# This is only necessary for Rails 3
def remove_index
remove_file "public/index.html"
end

def run_blacklight_generator
say_status("warning", "GENERATING BL", :yellow)

Bundler.with_clean_env do
run "bundle install"
end

generate 'blacklight:install'
end

def run_hierarchy_install
generate 'blacklight_hierarchy:install'
end

end

0 comments on commit 785f24c

Please sign in to comment.