Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make usable with Refinery CMS 2.0.0.

  • Loading branch information...
commit 368a1e1df57371bfe497d73ba7907e32b137ccc2 1 parent f16c61a
@ugisozols ugisozols authored
View
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+Gemfile.lock
+spec/dummy
View
76 Gemfile
@@ -0,0 +1,76 @@
+source 'http://rubygems.org'
+
+gemspec
+
+gem 'friendly_id', :git => 'git://github.com/norman/friendly_id.git'
+
+git 'git://github.com/resolve/refinerycms.git' do
+ gem 'refinerycms'
+
+ group :development, :test do
+ gem 'refinerycms-testing'
+ end
+end
+
+group :development, :test do
+ require 'rbconfig'
+
+ platforms :jruby do
+ gem 'activerecord-jdbcsqlite3-adapter'
+ gem 'activerecord-jdbcmysql-adapter'
+ gem 'activerecord-jdbcpostgresql-adapter'
+ gem 'jruby-openssl'
+ end
+
+ unless defined?(JRUBY_VERSION)
+ gem 'sqlite3'
+ gem 'mysql2'
+ gem 'pg'
+ end
+
+ platforms :mswin, :mingw do
+ gem 'win32console'
+ gem 'rb-fchange', '~> 0.0.5'
+ gem 'rb-notifu', '~> 0.0.4'
+ end
+
+ platforms :ruby do
+ gem 'spork', '0.9.0.rc9'
+ gem 'guard-spork'
+
+ unless ENV['TRAVIS']
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
+ gem 'rb-fsevent', '>= 0.3.9'
+ gem 'growl', '~> 1.0.3'
+ end
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
+ gem 'rb-inotify', '>= 0.5.1'
+ gem 'libnotify', '~> 0.1.3'
+ gem 'therubyracer', '~> 0.9.9'
+ end
+ end
+ end
+
+ platforms :jruby do
+ unless ENV['TRAVIS']
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
+ gem 'growl', '~> 1.0.3'
+ end
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
+ gem 'rb-inotify', '>= 0.5.1'
+ gem 'libnotify', '~> 0.1.3'
+ end
+ end
+ end
+end
+
+# Refinery/rails should pull in the proper versions of these
+group :assets do
+ gem 'sass-rails'
+ gem 'coffee-rails'
+ gem 'uglifier'
+end
+
+gem 'jquery-rails'
+
+gem 'refinerycms-jobs', :path => 'spec/dummy/vendor/extensions'
View
19 Rakefile
@@ -0,0 +1,19 @@
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
+ENGINE_PATH = File.dirname(__FILE__)
+APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
+
+if File.exists?(APP_RAKEFILE)
+ load 'rails/tasks/engine.rake'
+end
+
+require "refinerycms-testing"
+Refinery::Testing::Railtie.load_tasks
+Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
+
+load File.expand_path('../tasks/rspec.rake', __FILE__)
View
2  app/views/refinery/shared/_search.html.erb
@@ -1,4 +1,4 @@
-<%= form_tag main_app.search_path do -%>
+<%= form_tag refinery.search_path do -%>
<%= text_field_tag :query, {}, {:type => "search",
:placeholder => "Search site for...",
:value => (params[:query] if params[:query])} %>
View
6 config/routes.rb
@@ -1,5 +1,3 @@
-Rails.application.routes.draw do
- scope(:module => :refinery) do
- match "/search", :to => 'search#show', :as => 'search'
- end
+Refinery::Core::Engine.routes.draw do
+ match "/search", :to => 'search#show', :as => 'search'
end
View
2  db/migrate/01_create_search_page.rb
@@ -1,7 +1,6 @@
class CreateSearchPage < ActiveRecord::Migration
def up
- load(Rails.root.join('db', 'seeds', 'refinerycms_search.rb'))
end
def down
@@ -12,7 +11,6 @@ def down
if defined?(Refinery::Page)
Refinery::Page.delete_all({:link_url => "/search"})
end
-
end
end
View
12 db/seeds/refinerycms_search.rb → db/seeds.rb
@@ -1,25 +1,23 @@
-if defined?(::Refinery::User)
+if defined?(Refinery::User)
Refinery::User.all.each do |user|
if user.plugins.where(:name => 'refinerycms_search').blank?
- user.plugins.create(:name => 'refinerycms_search',
- :position => (user.plugins.maximum(:position) || -1) +1)
+ user.plugins.create(:name => 'refinerycms_search')
end
end
end
-if defined?(::Refinery::Page)
+if defined?(Refinery::Page)
unless Refinery::Page.where(:menu_match => "^/search.*$").any?
page = Refinery::Page.create(
:title => "Search Results",
:show_in_menu => false,
:link_url => "/search",
:deletable => false,
- :position => ((Refinery::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
:menu_match => "^/search.*$"
)
- Refinery::Page.default_parts.each do |default_page_part|
+ Refinery::Pages.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
end
end
-end
View
29 lib/gemspec.rb
@@ -1,29 +0,0 @@
-#!/usr/bin/env ruby
-version = '2.0.0'
-raise "Could not get version so gemspec can not be built" if version.nil?
-files = Dir.glob("**/*").flatten.reject do |file|
- file =~ /\.gem$/
-end
-
-gemspec = <<EOF
-Gem::Specification.new do |s|
- s.name = %q{refinerycms-search}
- s.version = %q{#{version}}
- s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
- s.summary = %q{Extra search handling for Refinery CMS}
- s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
- s.homepage = %q{http://refinerycms.com}
- s.email = %q{info@refinerycms.com}
- s.authors = ["Resolve Digital"]
- s.require_paths = %w(lib)
-
- s.add_dependency 'refinerycms-core', '~> 2.0.0'
-
- s.files = [
- '#{files.join("',\n '")}'
- ]
- s.require_path = 'lib'
-end
-EOF
-
-File.open(File.expand_path("../../refinerycms-search.gemspec", __FILE__), 'w').puts(gemspec)
View
15 lib/generators/refinery/search_generator.rb
@@ -1,7 +1,20 @@
module Refinery
class SearchGenerator < Rails::Generators::Base
- source_root File.expand_path('../../../', __FILE__)
+ def rake_db
+ rake("refinery_search:install:migrations")
+ end
+
+ def append_load_seed_data
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
+ append_file 'db/seeds.rb', :verbose => true do
+ <<-EOH
+
+# Added by Refinery CMS Search engine
+Refinery::Search::Engine.load_seed
+ EOH
+ end
+ end
end
end
View
18 lib/refinery/search.rb
@@ -0,0 +1,18 @@
+require "refinerycms-core"
+
+module Refinery
+ autoload :SearchGenerator, File.expand_path('../generators/refinery/search_generator', __FILE__)
+
+ module Search
+ require "refinery/search/engine"
+
+ class << self
+ attr_writer :root
+
+ def root
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
+ end
+ end
+ end
+end
+
View
27 lib/refinery/search/engine.rb
@@ -0,0 +1,27 @@
+module Refinery
+ module Search
+ class Engine < Rails::Engine
+ include Refinery::Engine
+
+ initializer "register refinery_search plugin" do
+ Refinery::Plugin.register do |plugin|
+ plugin.name = 'refinery_search'
+ plugin.version = 2.0
+ plugin.hide_from_menu = true
+ end
+ end
+
+ config.to_prepare do
+ module ::Refinery
+ class << self
+ attr_accessor :searchable_models
+
+ def searchable_models
+ @searchable_models ||= [(Refinery::Page if defined?(Refinery::Page))]
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
28 lib/refinerycms-search.rb
@@ -1,27 +1 @@
-module Refinery
- autoload :SearchGenerator, File.expand_path('../generators/refinery/search_generator', __FILE__)
-
- module Search
- class Engine < Rails::Engine
- config.to_prepare do
- module ::Refinery
- class << self
- attr_accessor :searchable_models
-
- def searchable_models
- @searchable_models ||= [(::Refinery::Page if defined?(::Refinery::Page))]
- end
- end
- end
- end
-
- config.after_initialize do
- ::Refinery::Plugin.register do |plugin|
- plugin.name = 'refinerycms_search'
- plugin.version = 2.0
- plugin.hide_from_menu = true
- end
- end
- end
- end
-end
+require "refinery/search"
View
43 refinerycms-search.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = %q{refinerycms-search}
s.version = %q{2.0.0}
- s.date = %q{2011-10-31}
+ s.date = "#{Date.today.strftime("%Y-%m-%d")}"
s.summary = %q{Extra search handling for Refinery CMS}
s.description = %q{Provides extra functionality for searching your frontend website using Refinery CMS.}
s.homepage = %q{http://refinerycms.com}
@@ -9,43 +9,8 @@ Gem::Specification.new do |s|
s.authors = ["Resolve Digital"]
s.require_paths = %w(lib)
- s.add_dependency 'refinerycms-core', '~> 2.0.0'
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- spec/*`.split("\n")
- s.files = [
- 'app',
- 'app/controllers',
- 'app/controllers/refinery',
- 'app/controllers/refinery/search_controller.rb',
- 'app/helpers',
- 'app/helpers/refinery',
- 'app/helpers/refinery/search_helper.rb',
- 'app/models',
- 'app/models/refinery',
- 'app/models/refinery/search_engine.rb',
- 'app/views',
- 'app/views/refinery',
- 'app/views/refinery/search',
- 'app/views/refinery/search/show.html.erb',
- 'app/views/refinery/shared',
- 'app/views/refinery/shared/_search.html.erb',
- 'config',
- 'config/locales',
- 'config/locales/bg.yml',
- 'config/locales/en.yml',
- 'config/routes.rb',
- 'db',
- 'db/migrate',
- 'db/migrate/01_create_search_page.rb',
- 'db/seeds',
- 'db/seeds/refinerycms_search.rb',
- 'lib',
- 'lib/gemspec.rb',
- 'lib/generators',
- 'lib/generators/refinery',
- 'lib/generators/refinery/search_generator.rb',
- 'lib/refinerycms-search.rb',
- 'readme.md',
- 'refinerycms-search.gemspec'
- ]
- s.require_path = 'lib'
+ s.add_dependency 'refinerycms-core', '~> 2.0.0'
end
View
25 spec/models/refinery/search_engine_spec.rb
@@ -0,0 +1,25 @@
+require "spec_helper"
+
+module Refinery
+ describe SearchEngine do
+ describe "#search" do
+ context "when page exist" do
+ # we're using page factory because search engine uses
+ # page model as default model
+ let!(:page) { FactoryGirl.create(:page, :title => "testy") }
+
+ it "returns an array consisting of mathcing pages" do
+ result = SearchEngine.search("testy")
+ result.should include(page)
+ end
+ end
+
+ context "when page does not exist" do
+ it "returns empty array" do
+ result = SearchEngine.search("ugisozols")
+ result.should be_empty
+ end
+ end
+ end
+ end
+end
View
59 spec/spec_helper.rb
@@ -0,0 +1,59 @@
+$VERBOSE = ENV['VERBOSE'] || false
+
+require 'rubygems'
+
+ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') unless defined?(ENGINE_RAILS_ROOT)
+
+def setup_environment
+ # Configure Rails Environment
+ ENV["RAILS_ENV"] ||= 'test'
+
+ require File.expand_path("../dummy/config/environment", __FILE__)
+
+ require 'rspec/rails'
+ require 'capybara/rspec'
+
+ Rails.backtrace_cleaner.remove_silencers!
+
+ RSpec.configure do |config|
+ config.mock_with :rspec
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+ end
+
+ # Set javascript driver for capybara
+ Capybara.javascript_driver = :selenium
+end
+
+def each_run
+ Rails.cache.clear
+ ActiveSupport::Dependencies.clear
+ FactoryGirl.reload
+
+ # Requires supporting files with custom matchers and macros, etc,
+ # in ./support/ and its subdirectories including factories.
+ ([ENGINE_RAILS_ROOT, Rails.root.to_s].uniq | Refinery::Plugins.registered.pathnames).map{|p|
+ Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
+ }.flatten.sort.each do |support_file|
+ require support_file
+ end
+end
+
+# If spork is available in the Gemfile it'll be used but we don't force it.
+unless (begin; require 'spork'; rescue LoadError; nil end).nil?
+ Spork.prefork do
+ # Loading more in this block will cause your tests to run faster. However,
+ # if you change any configuration or code from libraries loaded here, you'll
+ # need to restart spork for it take effect.
+ setup_environment
+ end
+
+ Spork.each_run do
+ # This code will be run each time you run your specs.
+ each_run
+ end
+else
+ setup_environment
+ each_run
+end
View
4 tasks/rspec.rake
@@ -0,0 +1,4 @@
+require 'rspec/core/rake_task'
+
+desc "Run specs"
+RSpec::Core::RakeTask.new
Please sign in to comment.
Something went wrong with that request. Please try again.