From 21b19db5a30fcb6db83f4ac9302cc94c6320a0db Mon Sep 17 00:00:00 2001 From: Jamie Winsor Date: Mon, 1 Aug 2011 11:27:28 -0700 Subject: refactor engine testing scenario Engine is now tested standalone by leveraging a dummy rails app Enable Guard for speedy testing Move factories to the more standard location `spec/factories/*` Update README with a Testing section Rename migrations to contain datetimestamps for their version to fix migration order issues when migrating the dummy application --- .gitignore | 3 + .rspec | 2 + Gemfile | 8 + Guardfile | 34 +++ Rakefile | 26 +++ app/assets/images/refinerycms-blog/.gitkeep | 0 app/assets/javascripts/refinerycms-blog/.gitkeep | 0 app/assets/stylesheets/refinerycms-blog/.gitkeep | 0 app/controllers/.gitkeep | 0 app/helpers/.gitkeep | 0 app/models/.gitkeep | 0 app/views/.gitkeep | 0 config/cucumber.yml | 10 + config/environment.rb | 3 + db/migrate/1_create_blog_structure.rb | 54 ----- db/migrate/20110803223522_create_blog_structure.rb | 54 +++++ .../20110803223523_add_user_id_to_blog_posts.rb | 7 + ...20110803223524_acts_as_taggable_on_migration.rb | 28 +++ .../20110803223525_create_seo_meta_for_blog.rb | 25 +++ db/migrate/20110803223526_add_cached_slugs.rb | 6 + ...803223527_add_custom_url_field_to_blog_posts.rb | 5 + ...223528_add_custom_teaser_field_to_blog_posts.rb | 6 + ...803223529_add_primary_key_to_categorizations.rb | 14 ++ db/migrate/2_add_user_id_to_blog_posts.rb | 7 - db/migrate/3_acts_as_taggable_on_migration.rb | 28 --- db/migrate/4_create_seo_meta_for_blog.rb | 25 --- db/migrate/5_add_cached_slugs.rb | 6 - db/migrate/6_add_custom_url_field_to_blog_posts.rb | 5 - .../7_add_custom_teaser_field_to_blog_posts.rb | 6 - db/migrate/8_add_primary_key_to_categorizations.rb | 14 -- features/step_definitions/authors_steps.rb | 7 + features/step_definitions/category_steps.rb | 11 + features/step_definitions/tags_steps.rb | 13 ++ features/step_definitions/user_steps.rb | 42 ++++ features/step_definitions/web_steps.rb | 196 +++++++++++++++++ features/support/env.rb | 50 +++++ features/support/paths.rb | 34 ++- features/support/selectors.rb | 39 ++++ features/support/step_definitions/authors_steps.rb | 7 - .../support/step_definitions/category_steps.rb | 11 - features/support/step_definitions/tags_steps.rb | 13 -- lib/refinery/blog/engine.rb | 21 ++ lib/refinerycms-blog.rb | 28 +-- readme.md | 17 +- refinerycms-blog.gemspec | 13 ++ script/cucumber | 10 + script/rails | 6 + spec/dummy/.gitignore | 77 +++++++ spec/dummy/Rakefile | 7 + spec/dummy/app/assets/javascripts/admin.js | 7 + spec/dummy/app/assets/javascripts/application.js | 9 + spec/dummy/app/assets/stylesheets/application.css | 1 + .../app/assets/stylesheets/application.css.backup | 1 + spec/dummy/app/assets/stylesheets/formatting.css | 4 + spec/dummy/app/assets/stylesheets/home.css | 4 + spec/dummy/app/assets/stylesheets/theme.css | 4 + .../app/controllers/application_controller.rb | 3 + spec/dummy/app/helpers/application_helper.rb | 2 + spec/dummy/app/mailers/.gitkeep | 0 spec/dummy/app/models/.gitkeep | 0 .../app/views/layouts/application.html.erb.backup | 14 ++ spec/dummy/app/views/sitemap/index.xml.builder | 25 +++ spec/dummy/autotest/autotest.rb | 17 ++ spec/dummy/autotest/discover.rb | 2 + spec/dummy/config.ru | 4 + spec/dummy/config/application.rb | 42 ++++ spec/dummy/config/boot.rb | 10 + spec/dummy/config/database.yml | 25 +++ spec/dummy/config/database.yml.mysql | 20 ++ spec/dummy/config/database.yml.postgresql | 55 +++++ spec/dummy/config/database.yml.sqlite3 | 26 +++ spec/dummy/config/environment.rb | 5 + spec/dummy/config/environments/development.rb | 31 +++ spec/dummy/config/environments/production.rb | 55 +++++ spec/dummy/config/environments/test.rb | 43 ++++ .../config/initializers/backtrace_silencers.rb | 7 + spec/dummy/config/initializers/devise.rb | 144 +++++++++++++ spec/dummy/config/initializers/inflections.rb | 10 + spec/dummy/config/initializers/mime_types.rb | 5 + spec/dummy/config/initializers/secret_token.rb | 7 + spec/dummy/config/initializers/session_store.rb | 8 + spec/dummy/config/initializers/wrap_parameters.rb | 12 ++ spec/dummy/config/locales/en.yml | 5 + spec/dummy/config/routes.rb | 58 +++++ ...0110802081556_create_refinerycms_core_schema.rb | 23 ++ .../migrate/20110802081557_add_locale_to_slugs.rb | 13 ++ ...802081558_create_refinerycms_settings_schema.rb | 24 +++ ...02081559_add_value_type_to_refinery_settings.rb | 9 + ...560_create_refinerycms_authentication_schema.rb | 48 +++++ ...802081561_add_missing_indexes_to_roles_users.rb | 11 + .../20110802081562_change_to_devise_users_table.rb | 31 +++ ...10802081563_add_remember_created_at_to_users.rb | 5 + ...110802081564_remove_password_salt_from_users.rb | 13 ++ ...10802081565_create_refinerycms_images_schema.rb | 23 ++ ...110802081566_create_refinerycms_pages_schema.rb | 56 +++++ .../20110802081567_translate_page_plugin.rb | 38 ++++ ...20110802081568_remove_cached_slug_from_pages.rb | 11 + ...110802081569_translate_custom_title_on_pages.rb | 26 +++ ...02081570_remove_translated_fields_from_pages.rb | 13 ++ .../db/migrate/20110802081571_create_seo_meta.rb | 86 ++++++++ .../20110802081572_create_add_template_columns.rb | 11 + ...02081573_create_refinerycms_resources_schema.rb | 21 ++ spec/dummy/db/schema.rb | 239 +++++++++++++++++++++ spec/dummy/db/seeds.rb | 5 + spec/dummy/db/seeds/pages.rb | 63 ++++++ spec/dummy/lib/assets/.gitkeep | 0 spec/dummy/log/.gitkeep | 0 spec/dummy/public/404.html | 26 +++ spec/dummy/public/422.html | 26 +++ spec/dummy/public/500.html | 26 +++ spec/dummy/public/favicon.ico | 0 spec/dummy/script/rails | 6 + spec/factories/blog_categories.rb | 3 + spec/factories/blog_comments.rb | 6 + spec/factories/blog_posts.rb | 7 + spec/factories/user.rb | 27 +++ spec/models/refinery/blog_post_spec.rb | 4 +- spec/rcov.opts | 2 + spec/requests/blog_categories_spec.rb | 4 +- spec/requests/blog_posts_spec.rb | 32 +-- spec/requests/manage_blog_posts_spec.rb | 9 +- spec/spec_helper.rb | 48 +++++ spec/support/refinery/factories/blog_categories.rb | 3 - spec/support/refinery/factories/blog_comments.rb | 6 - spec/support/refinery/factories/blog_posts.rb | 7 - 125 files changed, 2399 insertions(+), 255 deletions(-) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Guardfile create mode 100644 Rakefile create mode 100644 app/assets/images/refinerycms-blog/.gitkeep create mode 100644 app/assets/javascripts/refinerycms-blog/.gitkeep create mode 100644 app/assets/stylesheets/refinerycms-blog/.gitkeep create mode 100644 app/controllers/.gitkeep create mode 100644 app/helpers/.gitkeep create mode 100644 app/models/.gitkeep create mode 100644 app/views/.gitkeep create mode 100644 config/cucumber.yml create mode 100644 config/environment.rb delete mode 100644 db/migrate/1_create_blog_structure.rb create mode 100644 db/migrate/20110803223522_create_blog_structure.rb create mode 100644 db/migrate/20110803223523_add_user_id_to_blog_posts.rb create mode 100644 db/migrate/20110803223524_acts_as_taggable_on_migration.rb create mode 100644 db/migrate/20110803223525_create_seo_meta_for_blog.rb create mode 100644 db/migrate/20110803223526_add_cached_slugs.rb create mode 100644 db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb create mode 100644 db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb create mode 100644 db/migrate/20110803223529_add_primary_key_to_categorizations.rb delete mode 100644 db/migrate/2_add_user_id_to_blog_posts.rb delete mode 100644 db/migrate/3_acts_as_taggable_on_migration.rb delete mode 100644 db/migrate/4_create_seo_meta_for_blog.rb delete mode 100644 db/migrate/5_add_cached_slugs.rb delete mode 100644 db/migrate/6_add_custom_url_field_to_blog_posts.rb delete mode 100644 db/migrate/7_add_custom_teaser_field_to_blog_posts.rb delete mode 100644 db/migrate/8_add_primary_key_to_categorizations.rb create mode 100644 features/step_definitions/authors_steps.rb create mode 100644 features/step_definitions/category_steps.rb create mode 100644 features/step_definitions/tags_steps.rb create mode 100644 features/step_definitions/user_steps.rb create mode 100644 features/step_definitions/web_steps.rb create mode 100644 features/support/env.rb create mode 100644 features/support/selectors.rb delete mode 100644 features/support/step_definitions/authors_steps.rb delete mode 100644 features/support/step_definitions/category_steps.rb delete mode 100644 features/support/step_definitions/tags_steps.rb create mode 100644 lib/refinery/blog/engine.rb create mode 100755 script/cucumber create mode 100755 script/rails create mode 100644 spec/dummy/.gitignore create mode 100644 spec/dummy/Rakefile create mode 100644 spec/dummy/app/assets/javascripts/admin.js create mode 100644 spec/dummy/app/assets/javascripts/application.js create mode 100644 spec/dummy/app/assets/stylesheets/application.css create mode 100644 spec/dummy/app/assets/stylesheets/application.css.backup create mode 100644 spec/dummy/app/assets/stylesheets/formatting.css create mode 100644 spec/dummy/app/assets/stylesheets/home.css create mode 100644 spec/dummy/app/assets/stylesheets/theme.css create mode 100644 spec/dummy/app/controllers/application_controller.rb create mode 100644 spec/dummy/app/helpers/application_helper.rb create mode 100644 spec/dummy/app/mailers/.gitkeep create mode 100644 spec/dummy/app/models/.gitkeep create mode 100644 spec/dummy/app/views/layouts/application.html.erb.backup create mode 100644 spec/dummy/app/views/sitemap/index.xml.builder create mode 100644 spec/dummy/autotest/autotest.rb create mode 100644 spec/dummy/autotest/discover.rb create mode 100644 spec/dummy/config.ru create mode 100644 spec/dummy/config/application.rb create mode 100644 spec/dummy/config/boot.rb create mode 100644 spec/dummy/config/database.yml create mode 100644 spec/dummy/config/database.yml.mysql create mode 100644 spec/dummy/config/database.yml.postgresql create mode 100644 spec/dummy/config/database.yml.sqlite3 create mode 100644 spec/dummy/config/environment.rb create mode 100644 spec/dummy/config/environments/development.rb create mode 100644 spec/dummy/config/environments/production.rb create mode 100644 spec/dummy/config/environments/test.rb create mode 100644 spec/dummy/config/initializers/backtrace_silencers.rb create mode 100644 spec/dummy/config/initializers/devise.rb create mode 100644 spec/dummy/config/initializers/inflections.rb create mode 100644 spec/dummy/config/initializers/mime_types.rb create mode 100644 spec/dummy/config/initializers/secret_token.rb create mode 100644 spec/dummy/config/initializers/session_store.rb create mode 100644 spec/dummy/config/initializers/wrap_parameters.rb create mode 100644 spec/dummy/config/locales/en.yml create mode 100644 spec/dummy/config/routes.rb create mode 100644 spec/dummy/db/migrate/20110802081556_create_refinerycms_core_schema.rb create mode 100644 spec/dummy/db/migrate/20110802081557_add_locale_to_slugs.rb create mode 100644 spec/dummy/db/migrate/20110802081558_create_refinerycms_settings_schema.rb create mode 100644 spec/dummy/db/migrate/20110802081559_add_value_type_to_refinery_settings.rb create mode 100644 spec/dummy/db/migrate/20110802081560_create_refinerycms_authentication_schema.rb create mode 100644 spec/dummy/db/migrate/20110802081561_add_missing_indexes_to_roles_users.rb create mode 100644 spec/dummy/db/migrate/20110802081562_change_to_devise_users_table.rb create mode 100644 spec/dummy/db/migrate/20110802081563_add_remember_created_at_to_users.rb create mode 100644 spec/dummy/db/migrate/20110802081564_remove_password_salt_from_users.rb create mode 100644 spec/dummy/db/migrate/20110802081565_create_refinerycms_images_schema.rb create mode 100644 spec/dummy/db/migrate/20110802081566_create_refinerycms_pages_schema.rb create mode 100644 spec/dummy/db/migrate/20110802081567_translate_page_plugin.rb create mode 100644 spec/dummy/db/migrate/20110802081568_remove_cached_slug_from_pages.rb create mode 100644 spec/dummy/db/migrate/20110802081569_translate_custom_title_on_pages.rb create mode 100644 spec/dummy/db/migrate/20110802081570_remove_translated_fields_from_pages.rb create mode 100644 spec/dummy/db/migrate/20110802081571_create_seo_meta.rb create mode 100644 spec/dummy/db/migrate/20110802081572_create_add_template_columns.rb create mode 100644 spec/dummy/db/migrate/20110802081573_create_refinerycms_resources_schema.rb create mode 100644 spec/dummy/db/schema.rb create mode 100644 spec/dummy/db/seeds.rb create mode 100644 spec/dummy/db/seeds/pages.rb create mode 100644 spec/dummy/lib/assets/.gitkeep create mode 100644 spec/dummy/log/.gitkeep create mode 100644 spec/dummy/public/404.html create mode 100644 spec/dummy/public/422.html create mode 100644 spec/dummy/public/500.html create mode 100644 spec/dummy/public/favicon.ico create mode 100755 spec/dummy/script/rails create mode 100644 spec/factories/blog_categories.rb create mode 100644 spec/factories/blog_comments.rb create mode 100644 spec/factories/blog_posts.rb create mode 100644 spec/factories/user.rb create mode 100644 spec/rcov.opts create mode 100644 spec/spec_helper.rb delete mode 100644 spec/support/refinery/factories/blog_categories.rb delete mode 100644 spec/support/refinery/factories/blog_comments.rb delete mode 100644 spec/support/refinery/factories/blog_posts.rb diff --git a/.gitignore b/.gitignore index 9c1a2c5..2c06a4c 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ nbproject # Capybara Bug capybara-*html + +.rvmrc +Gemfile.lock diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4d52986 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color spec +--drb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..dab5e38 --- /dev/null +++ b/Gemfile @@ -0,0 +1,8 @@ +source "http://rubygems.org" + +## Uncomment the following lines to develop against a local clone of refinery +# gem 'refinerycms', :path => '~/Code/refinerycms' +# gem 'refinerycms-generators', :path => '~/Code/refinerycms-generators' +# gem 'seo_meta', :git => 'git://github.com/parndt/seo_meta.git' + +gemspec diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..91d89e0 --- /dev/null +++ b/Guardfile @@ -0,0 +1,34 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^spec/support/(.+)\.rb$}) { "spec" } + watch('spec/spec_helper.rb') { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + # Capybara request specs + watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } +end + +guard 'cucumber' do + watch(%r{^features/.+\.feature$}) + watch(%r{^features/support/.+$}) { 'features' } + watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' } +end + +guard 'spork', :wait => 60, :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do + watch('config/application.rb') + watch('config/environment.rb') + watch(%r{^config/environments/.+\.rb$}) + watch(%r{^config/initializers/.+\.rb$}) + watch('spec/spec_helper.rb') +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..699f74d --- /dev/null +++ b/Rakefile @@ -0,0 +1,26 @@ +#!/usr/bin/env rake +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end +begin + require 'rdoc/task' +rescue LoadError + require 'rdoc/rdoc' + require 'rake/rdoctask' + RDoc::Task = Rake::RDocTask +end + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'RefinerycmsBlog' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + +Bundler::GemHelper.install_tasks diff --git a/app/assets/images/refinerycms-blog/.gitkeep b/app/assets/images/refinerycms-blog/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/refinerycms-blog/.gitkeep b/app/assets/javascripts/refinerycms-blog/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/refinerycms-blog/.gitkeep b/app/assets/stylesheets/refinerycms-blog/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/.gitkeep b/app/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/helpers/.gitkeep b/app/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.gitkeep b/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/.gitkeep b/app/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/config/cucumber.yml b/config/cucumber.yml new file mode 100644 index 0000000..368422a --- /dev/null +++ b/config/cucumber.yml @@ -0,0 +1,10 @@ +<% +ENV["RAILS_ENV"] ||= "test" +require ::File.expand_path('../spec/dummy/config/environment', __FILE__) +rerun = IO.read('rerun.txt') if File.file?('rerun.txt') +rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" +std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip -r features" +%> +default: <%= std_opts %> +wip: --tags @wip:3 --wip features +rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..5cdbfa5 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,3 @@ +# TODO: Remove this when you figure out how to get Cucumber to look for the +# environment file in the dummy app instead of within the project root +require File.expand_path('../../spec/dummy/config/environment', __FILE__) diff --git a/db/migrate/1_create_blog_structure.rb b/db/migrate/1_create_blog_structure.rb deleted file mode 100644 index 612584e..0000000 --- a/db/migrate/1_create_blog_structure.rb +++ /dev/null @@ -1,54 +0,0 @@ -class CreateBlogStructure < ActiveRecord::Migration - - def up - create_table Refinery::BlogPost.table_name, :id => true do |t| - t.string :title - t.text :body - t.boolean :draft - t.datetime :published_at - t.timestamps - end - - add_index Refinery::BlogPost.table_name, :id - - create_table Refinery::BlogComment.table_name, :id => true do |t| - t.integer :blog_post_id - t.boolean :spam - t.string :name - t.string :email - t.text :body - t.string :state - t.timestamps - end - - add_index Refinery::BlogComment.table_name, :id - - create_table Refinery::BlogCategory.table_name, :id => true do |t| - t.string :title - t.timestamps - end - - add_index Refinery::BlogCategory.table_name, :id - - create_table Refinery::Categorization.table_name, :id => true do |t| - t.integer :blog_category_id - t.integer :blog_post_id - end - - add_index Refinery::Categorization.table_name, [:blog_category_id, :blog_post_id], :name => 'index_blog_categories_blog_posts_on_bc_and_bp' - - load(Rails.root.join('db', 'seeds', 'refinerycms_blog.rb').to_s) - end - - def down - Refinery::UserPlugin.destroy_all({:name => "refinerycms_blog"}) - - Refinery::Page.delete_all({:link_url => "/blog"}) - - drop_table Refinery::BlogPost.table_name - drop_table Refinery::BlogComment.table_name - drop_table Refinery::Category.table_name - drop_table Refinery::Categorization.table_name - end - -end diff --git a/db/migrate/20110803223522_create_blog_structure.rb b/db/migrate/20110803223522_create_blog_structure.rb new file mode 100644 index 0000000..f6f5b2d --- /dev/null +++ b/db/migrate/20110803223522_create_blog_structure.rb @@ -0,0 +1,54 @@ +class CreateBlogStructure < ActiveRecord::Migration + + def up + create_table Refinery::BlogPost.table_name, :id => true do |t| + t.string :title + t.text :body + t.boolean :draft + t.datetime :published_at + t.timestamps + end + + add_index Refinery::BlogPost.table_name, :id + + create_table Refinery::BlogComment.table_name, :id => true do |t| + t.integer :blog_post_id + t.boolean :spam + t.string :name + t.string :email + t.text :body + t.string :state + t.timestamps + end + + add_index Refinery::BlogComment.table_name, :id + + create_table Refinery::BlogCategory.table_name, :id => true do |t| + t.string :title + t.timestamps + end + + add_index Refinery::BlogCategory.table_name, :id + + create_table Refinery::Categorization.table_name, :id => true do |t| + t.integer :blog_category_id + t.integer :blog_post_id + end + + add_index Refinery::Categorization.table_name, [:blog_category_id, :blog_post_id], :name => 'index_blog_categories_blog_posts_on_bc_and_bp' + + load(File.expand_path('../../seeds/refinerycms_blog.rb', __FILE__)) + end + + def down + Refinery::UserPlugin.destroy_all({:name => "refinerycms_blog"}) + + Refinery::Page.delete_all({:link_url => "/blog"}) + + drop_table Refinery::BlogPost.table_name + drop_table Refinery::BlogComment.table_name + drop_table Refinery::Category.table_name + drop_table Refinery::Categorization.table_name + end + +end diff --git a/db/migrate/20110803223523_add_user_id_to_blog_posts.rb b/db/migrate/20110803223523_add_user_id_to_blog_posts.rb new file mode 100644 index 0000000..5be3224 --- /dev/null +++ b/db/migrate/20110803223523_add_user_id_to_blog_posts.rb @@ -0,0 +1,7 @@ +class AddUserIdToBlogPosts < ActiveRecord::Migration + + def change + add_column Refinery::BlogPost.table_name, :user_id, :integer + end + +end \ No newline at end of file diff --git a/db/migrate/20110803223524_acts_as_taggable_on_migration.rb b/db/migrate/20110803223524_acts_as_taggable_on_migration.rb new file mode 100644 index 0000000..812daf4 --- /dev/null +++ b/db/migrate/20110803223524_acts_as_taggable_on_migration.rb @@ -0,0 +1,28 @@ +class ActsAsTaggableOnMigration < ActiveRecord::Migration + def up + create_table :tags do |t| + t.string :name + end + + create_table :taggings do |t| + t.references :tag + + # You should make sure that the column created is + # long enough to store the required class names. + t.references :taggable, :polymorphic => true + t.references :tagger, :polymorphic => true + + t.string :context + + t.datetime :created_at + end + + add_index :taggings, :tag_id + add_index :taggings, [:taggable_id, :taggable_type, :context] + end + + def down + drop_table :taggings + drop_table :tags + end +end diff --git a/db/migrate/20110803223525_create_seo_meta_for_blog.rb b/db/migrate/20110803223525_create_seo_meta_for_blog.rb new file mode 100644 index 0000000..b1c3c31 --- /dev/null +++ b/db/migrate/20110803223525_create_seo_meta_for_blog.rb @@ -0,0 +1,25 @@ +class CreateSeoMetaForBlog < ActiveRecord::Migration + + def up + unless ::SeoMetum.table_exists? + create_table ::SeoMetum.table_name do |t| + t.integer :seo_meta_id + t.string :seo_meta_type + + t.string :browser_title + t.string :meta_keywords + t.text :meta_description + + t.timestamps + end + + add_index ::SeoMetum.table_name, :id + add_index ::SeoMetum.table_name, [:seo_meta_id, :seo_meta_type] + end + end + + def down + # can't drop the table because someone else might be using it. + end + +end diff --git a/db/migrate/20110803223526_add_cached_slugs.rb b/db/migrate/20110803223526_add_cached_slugs.rb new file mode 100644 index 0000000..9e39586 --- /dev/null +++ b/db/migrate/20110803223526_add_cached_slugs.rb @@ -0,0 +1,6 @@ +class AddCachedSlugs < ActiveRecord::Migration + def change + add_column Refinery::BlogCategory.table_name, :cached_slug, :string + add_column Refinery::BlogPost.table_name, :cached_slug, :string + end +end diff --git a/db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb b/db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb new file mode 100644 index 0000000..22b49a4 --- /dev/null +++ b/db/migrate/20110803223527_add_custom_url_field_to_blog_posts.rb @@ -0,0 +1,5 @@ +class AddCustomUrlFieldToBlogPosts < ActiveRecord::Migration + def change + add_column Refinery::BlogPost.table_name, :custom_url, :string + end +end diff --git a/db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb b/db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb new file mode 100644 index 0000000..9c50b97 --- /dev/null +++ b/db/migrate/20110803223528_add_custom_teaser_field_to_blog_posts.rb @@ -0,0 +1,6 @@ +class AddCustomTeaserFieldToBlogPosts < ActiveRecord::Migration + def change + add_column Refinery::BlogPost.table_name, :custom_teaser, :text + end +end + diff --git a/db/migrate/20110803223529_add_primary_key_to_categorizations.rb b/db/migrate/20110803223529_add_primary_key_to_categorizations.rb new file mode 100644 index 0000000..5bbfcf3 --- /dev/null +++ b/db/migrate/20110803223529_add_primary_key_to_categorizations.rb @@ -0,0 +1,14 @@ +class AddPrimaryKeyToCategorizations < ActiveRecord::Migration + def up + unless Refinery::Categorization.column_names.include?("id") + add_column Refinery::Categorization.table_name, :id, :primary_key + end + end + + def down + if Refinery::Categorization.column_names.include?("id") + remove_column Refinery::Categorization.table_name, :id + end + end +end + diff --git a/db/migrate/2_add_user_id_to_blog_posts.rb b/db/migrate/2_add_user_id_to_blog_posts.rb deleted file mode 100644 index 5be3224..0000000 --- a/db/migrate/2_add_user_id_to_blog_posts.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddUserIdToBlogPosts < ActiveRecord::Migration - - def change - add_column Refinery::BlogPost.table_name, :user_id, :integer - end - -end \ No newline at end of file diff --git a/db/migrate/3_acts_as_taggable_on_migration.rb b/db/migrate/3_acts_as_taggable_on_migration.rb deleted file mode 100644 index 812daf4..0000000 --- a/db/migrate/3_acts_as_taggable_on_migration.rb +++ /dev/null @@ -1,28 +0,0 @@ -class ActsAsTaggableOnMigration < ActiveRecord::Migration - def up - create_table :tags do |t| - t.string :name - end - - create_table :taggings do |t| - t.references :tag - - # You should make sure that the column created is - # long enough to store the required class names. - t.references :taggable, :polymorphic => true - t.references :tagger, :polymorphic => true - - t.string :context - - t.datetime :created_at - end - - add_index :taggings, :tag_id - add_index :taggings, [:taggable_id, :taggable_type, :context] - end - - def down - drop_table :taggings - drop_table :tags - end -end diff --git a/db/migrate/4_create_seo_meta_for_blog.rb b/db/migrate/4_create_seo_meta_for_blog.rb deleted file mode 100644 index b1c3c31..0000000 --- a/db/migrate/4_create_seo_meta_for_blog.rb +++ /dev/null @@ -1,25 +0,0 @@ -class CreateSeoMetaForBlog < ActiveRecord::Migration - - def up - unless ::SeoMetum.table_exists? - create_table ::SeoMetum.table_name do |t| - t.integer :seo_meta_id - t.string :seo_meta_type - - t.string :browser_title - t.string :meta_keywords - t.text :meta_description - - t.timestamps - end - - add_index ::SeoMetum.table_name, :id - add_index ::SeoMetum.table_name, [:seo_meta_id, :seo_meta_type] - end - end - - def down - # can't drop the table because someone else might be using it. - end - -end diff --git a/db/migrate/5_add_cached_slugs.rb b/db/migrate/5_add_cached_slugs.rb deleted file mode 100644 index 9e39586..0000000 --- a/db/migrate/5_add_cached_slugs.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddCachedSlugs < ActiveRecord::Migration - def change - add_column Refinery::BlogCategory.table_name, :cached_slug, :string - add_column Refinery::BlogPost.table_name, :cached_slug, :string - end -end diff --git a/db/migrate/6_add_custom_url_field_to_blog_posts.rb b/db/migrate/6_add_custom_url_field_to_blog_posts.rb deleted file mode 100644 index 22b49a4..0000000 --- a/db/migrate/6_add_custom_url_field_to_blog_posts.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCustomUrlFieldToBlogPosts < ActiveRecord::Migration - def change - add_column Refinery::BlogPost.table_name, :custom_url, :string - end -end diff --git a/db/migrate/7_add_custom_teaser_field_to_blog_posts.rb b/db/migrate/7_add_custom_teaser_field_to_blog_posts.rb deleted file mode 100644 index 9c50b97..0000000 --- a/db/migrate/7_add_custom_teaser_field_to_blog_posts.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddCustomTeaserFieldToBlogPosts < ActiveRecord::Migration - def change - add_column Refinery::BlogPost.table_name, :custom_teaser, :text - end -end - diff --git a/db/migrate/8_add_primary_key_to_categorizations.rb b/db/migrate/8_add_primary_key_to_categorizations.rb deleted file mode 100644 index 5bbfcf3..0000000 --- a/db/migrate/8_add_primary_key_to_categorizations.rb +++ /dev/null @@ -1,14 +0,0 @@ -class AddPrimaryKeyToCategorizations < ActiveRecord::Migration - def up - unless Refinery::Categorization.column_names.include?("id") - add_column Refinery::Categorization.table_name, :id, :primary_key - end - end - - def down - if Refinery::Categorization.column_names.include?("id") - remove_column Refinery::Categorization.table_name, :id - end - end -end - diff --git a/features/step_definitions/authors_steps.rb b/features/step_definitions/authors_steps.rb new file mode 100644 index 0000000..eaa5f32 --- /dev/null +++ b/features/step_definitions/authors_steps.rb @@ -0,0 +1,7 @@ +Then /^there should be (\d+) blog posts?$/ do |num| + ::Refinery::BlogPost.all.size == num +end + +Then /^the blog post should belong to me$/ do + ::Refinery::BlogPost.first.author.login == ::Refinery::User.last.login +end \ No newline at end of file diff --git a/features/step_definitions/category_steps.rb b/features/step_definitions/category_steps.rb new file mode 100644 index 0000000..3c197e2 --- /dev/null +++ b/features/step_definitions/category_steps.rb @@ -0,0 +1,11 @@ +Given /^there is a category titled "([^"]*)"$/ do |title| + @category = Factory.create(:blog_category, :title => title) +end + +Then /^the blog post should have ([\d]*) categor[yies]{1,3}$/ do |num_category| + ::Refinery::BlogPost.last.categories.count.should == num_category.to_i +end + +Then /^the blog post should have the category "([^"]*)"$/ do |category| + ::Refinery::BlogPost.last.categories.first.title.should == category +end diff --git a/features/step_definitions/tags_steps.rb b/features/step_definitions/tags_steps.rb new file mode 100644 index 0000000..d16f758 --- /dev/null +++ b/features/step_definitions/tags_steps.rb @@ -0,0 +1,13 @@ +Given /^there is a blog post titled "([^"]*)" and tagged "([^"]*)"$/ do |title, tag_name| + @blog_post = Factory.create(:blog_post, :title => title, :tag_list => tag_name) +end + +When /^I visit the tagged posts page for "([^"]*)"$/ do |tag_name| + @blog_post ||= Factory.create(:blog_post, :tag_list => tag_name) + tag = ::Refinery::BlogPost.tag_counts_on(:tags).first + visit tagged_posts_path(tag.id, tag_name.parameterize) +end + +Then /^the blog post should have the tags "([^"]*)"$/ do |tag_list| + ::Refinery::BlogPost.last.tag_list == tag_list.split(', ') +end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb new file mode 100644 index 0000000..002fa7d --- /dev/null +++ b/features/step_definitions/user_steps.rb @@ -0,0 +1,42 @@ +def login(options = {}) + options = {:user => @refinery_user}.merge(options) + visit new_refinery_user_session_path + fill_in("refinery_user_login", :with => options[:user].email) + fill_in("refinery_user_password", :with => 'greenandjuicy') + click_button("submit_button") +end + +Given /^I am a logged in refinery user$/i do + @refinery_user ||= Factory(:refinery_user) + login(:user => @refinery_user) +end + +Given /^I am a logged in refinery translator$/i do + @refinery_translator ||= Factory(:refinery_translator) + login(:user => @refinery_translator) +end + +Given /^I am a logged in customer$/i do + @user ||= Factory(:user) + login(:user => @user) +end + +Given /^A Refinery user exists$/i do + @refinery_user ||= Factory(:refinery_user) +end + +Given /^I have a user named "(.*)"$/ do |name| + @user = Factory(:user, :username => name) +end + +Given /^I have a refinery user named "(.*)"$/i do |name| + @refinery_user = Factory(:refinery_user, :username => name) +end + +Given /^I have no users$/ do + ::Refinery::User.delete_all +end + +Then /^I should have ([0-9]+) users?$/ do |count| + ::Refinery::User.count.should == count.to_i +end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb new file mode 100644 index 0000000..22abbf6 --- /dev/null +++ b/features/step_definitions/web_steps.rb @@ -0,0 +1,196 @@ +# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file +# instead of editing this one. Cucumber will automatically load all features/**/*.rb +# files. + +require 'uri' +require 'cgi' +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors")) + +module WithinHelpers + def with_scope(locator) + locator ? within(*selector_for(locator)) { yield } : yield + end +end +World(WithinHelpers) + +# Single-line step scoper +When /^(.*) within (.*[^:])$/ do |step, parent| + with_scope(parent) { When step } +end + +# Multi-line step scoper +When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string| + with_scope(parent) { When "#{step}:", table_or_string } +end + +Given /^(?:|I )am on (.+)$/ do |page_name| + visit path_to(page_name) +end + +When /^(?:|I )go to (.+)$/ do |page_name| + visit path_to(page_name) +end + +When /^(?:|I )press "([^"]*)"$/ do |button| + click_button(button) +end + +When /^(?:|I )follow "([^"]*)"$/ do |link| + click_link(link) +end + +When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value| + fill_in(field, :with => value) +end + +When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field| + fill_in(field, :with => value) +end + +# Use this to fill in an entire form with data from a table. Example: +# +# When I fill in the following: +# | Account Number | 5002 | +# | Expiry date | 2009-11-01 | +# | Note | Nice guy | +# | Wants Email? | | +# +# TODO: Add support for checkbox, select og option +# based on naming conventions. +# +When /^(?:|I )fill in the following:$/ do |fields| + fields.rows_hash.each do |name, value| + When %{I fill in "#{name}" with "#{value}"} + end +end + +When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field| + select(value, :from => field) +end + +When /^(?:|I )check "([^"]*)"$/ do |field| + check(field) +end + +When /^(?:|I )uncheck "([^"]*)"$/ do |field| + uncheck(field) +end + +When /^(?:|I )choose "([^"]*)"$/ do |field| + choose(field) +end + +When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field| + attach_file(field, File.expand_path(path)) +end + +Then /^(?:|I )should see "([^"]*)"$/ do |text| + if page.respond_to? :should + page.should have_content(text) + else + assert page.has_content?(text) + end +end + +Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp| + regexp = Regexp.new(regexp) + + if page.respond_to? :should + page.should have_xpath('//*', :text => regexp) + else + assert page.has_xpath?('//*', :text => regexp) + end +end + +Then /^(?:|I )should not see "([^"]*)"$/ do |text| + if page.respond_to? :should + page.should have_no_content(text) + else + assert page.has_no_content?(text) + end +end + +Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp| + regexp = Regexp.new(regexp) + + if page.respond_to? :should + page.should have_no_xpath('//*', :text => regexp) + else + assert page.has_no_xpath?('//*', :text => regexp) + end +end + +Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value| + with_scope(parent) do + field = find_field(field) + field_value = (field.tag_name == 'textarea') ? field.text : field.value + if field_value.respond_to? :should + field_value.should =~ /#{value}/ + else + assert_match(/#{value}/, field_value) + end + end +end + +Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value| + with_scope(parent) do + field = find_field(field) + field_value = (field.tag_name == 'textarea') ? field.text : field.value + if field_value.respond_to? :should_not + field_value.should_not =~ /#{value}/ + else + assert_no_match(/#{value}/, field_value) + end + end +end + +Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent| + with_scope(parent) do + field_checked = find_field(label)['checked'] + if field_checked.respond_to? :should + field_checked.should be_true + else + assert field_checked + end + end +end + +Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent| + with_scope(parent) do + field_checked = find_field(label)['checked'] + if field_checked.respond_to? :should + field_checked.should be_false + else + assert !field_checked + end + end +end + +Then /^(?:|I )should be on (.+)$/ do |page_name| + current_path = URI.parse(current_url).path + if current_path.respond_to? :should + current_path.should == path_to(page_name) + else + assert_equal path_to(page_name), current_path + end +end + +Then /^(?:|I )should have the following query string:$/ do |expected_pairs| + query = URI.parse(current_url).query + actual_params = query ? CGI.parse(query) : {} + expected_params = {} + expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')} + + if actual_params.respond_to? :should + actual_params.should == expected_params + else + assert_equal expected_params, actual_params + end +end + +Then /^show me the page$/ do + save_and_open_page +end diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..a84d601 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,50 @@ +require 'rubygems' +require 'bundler/setup' +require 'spork' + +Spork.prefork do + require 'cucumber/rails' + require 'capybara/rails' + require 'capybara/cucumber' + require 'capybara/session' + + require 'factory_girl' + require 'database_cleaner' + require 'database_cleaner/cucumber' + + Dir[File.expand_path("../../../spec/factories/*.rb", __FILE__)].each {|f| require f} + + include ::Devise::Controllers::UrlHelpers + + # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In + # order to ease the transition to Capybara we set the default here. If you'd + # prefer to use XPath just remove this line and adjust any selectors in your + # steps to use the XPath syntax. + Capybara.default_selector = :css + + # By default, any exception happening in your Rails application will bubble up + # to Cucumber so that your scenario will fail. This is a different from how + # your application behaves in the production environment, where an error page will + # be rendered instead. + # + # Sometimes we want to override this default behaviour and allow Rails to rescue + # exceptions and display an error page (just like when the app is running in production). + # Typical scenarios where you want to do this is when you test your error pages. + # There are two ways to allow Rails to rescue exceptions: + # + # 1) Tag your scenario (or feature) with @allow-rescue + # + # 2) Set the value below to true. Beware that doing this globally is not + # recommended as it will mask a lot of errors for you! + # + ActionController::Base.allow_rescue = false + + DatabaseCleaner.strategy = :truncation + + Before { DatabaseCleaner.start } + After { DatabaseCleaner.clean } +end + +Spork.each_run do + # This code will be run each time you run your specs. +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 1fdf9f8..f69b8fe 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -1,24 +1,18 @@ -module NavigationHelpers - module Refinery - module Blog - def path_to(page_name) - case page_name - when /the list of blog posts/ - refinery_admin_blog_posts_path - when /the new blog posts? form/ - new_refinery_admin_blog_post_path - else - begin - if page_name =~ /the blog post titled "?([^\"]*)"?/ and (page = BlogPost.find_by_title($1)).present? - self.url_for(page.url) - else - nil - end - rescue - nil - end - end +def path_to(page_name) + case page_name + when /the list of blog posts/ + refinery_admin_blog_posts_path + when /the new blog posts? form/ + new_refinery_admin_blog_post_path + else + begin + if page_name =~ /the blog post titled "?([^\"]*)"?/ and (page = BlogPost.find_by_title($1)).present? + self.url_for(page.url) + else + nil end + rescue + nil end end end diff --git a/features/support/selectors.rb b/features/support/selectors.rb new file mode 100644 index 0000000..44e34a4 --- /dev/null +++ b/features/support/selectors.rb @@ -0,0 +1,39 @@ +module HtmlSelectorsHelpers + # Maps a name to a selector. Used primarily by the + # + # When /^(.+) within (.+)$/ do |step, scope| + # + # step definitions in web_steps.rb + # + def selector_for(locator) + case locator + + when "the page" + "html > body" + + # Add more mappings here. + # Here is an example that pulls values out of the Regexp: + # + # when /^the (notice|error|info) flash$/ + # ".flash.#{$1}" + + # You can also return an array to use a different selector + # type, like: + # + # when /the header/ + # [:xpath, "//header"] + + # This allows you to provide a quoted selector as the scope + # for "within" steps as was previously the default for the + # web steps: + when /^"(.+)"$/ + $1 + + else + raise "Can't find mapping from \"#{locator}\" to a selector.\n" + + "Now, go and add a mapping in #{__FILE__}" + end + end +end + +World(HtmlSelectorsHelpers) diff --git a/features/support/step_definitions/authors_steps.rb b/features/support/step_definitions/authors_steps.rb deleted file mode 100644 index eaa5f32..0000000 --- a/features/support/step_definitions/authors_steps.rb +++ /dev/null @@ -1,7 +0,0 @@ -Then /^there should be (\d+) blog posts?$/ do |num| - ::Refinery::BlogPost.all.size == num -end - -Then /^the blog post should belong to me$/ do - ::Refinery::BlogPost.first.author.login == ::Refinery::User.last.login -end \ No newline at end of file diff --git a/features/support/step_definitions/category_steps.rb b/features/support/step_definitions/category_steps.rb deleted file mode 100644 index 3c197e2..0000000 --- a/features/support/step_definitions/category_steps.rb +++ /dev/null @@ -1,11 +0,0 @@ -Given /^there is a category titled "([^"]*)"$/ do |title| - @category = Factory.create(:blog_category, :title => title) -end - -Then /^the blog post should have ([\d]*) categor[yies]{1,3}$/ do |num_category| - ::Refinery::BlogPost.last.categories.count.should == num_category.to_i -end - -Then /^the blog post should have the category "([^"]*)"$/ do |category| - ::Refinery::BlogPost.last.categories.first.title.should == category -end diff --git a/features/support/step_definitions/tags_steps.rb b/features/support/step_definitions/tags_steps.rb deleted file mode 100644 index d16f758..0000000 --- a/features/support/step_definitions/tags_steps.rb +++ /dev/null @@ -1,13 +0,0 @@ -Given /^there is a blog post titled "([^"]*)" and tagged "([^"]*)"$/ do |title, tag_name| - @blog_post = Factory.create(:blog_post, :title => title, :tag_list => tag_name) -end - -When /^I visit the tagged posts page for "([^"]*)"$/ do |tag_name| - @blog_post ||= Factory.create(:blog_post, :tag_list => tag_name) - tag = ::Refinery::BlogPost.tag_counts_on(:tags).first - visit tagged_posts_path(tag.id, tag_name.parameterize) -end - -Then /^the blog post should have the tags "([^"]*)"$/ do |tag_list| - ::Refinery::BlogPost.last.tag_list == tag_list.split(', ') -end diff --git a/lib/refinery/blog/engine.rb b/lib/refinery/blog/engine.rb new file mode 100644 index 0000000..ef21472 --- /dev/null +++ b/lib/refinery/blog/engine.rb @@ -0,0 +1,21 @@ +module Refinery + module Blog + class Engine < Rails::Engine + config.to_prepare do + require 'refinery/blog/tabs' + end + + initializer "init plugin", :after => :set_routes_reloader do |app| + Refinery::Plugin.register do |plugin| + plugin.pathname = root + plugin.name = "refinerycms_blog" + plugin.url = app.routes.url_helpers.refinery_admin_blog_posts_path + plugin.menu_match = /^\/refinery\/blog\/?(posts|comments|categories)?/ + plugin.activity = { + :class => Refinery::BlogPost + } + end + end + end + end +end diff --git a/lib/refinerycms-blog.rb b/lib/refinerycms-blog.rb index 334380e..fafedf5 100644 --- a/lib/refinerycms-blog.rb +++ b/lib/refinerycms-blog.rb @@ -1,10 +1,14 @@ +require 'rubygems' +require 'bundler' +Bundler.require + require 'filters_spam' require File.expand_path('../generators/blog_generator', __FILE__) module Refinery module Blog - autoload :Version, File.expand_path('../refinery/blog/version', __FILE__) - autoload :Tab, File.expand_path("../refinery/blog/tabs", __FILE__) + autoload :Version, 'refinery/blog/version' + autoload :Tab, 'refinery/blog/tabs' class << self attr_accessor :root @@ -16,23 +20,7 @@ module Refinery ::Refinery::Blog::Version.to_s end end - - class Engine < Rails::Engine - config.to_prepare do - require File.expand_path('../refinery/blog/tabs', __FILE__) - end - - initializer "init plugin", :after => :set_routes_reloader do |app| - Refinery::Plugin.register do |plugin| - plugin.pathname = root - plugin.name = "refinerycms_blog" - plugin.url = app.routes.url_helpers.refinery_admin_blog_posts_path - plugin.menu_match = /^\/refinery\/blog\/?(posts|comments|categories)?/ - plugin.activity = { - :class => Refinery::BlogPost - } - end - end - end if defined?(Rails::Engine) end end + +require 'refinery/blog/engine' if defined?(Rails) diff --git a/readme.md b/readme.md index 32bf487..f5f0e53 100644 --- a/readme.md +++ b/readme.md @@ -27,4 +27,19 @@ Next, to install the blog plugin run: Finally migrate your database and you're done. - rake db:migrate \ No newline at end of file + rake db:migrate + +## Developing & Contributing + +### Testing + +Setup the test environment + + $ bundle install + $ bundle exec rake app:db:migrate + $ bundle exec rake app:db:test:prepare + +Run the test suite with [Guard](https://github.com/guard/guard) + + $ bundle exec guard start + \ No newline at end of file diff --git a/refinerycms-blog.gemspec b/refinerycms-blog.gemspec index dca15fb..91f2b07 100644 --- a/refinerycms-blog.gemspec +++ b/refinerycms-blog.gemspec @@ -16,7 +16,20 @@ Gem::Specification.new do |s| s.add_dependency 'seo_meta', '~> 1.1.0' # Development dependencies + s.add_development_dependency 'rake', '~> 0.9.2' + s.add_development_dependency 'rails', '3.1.0.rc5' s.add_development_dependency 'factory_girl' + s.add_development_dependency 'sqlite3' + s.add_development_dependency 'rspec' + s.add_development_dependency 'rspec-rails', '2.6.1.beta1' + s.add_development_dependency 'capybara' + s.add_development_dependency 'cucumber-rails' + s.add_development_dependency 'spork', '0.9.0.rc9' + s.add_development_dependency 'guard-spork' + s.add_development_dependency 'guard-rspec' + s.add_development_dependency 'guard-cucumber' + s.add_development_dependency 'rb-fsevent' + s.add_development_dependency 'database_cleaner' s.files = %w( app diff --git a/script/cucumber b/script/cucumber new file mode 100755 index 0000000..7fa5c92 --- /dev/null +++ b/script/cucumber @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first +if vendored_cucumber_bin + load File.expand_path(vendored_cucumber_bin) +else + require 'rubygems' unless ENV['NO_RUBYGEMS'] + require 'cucumber' + load Cucumber::BINARY +end diff --git a/script/rails b/script/rails new file mode 100755 index 0000000..4309856 --- /dev/null +++ b/script/rails @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +ENGINE_PATH = File.expand_path('../..', __FILE__) +load File.expand_path('../../spec/dummy/script/rails', __FILE__) diff --git a/spec/dummy/.gitignore b/spec/dummy/.gitignore new file mode 100644 index 0000000..55ff259 --- /dev/null +++ b/spec/dummy/.gitignore @@ -0,0 +1,77 @@ +# Rails +.bundle +db/*.sqlite3 +db/*.sqlite3-journal +*.log +tmp +tmp/**/* + +# Documentation +doc/api +doc/app +.yardoc +.yardopts +coverage + +# Public Uploads +public/system/* +public/themes/* + +# Public Cache +public/javascripts/cache +public/stylesheets/cache + +# Vendor Cache +vendor/cache + +# Acts as Indexed +index/**/* + +# Refinery Specific +*.tmproj +*.autobackupbyrefinery.* +refinerycms-*.gem +.autotest + +# Mac +.DS_Store + +# Windows +Thumbs.db + +# NetBeans +nbproject + +# Eclipse +.project + +# Redcar +.redcar + +# Rubinius +*.rbc + +# Vim +*.swp +*.swo + +# RubyMine +.idea + +# E-texteditor +.eprj + +# Backup +*~ + +# Capybara Bug +capybara-*html + +# sass +.sass-cache +.sass-cache/* + +#rvm +.rvmrc +.rvmrc.* + diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile new file mode 100644 index 0000000..3645852 --- /dev/null +++ b/spec/dummy/Rakefile @@ -0,0 +1,7 @@ +#!/usr/bin/env rake +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Dummy::Application.load_tasks diff --git a/spec/dummy/app/assets/javascripts/admin.js b/spec/dummy/app/assets/javascripts/admin.js new file mode 100644 index 0000000..23c4fb9 --- /dev/null +++ b/spec/dummy/app/assets/javascripts/admin.js @@ -0,0 +1,7 @@ +// Use this to customize the wymeditor boot process +// Just mirror the options specified in boot_wym.js with the new options here. +// This will completely override anything specified in boot_wym.js for that key. +// e.g. skin: 'something_else' +var custom_wymeditor_boot_options = { + +}; \ No newline at end of file diff --git a/spec/dummy/app/assets/javascripts/application.js b/spec/dummy/app/assets/javascripts/application.js new file mode 100644 index 0000000..37c7bfc --- /dev/null +++ b/spec/dummy/app/assets/javascripts/application.js @@ -0,0 +1,9 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +//= require jquery +//= require jquery_ujs +//= require_tree . diff --git a/spec/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/application.css @@ -0,0 +1 @@ + diff --git a/spec/dummy/app/assets/stylesheets/application.css.backup b/spec/dummy/app/assets/stylesheets/application.css.backup new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/application.css.backup @@ -0,0 +1 @@ + diff --git a/spec/dummy/app/assets/stylesheets/formatting.css b/spec/dummy/app/assets/stylesheets/formatting.css new file mode 100644 index 0000000..1132188 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/formatting.css @@ -0,0 +1,4 @@ +/* + Override default refinery formatting below. + Formatting applies to backend WYSIWYG editors and all frontend. +*/ \ No newline at end of file diff --git a/spec/dummy/app/assets/stylesheets/home.css b/spec/dummy/app/assets/stylesheets/home.css new file mode 100644 index 0000000..824db99 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/home.css @@ -0,0 +1,4 @@ +/* + Override default refinery homepage styles here. + These only apply to the homepage of your site. +*/ \ No newline at end of file diff --git a/spec/dummy/app/assets/stylesheets/theme.css b/spec/dummy/app/assets/stylesheets/theme.css new file mode 100644 index 0000000..8205050 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/theme.css @@ -0,0 +1,4 @@ +/* + Override default refinery 'theme' styles here. + These only apply when using custom WYMeditor CSS. +*/ \ No newline at end of file diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..e8065d9 --- /dev/null +++ b/spec/dummy/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery +end diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/spec/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/spec/dummy/app/mailers/.gitkeep b/spec/dummy/app/mailers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/models/.gitkeep b/spec/dummy/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/views/layouts/application.html.erb.backup b/spec/dummy/app/views/layouts/application.html.erb.backup new file mode 100644 index 0000000..9a8a761 --- /dev/null +++ b/spec/dummy/app/views/layouts/application.html.erb.backup @@ -0,0 +1,14 @@ + + + + Dummy + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/spec/dummy/app/views/sitemap/index.xml.builder b/spec/dummy/app/views/sitemap/index.xml.builder new file mode 100644 index 0000000..8e89852 --- /dev/null +++ b/spec/dummy/app/views/sitemap/index.xml.builder @@ -0,0 +1,25 @@ +xml.instruct! + +xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do + + @locales.each do |locale| + ::I18n.locale = locale + ::Refinery::Page.live.in_menu.includes(:parts).each do |page| + # exclude sites that are external to our own domain. + page_url = if page.url.is_a?(Hash) + # This is how most pages work without being overriden by link_url + page.url.merge({:only_path => false}) + elsif page.url.to_s !~ /^http/ + # handle relative link_url addresses. + [request.protocol, request.host_with_port, page.url].join + end + + # Add XML entry only if there is a valid page_url found above. + xml.url do + xml.loc url_for(page_url) + xml.lastmod page.updated_at.to_date + end if page_url.present? and page.show_in_menu? + end + end + +end diff --git a/spec/dummy/autotest/autotest.rb b/spec/dummy/autotest/autotest.rb new file mode 100644 index 0000000..09f5b8a --- /dev/null +++ b/spec/dummy/autotest/autotest.rb @@ -0,0 +1,17 @@ +### uncomment any of the following requires applicable for your system +### and then copy this to .autotest if you are using the ZenTest autotest. +# require "autotest/restart" +# require "test_notifier/runner/autotest" +# require "redgreen/autotest" +# require "autotest/timestamp" + +# adds exceptions from .gitignore file, please modify exceptions there! +imported_exceptions = IO.readlines('.gitignore').inject([]) do |acc, line| + acc << line.strip if line.to_s[0] != '#' && line.strip != ''; acc +end + +Autotest.add_hook :initialize do |autotest| + imported_exceptions.each do |exception| + autotest.add_exception(exception) + end +end diff --git a/spec/dummy/autotest/discover.rb b/spec/dummy/autotest/discover.rb new file mode 100644 index 0000000..f421dc5 --- /dev/null +++ b/spec/dummy/autotest/discover.rb @@ -0,0 +1,2 @@ +Autotest.add_discovery { "rails" } +Autotest.add_discovery { "rspec2" } diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru new file mode 100644 index 0000000..1989ed8 --- /dev/null +++ b/spec/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Dummy::Application diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb new file mode 100644 index 0000000..f83ab50 --- /dev/null +++ b/spec/dummy/config/application.rb @@ -0,0 +1,42 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require +require "refinerycms-blog" + +module Dummy + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Custom directories with classes and modules you want to be autoloadable. + # config.autoload_paths += %W(#{config.root}/extras) + + # Only load the plugins named here, in the order given (default is alphabetical). + # :all can be used as a placeholder for all plugins not explicitly named. + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Activate observers that should always be running. + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # Configure the default encoding used in templates for Ruby 1.9. + config.encoding = "utf-8" + + # Configure sensitive parameters which will be filtered from the log file. + config.filter_parameters += [:password] + + # Enable the asset pipeline + config.assets.enabled = true + end +end + diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb new file mode 100644 index 0000000..eba0681 --- /dev/null +++ b/spec/dummy/config/boot.rb @@ -0,0 +1,10 @@ +require 'rubygems' +gemfile = File.expand_path('../../../../Gemfile', __FILE__) + +if File.exist?(gemfile) + ENV['BUNDLE_GEMFILE'] = gemfile + require 'bundler' + Bundler.setup +end + +$:.unshift File.expand_path('../../../../lib', __FILE__) \ No newline at end of file diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml new file mode 100644 index 0000000..51a4dd4 --- /dev/null +++ b/spec/dummy/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/spec/dummy/config/database.yml.mysql b/spec/dummy/config/database.yml.mysql new file mode 100644 index 0000000..75cca95 --- /dev/null +++ b/spec/dummy/config/database.yml.mysql @@ -0,0 +1,20 @@ +development: &development + adapter: mysql2 + host: localhost + username: root + password: + database: your_local_database + +test: &test + adapter: mysql2 + host: localhost + username: root + password: + database: your_test_database + +production: &production + adapter: mysql2 + host: localhost + database: your_production_database + username: your_production_database_login + password: your_production_database_password diff --git a/spec/dummy/config/database.yml.postgresql b/spec/dummy/config/database.yml.postgresql new file mode 100644 index 0000000..2146d1f --- /dev/null +++ b/spec/dummy/config/database.yml.postgresql @@ -0,0 +1,55 @@ +# PostgreSQL. Versions 7.4 and 8.x are supported. +# +# Install the pg driver: +# gem install pg +# On Mac OS X with macports: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +development: + adapter: postgresql + encoding: unicode + database: refinery_database_development + pool: 5 + username: postgres + password: postgres + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # The server defaults to notice. + #min_messages: warning + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: postgresql + encoding: unicode + database: refinery_database_test + pool: 5 + username: postgres + password: postgres + +production: + adapter: postgresql + encoding: unicode + database: refinery_database_production + pool: 5 + username: postgres + password: postgres diff --git a/spec/dummy/config/database.yml.sqlite3 b/spec/dummy/config/database.yml.sqlite3 new file mode 100644 index 0000000..c2da158 --- /dev/null +++ b/spec/dummy/config/database.yml.sqlite3 @@ -0,0 +1,26 @@ +# SQLite version 3.x +development: + adapter: <%= "jdbc" if defined?(JRUBY_PLATFORM) %>sqlite3 + database: db/development.sqlite3 + timeout: 5000 + +# Warning: The database defined as 'test' will be erased and +# re-generated from your development database when you run 'rake'. +# Do not set this db to the same as development or production. +test: + adapter: <%= "jdbc" if defined?(JRUBY_PLATFORM) %>sqlite3 + database: db/test.sqlite3 + timeout: 5000 + +# Warning: The database defined as 'cucumber' will be erased and +# re-generated from your development database when you run 'rake'. +# Do not set this db to the same as development or production. +cucumber: + adapter: <%= "jdbc" if defined?(JRUBY_PLATFORM) %>sqlite3 + database: db/cucumber.sqlite3 + timeout: 5000 + +production: + adapter: <%= "jdbc" if defined?(JRUBY_PLATFORM) %>sqlite3 + database: db/production.sqlite3 + timeout: 5000 \ No newline at end of file diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb new file mode 100644 index 0000000..3da5eb9 --- /dev/null +++ b/spec/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the rails application +require File.expand_path('../application', __FILE__) + +# Initialize the rails application +Dummy::Application.initialize! diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb new file mode 100644 index 0000000..8604338 --- /dev/null +++ b/spec/dummy/config/environments/development.rb @@ -0,0 +1,31 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin + + # Do not compress assets + config.assets.compress = false +end +Refinery.rescue_not_found = false +# When true will use Amazon's Simple Storage Service on your production machine +# instead of the default file system for resources and images +Refinery.s3_backend = !(ENV['S3_KEY'].nil? || ENV['S3_SECRET'].nil?) diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb new file mode 100644 index 0000000..17a630b --- /dev/null +++ b/spec/dummy/config/environments/production.rb @@ -0,0 +1,55 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.serve_static_assets = true # Refinery CMS requires this to be true + + # Compress JavaScripts and CSS + config.assets.compress = true + + # Specifies the header that your server uses for sending files + # (comment out if your front-end server doesn't support this) + config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # See everything in the log (default is :info) + # config.log_level = :debug + + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new + + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # config.assets.precompile += %w( search.js ) + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify +end +Refinery.rescue_not_found = true +# When true will use Amazon's Simple Storage Service on your production machine +# instead of the default file system for resources and images +Refinery.s3_backend = !(ENV['S3_KEY'].nil? || ENV['S3_SECRET'].nil?) diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb new file mode 100644 index 0000000..9e84bae --- /dev/null +++ b/spec/dummy/config/environments/test.rb @@ -0,0 +1,43 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = false + + # Configure static asset server for tests with Cache-Control for performance + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Log error messages when you accidentally call methods on nil + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # Print deprecation notices to the stderr + config.active_support.deprecation = :stderr +end +Refinery.rescue_not_found = false +# When true will use Amazon's Simple Storage Service on your production machine +# instead of the default file system for resources and images +Refinery.s3_backend = !(ENV['S3_KEY'].nil? || ENV['S3_SECRET'].nil?) diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/spec/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/dummy/config/initializers/devise.rb b/spec/dummy/config/initializers/devise.rb new file mode 100644 index 0000000..0d00106 --- /dev/null +++ b/spec/dummy/config/initializers/devise.rb @@ -0,0 +1,144 @@ +require 'devise' + +# Use this hook to configure devise mailer, warden hooks and so forth. The first +# four configuration values can also be set straight in your models. +::Devise.setup do |config| + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in DeviseMailer. + # config.mailer_sender = "please-change-me@config-initializers-devise.com" + + # Configure the class responsible to send e-mails. + # config.mailer = "::Devise::Mailer" + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating an user. By default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating an user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + config.authentication_keys = [ :login ] + + # Tell if authentication through request.params is enabled. True by default. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Basic Auth is enabled. False by default. + # config.http_authenticatable = false + + # Set this to true to use Basic Auth for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication + # config.http_authentication_realm = "Application" + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 10. If + # using other encryptors, it sets how many times you want the password re-encrypted. + # config.stretches = 20 + + # Define which will be the encryption algorithm. Devise also supports encryptors + # from others authentication tools as :clearance_sha1, :authlogic_sha512 (then + # you should set stretches above to 20 for default behavior) and :restful_authentication_sha1 + # (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper) + # config.encryptor = :bcrypt + + # Setup a pepper to generate the encrypted password. + # config.pepper = "2e20a8abdd34d729ba6d05f679e513cfea9fbb1e83c81f84b29e9e4fdbd4ee59b56a32200064082a15a72b05a4d4a6a2c3784a09c0554b3a47a67cc8333ccbc7" + + # ==> Configuration for :confirmable + # The time you want to give your user to confirm his account. During this time + # he will be able to access your application without confirming. Default is nil. + # When confirm_within is zero, the user won't be able to sign in without confirming. + # You can use this to let your user access some features of your application + # without confirming the account, but blocking it after a certain period + # (ie 2 days). + # config.confirm_within = 2.days + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # If true, a valid remember token can be re-used between multiple browsers. + # config.remember_across_browsers = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # ==> Configuration for :validatable + # Range for password length + config.password_length = 4..20 + + # Regex to use to validate the email address + # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. + # config.timeout_in = 10.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # ==> Configuration for :token_authenticatable + # Defines name of the authentication token params key + # config.token_authentication_key = :auth_token + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = true + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes. + # config.default_scope = :user + + # Configure sign_out behavior. + # By default sign_out is scoped (i.e. /users/sign_out affects only :user scope). + # In case of sign_out_all_scopes set to true any logout action will sign out all active scopes. + # config.sign_out_all_scopes = false + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. Default is [:html] + # config.navigational_formats = [:html, :iphone] + + # ==> Warden configuration + # If you want to use other strategies, that are not (yet) supported by Devise, + # you can configure them inside the config.warden block. The example below + # allows you to setup OAuth, using http://github.com/roman/warden_oauth + # + # config.warden do |manager| + # manager.oauth(:twitter) do |twitter| + # twitter.consumer_secret = + # twitter.consumer_key = + # twitter.options :site => 'http://twitter.com' + # end + # manager.default_strategies(:scope => :user).unshift :twitter_oauth + # end +end diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..9e8b013 --- /dev/null +++ b/spec/dummy/config/initializers/inflections.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format +# (all these examples are active by default): +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/spec/dummy/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/spec/dummy/config/initializers/secret_token.rb b/spec/dummy/config/initializers/secret_token.rb new file mode 100644 index 0000000..7a99397 --- /dev/null +++ b/spec/dummy/config/initializers/secret_token.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +Dummy::Application.config.secret_token = '75470fb2f9c361e0509af41d5835fdb3fee2e588a44c68596c6201976f994e0689c434b6e8360dbc45c0d424c1811a5cf1e3f4f0550be9b784fed60fb4e5d29d' diff --git a/spec/dummy/config/initializers/session_store.rb b/spec/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000..952473f --- /dev/null +++ b/spec/dummy/config/initializers/session_store.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' + +# Use the database for sessions instead of the cookie-based default, +# which shouldn't be used to store highly confidential information +# (create the session table with "rails generate session_migration") +# Dummy::Application.config.session_store :active_record_store diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..16c3243 --- /dev/null +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActionController::Base.wrap_parameters format: [:json] + +# Disable root element in JSON by default. +if defined?(ActiveRecord) + ActiveRecord::Base.include_root_in_json = false +end diff --git a/spec/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml new file mode 100644 index 0000000..179c14c --- /dev/null +++ b/spec/dummy/config/locales/en.yml @@ -0,0 +1,5 @@ +# Sample localization file for English. Add more files in this directory for other locales. +# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. + +en: + hello: "Hello world" diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb new file mode 100644 index 0000000..bb509f2 --- /dev/null +++ b/spec/dummy/config/routes.rb @@ -0,0 +1,58 @@ +Dummy::Application.routes.draw do + # The priority is based upon order of creation: + # first created -> highest priority. + + # Sample of regular route: + # match 'products/:id' => 'catalog#view' + # Keep in mind you can assign values other than :controller and :action + + # Sample of named route: + # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase + # This route can be invoked with purchase_url(:id => product.id) + + # Sample resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Sample resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Sample resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Sample resource route with more complex sub-resources + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', :on => :collection + # end + # end + + # Sample resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end + + # You can have the root of your site routed with "root" + # just remember to delete public/index.html. + # root :to => 'welcome#index' + + # See how all your routes lay out with "rake routes" + + # This is a legacy wild controller route that's not recommended for RESTful applications. + # Note: This route will make all actions in every controller accessible via GET requests. + # match ':controller(/:action(/:id(.:format)))' +end diff --git a/spec/dummy/db/migrate/20110802081556_create_refinerycms_core_schema.rb b/spec/dummy/db/migrate/20110802081556_create_refinerycms_core_schema.rb new file mode 100644 index 0000000..3199a9c --- /dev/null +++ b/spec/dummy/db/migrate/20110802081556_create_refinerycms_core_schema.rb @@ -0,0 +1,23 @@ +class CreateRefinerycmsCoreSchema < ActiveRecord::Migration + def self.up + create_table ::Slug.table_name, :force => true do |t| + t.string "name" + t.integer "sluggable_id" + t.integer "sequence", :default => 1, :null => false + t.string "sluggable_type", :limit => 40 + t.string "scope", :limit => 40 + t.datetime "created_at" + end + + add_index ::Slug.table_name, ["name", "sluggable_type", "scope", "sequence"], :name => "index_#{::Slug.table_name}_on_n_s_s_and_s", :unique => true + add_index ::Slug.table_name, ["sluggable_id"], :name => "index_#{::Slug.table_name}_on_sluggable_id" + end + + def self.down + [::Slug].reject{|m| + !(defined?(m) and m.respond_to?(:table_name)) + }.each do |model| + drop_table model.table_name + end + end +end diff --git a/spec/dummy/db/migrate/20110802081557_add_locale_to_slugs.rb b/spec/dummy/db/migrate/20110802081557_add_locale_to_slugs.rb new file mode 100644 index 0000000..0795cad --- /dev/null +++ b/spec/dummy/db/migrate/20110802081557_add_locale_to_slugs.rb @@ -0,0 +1,13 @@ +class AddLocaleToSlugs < ActiveRecord::Migration + def self.up + add_column ::Slug.table_name, :locale, :string + + add_index ::Slug.table_name, :locale + end + + def self.down + remove_column ::Slug.table_name, :locale + + remove_index ::Slug.table_name, :locale + end +end diff --git a/spec/dummy/db/migrate/20110802081558_create_refinerycms_settings_schema.rb b/spec/dummy/db/migrate/20110802081558_create_refinerycms_settings_schema.rb new file mode 100644 index 0000000..b60cf82 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081558_create_refinerycms_settings_schema.rb @@ -0,0 +1,24 @@ +class CreateRefinerycmsSettingsSchema < ActiveRecord::Migration + def self.up + create_table ::Refinery::Setting.table_name, :force => true do |t| + t.string "name" + t.text "value" + t.boolean "destroyable", :default => true + t.datetime "created_at" + t.datetime "updated_at" + t.string "scoping" + t.boolean "restricted", :default => false + t.string "callback_proc_as_string" + end + + add_index ::Refinery::Setting.table_name, ["name"], :name => "index_#{::Refinery::Setting.table_name}_on_name" + end + + def self.down + [::Refinery::Setting].reject{|m| + !(defined?(m) and m.respond_to?(:table_name)) + }.each do |model| + drop_table model.table_name + end + end +end diff --git a/spec/dummy/db/migrate/20110802081559_add_value_type_to_refinery_settings.rb b/spec/dummy/db/migrate/20110802081559_add_value_type_to_refinery_settings.rb new file mode 100644 index 0000000..2fdf6d8 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081559_add_value_type_to_refinery_settings.rb @@ -0,0 +1,9 @@ +class AddValueTypeToRefinerySettings < ActiveRecord::Migration + def self.up + add_column ::Refinery::Setting.table_name, :form_value_type, :string + end + + def self.down + remove_column ::Refinery::Setting.table_name, :form_value_type + end +end diff --git a/spec/dummy/db/migrate/20110802081560_create_refinerycms_authentication_schema.rb b/spec/dummy/db/migrate/20110802081560_create_refinerycms_authentication_schema.rb new file mode 100644 index 0000000..f9b6c2e --- /dev/null +++ b/spec/dummy/db/migrate/20110802081560_create_refinerycms_authentication_schema.rb @@ -0,0 +1,48 @@ +class CreateRefinerycmsAuthenticationSchema < ActiveRecord::Migration + def self.up + # Postgres apparently requires the roles_users table to exist before creating the roles table. + create_table ::Refinery::RolesUsers.table_name, :id => false, :force => true do |t| + t.integer "user_id" + t.integer "role_id" + end unless ::Refinery::RolesUsers.table_exists? + + create_table ::Refinery::Role.table_name, :force => true do |t| + t.string "title" + end unless ::Refinery::Role.table_exists? + + unless ::Refinery::UserPlugin.table_exists? + create_table ::Refinery::UserPlugin.table_name, :force => true do |t| + t.integer "user_id" + t.string "name" + t.integer "position" + end + + add_index ::Refinery::UserPlugin.table_name, ["name"], :name => "index_#{::Refinery::UserPlugin.table_name}_on_title" + add_index ::Refinery::UserPlugin.table_name, ["user_id", "name"], :name => "index_unique_#{::Refinery::UserPlugin.table_name}", :unique => true + + end + + unless ::Refinery::User.table_exists? + create_table ::Refinery::User.table_name, :force => true do |t| + t.string "login", :null => false + t.string "email", :null => false + t.string "crypted_password", :null => false + t.string "password_salt", :null => false + t.string "persistence_token" + t.datetime "created_at" + t.datetime "updated_at" + t.string "perishable_token" + end + + add_index ::Refinery::User.table_name, ["id"], :name => "index_#{::Refinery::User.table_name}_on_id" + end + end + + def self.down + [::User].reject{|m| + !(defined?(m) and m.respond_to?(:table_name)) + }.each do |model| + drop_table model.table_name if model.table_exists? if model.table_exists? + end + end +end diff --git a/spec/dummy/db/migrate/20110802081561_add_missing_indexes_to_roles_users.rb b/spec/dummy/db/migrate/20110802081561_add_missing_indexes_to_roles_users.rb new file mode 100644 index 0000000..e72d81f --- /dev/null +++ b/spec/dummy/db/migrate/20110802081561_add_missing_indexes_to_roles_users.rb @@ -0,0 +1,11 @@ +class AddMissingIndexesToRolesUsers < ActiveRecord::Migration + def self.up + add_index ::Refinery::RolesUsers.table_name, [:role_id, :user_id] + add_index ::Refinery::RolesUsers.table_name, [:user_id, :role_id] + end + + def self.down + remove_index ::Refinery::RolesUsers.table_name, :column => [:role_id, :user_id] + remove_index ::Refinery::RolesUsers.table_name, :column => [:user_id, :role_id] + end +end diff --git a/spec/dummy/db/migrate/20110802081562_change_to_devise_users_table.rb b/spec/dummy/db/migrate/20110802081562_change_to_devise_users_table.rb new file mode 100644 index 0000000..8beef83 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081562_change_to_devise_users_table.rb @@ -0,0 +1,31 @@ +class ChangeToDeviseUsersTable < ActiveRecord::Migration + def self.up + add_column ::Refinery::User.table_name, :current_sign_in_at, :datetime + add_column ::Refinery::User.table_name, :last_sign_in_at, :datetime + add_column ::Refinery::User.table_name, :current_sign_in_ip, :string + add_column ::Refinery::User.table_name, :last_sign_in_ip, :string + add_column ::Refinery::User.table_name, :sign_in_count, :integer + add_column ::Refinery::User.table_name, :remember_token, :string + add_column ::Refinery::User.table_name, :reset_password_token, :string + + rename_column ::Refinery::User.table_name, :crypted_password, :encrypted_password + rename_column ::Refinery::User.table_name, :login, :username + + ::Refinery::User.reset_column_information + end + + def self.down + remove_column ::Refinery::User.table_name, :current_sign_in_at + remove_column ::Refinery::User.table_name, :last_sign_in_at + remove_column ::Refinery::User.table_name, :current_sign_in_ip + remove_column ::Refinery::User.table_name, :last_sign_in_ip + remove_column ::Refinery::User.table_name, :sign_in_count + remove_column ::Refinery::User.table_name, :remember_token + remove_column ::Refinery::User.table_name, :reset_password_token + + rename_column ::Refinery::User.table_name, :encrypted_password, :crypted_password + rename_column ::Refinery::User.table_name, :username, :login + + ::Refinery::User.reset_column_information + end +end diff --git a/spec/dummy/db/migrate/20110802081563_add_remember_created_at_to_users.rb b/spec/dummy/db/migrate/20110802081563_add_remember_created_at_to_users.rb new file mode 100644 index 0000000..524b36f --- /dev/null +++ b/spec/dummy/db/migrate/20110802081563_add_remember_created_at_to_users.rb @@ -0,0 +1,5 @@ +class AddRememberCreatedAtToUsers < ActiveRecord::Migration + def change + add_column ::Refinery::User.table_name, :remember_created_at, :datetime + end +end diff --git a/spec/dummy/db/migrate/20110802081564_remove_password_salt_from_users.rb b/spec/dummy/db/migrate/20110802081564_remove_password_salt_from_users.rb new file mode 100644 index 0000000..afcbfd7 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081564_remove_password_salt_from_users.rb @@ -0,0 +1,13 @@ +class RemovePasswordSaltFromUsers < ActiveRecord::Migration + def self.up + remove_column ::Refinery::User.table_name, :password_salt + # Make the current password invalid :( + ::Refinery::User.all.each do |u| + u.update_attribute(:encrypted_password, u.encrypted_password[29..-1]) + end + end + + def self.down + add_column ::Refinery::User.table_name, :password_salt, :string + end +end diff --git a/spec/dummy/db/migrate/20110802081565_create_refinerycms_images_schema.rb b/spec/dummy/db/migrate/20110802081565_create_refinerycms_images_schema.rb new file mode 100644 index 0000000..6c4e079 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081565_create_refinerycms_images_schema.rb @@ -0,0 +1,23 @@ +class CreateRefinerycmsImagesSchema < ActiveRecord::Migration + def self.up + create_table ::Refinery::Image.table_name, :force => true do |t| + t.string "image_mime_type" + t.string "image_name" + t.integer "image_size" + t.integer "image_width" + t.integer "image_height" + t.datetime "created_at" + t.datetime "updated_at" + t.string "image_uid" + t.string "image_ext" + end unless ::Refinery::Image.table_exists? + end + + def self.down + [::Image].reject{|m| + !(defined?(m) and m.respond_to?(:table_name)) + }.each do |model| + drop_table model.table_name if model.table_exists? + end + end +end diff --git a/spec/dummy/db/migrate/20110802081566_create_refinerycms_pages_schema.rb b/spec/dummy/db/migrate/20110802081566_create_refinerycms_pages_schema.rb new file mode 100644 index 0000000..4458726 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081566_create_refinerycms_pages_schema.rb @@ -0,0 +1,56 @@ +class CreateRefinerycmsPagesSchema < ActiveRecord::Migration + def self.up + unless ::Refinery::PagePart.table_exists? + create_table ::Refinery::PagePart.table_name, :force => true do |t| + t.integer "refinery_page_id" + t.string "title" + t.text "body" + t.integer "position" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index ::Refinery::PagePart.table_name, ["id"], :name => "index_#{::Refinery::PagePart.table_name}_on_id" + add_index ::Refinery::PagePart.table_name, ["refinery_page_id"], :name => "index_#{::Refinery::PagePart.table_name}_on_page_id" + end + + unless ::Refinery::Page.table_exists? + create_table ::Refinery::Page.table_name, :force => true do |t| + t.string "title" + t.integer "parent_id" + t.integer "position" + t.string "path" + t.datetime "created_at" + t.datetime "updated_at" + t.string "meta_keywords" + t.text "meta_description" + t.boolean "show_in_menu", :default => true + t.string "link_url" + t.string "menu_match" + t.boolean "deletable", :default => true + t.string "custom_title" + t.string "custom_title_type", :default => "none" + t.boolean "draft", :default => false + t.string "browser_title" + t.boolean "skip_to_first_child", :default => false + t.integer "lft" + t.integer "rgt" + t.integer "depth" + end + + add_index ::Refinery::Page.table_name, ["depth"], :name => "index_#{::Refinery::Page.table_name}_on_depth" + add_index ::Refinery::Page.table_name, ["id"], :name => "index_#{::Refinery::Page.table_name}_on_id" + add_index ::Refinery::Page.table_name, ["lft"], :name => "index_#{::Refinery::Page.table_name}_on_lft" + add_index ::Refinery::Page.table_name, ["parent_id"], :name => "index_#{::Refinery::Page.table_name}_on_parent_id" + add_index ::Refinery::Page.table_name, ["rgt"], :name => "index_#{::Refinery::Page.table_name}_on_rgt" + end + end + + def self.down + [::Page, ::Refinery::PagePart].reject{|m| + !(defined?(m) and m.respond_to?(:table_name)) + }.each do |model| + drop_table model.table_name if model.table_exists? + end + end +end diff --git a/spec/dummy/db/migrate/20110802081567_translate_page_plugin.rb b/spec/dummy/db/migrate/20110802081567_translate_page_plugin.rb new file mode 100644 index 0000000..bdb0a43 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081567_translate_page_plugin.rb @@ -0,0 +1,38 @@ +class TranslatePagePlugin < ActiveRecord::Migration + def self.up + say_with_time("Creating ::Refinery::PagePart translation table") do + ::Refinery::PagePart.create_translation_table!({ + :body => :text + }, { + :migrate_data => true + }) + end + + say_with_time("Creating ::Refinery::Page translation table") do + ::Refinery::Page.create_translation_table!({ + :title => :string, + :meta_keywords => :string, + :meta_description => :text, + :browser_title => :string + }, { + :migrate_data => true + }) + end + + puts "seeds pages" + if (seed_file = Rails.root.join('db', 'seeds', 'pages.rb')).file? + load seed_file.to_s unless ::Refinery::Page.where(:link_url => '/').any? + end + + say_with_time("Updating slugs") do + ::Slug.update_all(:locale => I18n.locale) + end + end + + def self.down + say_with_time("Dropping ::Refinery::Page and ::Refinery::PagePart translation tables") do + ::Refinery::Page.drop_translation_table! :migrate_data => true + ::Refinery::PagePart.drop_translation_table! :migrate_data => true + end + end +end diff --git a/spec/dummy/db/migrate/20110802081568_remove_cached_slug_from_pages.rb b/spec/dummy/db/migrate/20110802081568_remove_cached_slug_from_pages.rb new file mode 100644 index 0000000..d265838 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081568_remove_cached_slug_from_pages.rb @@ -0,0 +1,11 @@ +class RemoveCachedSlugFromPages < ActiveRecord::Migration + def self.up + if ::Refinery::Page.column_names.map(&:to_s).include?('cached_slug') + remove_column ::Refinery::Page.table_name, :cached_slug + end + end + + def self.down + # Don't add this column back, it breaks stuff. + end +end diff --git a/spec/dummy/db/migrate/20110802081569_translate_custom_title_on_pages.rb b/spec/dummy/db/migrate/20110802081569_translate_custom_title_on_pages.rb new file mode 100644 index 0000000..ab21e11 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081569_translate_custom_title_on_pages.rb @@ -0,0 +1,26 @@ +class TranslateCustomTitleOnPages < ActiveRecord::Migration + def self.up + unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(:custom_title) + add_column ::Refinery::Page.translation_class.table_name, :custom_title, :string + + # Re-save custom_title + ::Refinery::Page.all.each do |page| + page.update_attribute(:custom_title, page.untranslated_attributes['custom_title']) + end + + end + end + + def self.down + # Re-save custom_title + ::Refinery::Page.all.each do |page| + ::Refinery::Page.update_all({ + :custom_title => page.attributes['custom_title'] + }, { + :id => page.id.to_s + }) unless page.attributes['custom_title'].nil? + end + + remove_column ::Refinery::Page.translation_class.table_name, :custom_title + end +end diff --git a/spec/dummy/db/migrate/20110802081570_remove_translated_fields_from_pages.rb b/spec/dummy/db/migrate/20110802081570_remove_translated_fields_from_pages.rb new file mode 100644 index 0000000..9dc30b2 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081570_remove_translated_fields_from_pages.rb @@ -0,0 +1,13 @@ +class RemoveTranslatedFieldsFromPages < ActiveRecord::Migration + def self.up + ::Refinery::Page.translated_attribute_names.map(&:to_sym).each do |column_name| + remove_column ::Refinery::Page.table_name, column_name if ::Refinery::Page.column_names.map(&:to_sym).include?(column_name) + end + end + + def self.down + ::Refinery::Page.translated_attribute_names.map(&:to_sym).each do |column_name| + add_column ::Refinery::Page.table_name, column_name, Page::Translation.columns.detect{|c| c.name.to_sym == column_name}.type + end + end +end diff --git a/spec/dummy/db/migrate/20110802081571_create_seo_meta.rb b/spec/dummy/db/migrate/20110802081571_create_seo_meta.rb new file mode 100644 index 0000000..abc2178 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081571_create_seo_meta.rb @@ -0,0 +1,86 @@ +class CreateSeoMeta < ActiveRecord::Migration + + def self.up + create_table :seo_meta do |t| + t.integer :seo_meta_id + t.string :seo_meta_type + + t.string :browser_title + t.string :meta_keywords + t.text :meta_description + + t.timestamps + end + + add_index :seo_meta, :id + add_index :seo_meta, [:seo_meta_id, :seo_meta_type] + + # Grab the attributes of the records that currently exist + existing_translations = ::Refinery::Page.translation_class.all.map(&:attributes) + + # Remove columns + ::SeoMeta.attributes.keys.each do |field| + if ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(field) + remove_column ::Refinery::Page.translation_class.table_name, field + end + end + + # Reset column information because otherwise the old columns will still exist. + ::Refinery::Page.translation_class.reset_column_information + + # Re-attach seo_meta + ::Refinery::Page.translation_class.send :is_seo_meta + + # Migrate data + existing_translations.each do |translation| + ::Refinery::Page.translation_class.find(translation['id']).update_attributes( + ::SeoMeta.attributes.keys.inject({}) {|attributes, name| + attributes.merge(name => translation[name.to_s]) + } + ) + end + + # Reset column information again because otherwise the old columns will still exist. + ::Refinery::Page.reset_column_information + end + + def self.down + # Grab the attributes of the records that currently exist + existing_translations = ::Refinery::Page.translation_class.all.map(&:attributes) + + # Add columns back to your model + ::SeoMeta.attributes.each do |field, field_type| + unless ::Refinery::Page.translation_class.column_names.map(&:to_sym).include?(field) + add_column ::Refinery::Page.translation_class.table_name, field, field_type + end + end + + # Reset column information because otherwise the new columns won't exist yet. + ::Refinery::Page.translation_class.reset_column_information + + # Migrate data + existing_translations.each do |translation| + ::Refinery::Page.translation_class.update_all( + ::SeoMeta.attributes.keys.inject({}) {|attributes, name| + attributes.merge(name => translation[name.to_s]) + }, :id => translation['id'] + ) + end + + ::SeoMeta.attributes.keys.each do |k| + ::Refinery::Page.translation_class.module_eval %{ + def #{k} + end + + def #{k}=(*args) + end + } + end + + # Reset column information again because otherwise the old columns will still exist. + ::Refinery::Page.reset_column_information + + drop_table :seo_meta + end + +end diff --git a/spec/dummy/db/migrate/20110802081572_create_add_template_columns.rb b/spec/dummy/db/migrate/20110802081572_create_add_template_columns.rb new file mode 100644 index 0000000..eb98ed1 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081572_create_add_template_columns.rb @@ -0,0 +1,11 @@ +class CreateAddTemplateColumns < ActiveRecord::Migration + def self.up + add_column ::Refinery::Page.table_name, :view_template, :string + add_column ::Refinery::Page.table_name, :layout_template, :string + end + + def self.down + remove_column ::Refinery::Page.table_name, :layout_template + remove_column ::Refinery::Page.table_name, :view_template + end +end diff --git a/spec/dummy/db/migrate/20110802081573_create_refinerycms_resources_schema.rb b/spec/dummy/db/migrate/20110802081573_create_refinerycms_resources_schema.rb new file mode 100644 index 0000000..360f469 --- /dev/null +++ b/spec/dummy/db/migrate/20110802081573_create_refinerycms_resources_schema.rb @@ -0,0 +1,21 @@ +class CreateRefinerycmsResourcesSchema < ActiveRecord::Migration + def self.up + create_table ::Refinery::Resource.table_name, :force => true do |t| + t.string "file_mime_type" + t.string "file_name" + t.integer "file_size" + t.datetime "created_at" + t.datetime "updated_at" + t.string "file_uid" + t.string "file_ext" + end unless ::Refinery::Resource.table_exists? + end + + def self.down + [::Resource].reject{|m| + !(defined?(m) and m.respond_to?(:table_name)) + }.each do |model| + drop_table model.table_name if model.table_exists? + end + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb new file mode 100644 index 0000000..3068a6b --- /dev/null +++ b/spec/dummy/db/schema.rb @@ -0,0 +1,239 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20110803223529) do + + create_table "refinery_blog_categories", :force => true do |t| + t.string "title" + t.datetime "created_at" + t.datetime "updated_at" + t.string "cached_slug" + end + + add_index "refinery_blog_categories", ["id"], :name => "index_refinery_blog_categories_on_id" + + create_table "refinery_blog_categories_blog_posts", :force => true do |t| + t.integer "blog_category_id" + t.integer "blog_post_id" + end + + add_index "refinery_blog_categories_blog_posts", ["blog_category_id", "blog_post_id"], :name => "index_blog_categories_blog_posts_on_bc_and_bp" + + create_table "refinery_blog_comments", :force => true do |t| + t.integer "blog_post_id" + t.boolean "spam" + t.string "name" + t.string "email" + t.text "body" + t.string "state" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "refinery_blog_comments", ["id"], :name => "index_refinery_blog_comments_on_id" + + create_table "refinery_blog_posts", :force => true do |t| + t.string "title" + t.text "body" + t.boolean "draft" + t.datetime "published_at" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "user_id" + t.string "cached_slug" + t.string "custom_url" + t.text "custom_teaser" + end + + add_index "refinery_blog_posts", ["id"], :name => "index_refinery_blog_posts_on_id" + + create_table "refinery_images", :force => true do |t| + t.string "image_mime_type" + t.string "image_name" + t.integer "image_size" + t.integer "image_width" + t.integer "image_height" + t.datetime "created_at" + t.datetime "updated_at" + t.string "image_uid" + t.string "image_ext" + end + + create_table "refinery_page_part_translations", :force => true do |t| + t.integer "refinery_page_part_id" + t.string "locale" + t.text "body" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "refinery_page_part_translations", ["refinery_page_part_id"], :name => "index_f9716c4215584edbca2557e32706a5ae084a15ef" + + create_table "refinery_page_parts", :force => true do |t| + t.integer "refinery_page_id" + t.string "title" + t.text "body" + t.integer "position" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "refinery_page_parts", ["id"], :name => "index_refinery_page_parts_on_id" + add_index "refinery_page_parts", ["refinery_page_id"], :name => "index_refinery_page_parts_on_page_id" + + create_table "refinery_page_translations", :force => true do |t| + t.integer "refinery_page_id" + t.string "locale" + t.string "title" + t.string "custom_title" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "refinery_page_translations", ["refinery_page_id"], :name => "index_d079468f88bff1c6ea81573a0d019ba8bf5c2902" + + create_table "refinery_pages", :force => true do |t| + t.integer "parent_id" + t.integer "position" + t.string "path" + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "show_in_menu", :default => true + t.string "link_url" + t.string "menu_match" + t.boolean "deletable", :default => true + t.string "custom_title_type", :default => "none" + t.boolean "draft", :default => false + t.boolean "skip_to_first_child", :default => false + t.integer "lft" + t.integer "rgt" + t.integer "depth" + t.string "view_template" + t.string "layout_template" + end + + add_index "refinery_pages", ["depth"], :name => "index_refinery_pages_on_depth" + add_index "refinery_pages", ["id"], :name => "index_refinery_pages_on_id" + add_index "refinery_pages", ["lft"], :name => "index_refinery_pages_on_lft" + add_index "refinery_pages", ["parent_id"], :name => "index_refinery_pages_on_parent_id" + add_index "refinery_pages", ["rgt"], :name => "index_refinery_pages_on_rgt" + + create_table "refinery_resources", :force => true do |t| + t.string "file_mime_type" + t.string "file_name" + t.integer "file_size" + t.datetime "created_at" + t.datetime "updated_at" + t.string "file_uid" + t.string "file_ext" + end + + create_table "refinery_roles", :force => true do |t| + t.string "title" + end + + create_table "refinery_roles_users", :id => false, :force => true do |t| + t.integer "user_id" + t.integer "role_id" + end + + add_index "refinery_roles_users", ["role_id", "user_id"], :name => "index_refinery_roles_users_on_role_id_and_user_id" + add_index "refinery_roles_users", ["user_id", "role_id"], :name => "index_refinery_roles_users_on_user_id_and_role_id" + + create_table "refinery_settings", :force => true do |t| + t.string "name" + t.text "value" + t.boolean "destroyable", :default => true + t.datetime "created_at" + t.datetime "updated_at" + t.string "scoping" + t.boolean "restricted", :default => false + t.string "callback_proc_as_string" + t.string "form_value_type" + end + + add_index "refinery_settings", ["name"], :name => "index_refinery_settings_on_name" + + create_table "refinery_user_plugins", :force => true do |t| + t.integer "user_id" + t.string "name" + t.integer "position" + end + + add_index "refinery_user_plugins", ["name"], :name => "index_refinery_user_plugins_on_title" + add_index "refinery_user_plugins", ["user_id", "name"], :name => "index_unique_refinery_user_plugins", :unique => true + + create_table "refinery_users", :force => true do |t| + t.string "username", :null => false + t.string "email", :null => false + t.string "encrypted_password", :null => false + t.string "persistence_token" + t.datetime "created_at" + t.datetime "updated_at" + t.string "perishable_token" + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.integer "sign_in_count" + t.string "remember_token" + t.string "reset_password_token" + t.datetime "remember_created_at" + end + + add_index "refinery_users", ["id"], :name => "index_refinery_users_on_id" + + create_table "seo_meta", :force => true do |t| + t.integer "seo_meta_id" + t.string "seo_meta_type" + t.string "browser_title" + t.string "meta_keywords" + t.text "meta_description" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "seo_meta", ["id"], :name => "index_seo_meta_on_id" + add_index "seo_meta", ["seo_meta_id", "seo_meta_type"], :name => "index_seo_meta_on_seo_meta_id_and_seo_meta_type" + + create_table "slugs", :force => true do |t| + t.string "name" + t.integer "sluggable_id" + t.integer "sequence", :default => 1, :null => false + t.string "sluggable_type", :limit => 40 + t.string "scope", :limit => 40 + t.datetime "created_at" + t.string "locale" + end + + add_index "slugs", ["locale"], :name => "index_slugs_on_locale" + add_index "slugs", ["name", "sluggable_type", "scope", "sequence"], :name => "index_slugs_on_n_s_s_and_s", :unique => true + add_index "slugs", ["sluggable_id"], :name => "index_slugs_on_sluggable_id" + + create_table "taggings", :force => true do |t| + t.integer "tag_id" + t.integer "taggable_id" + t.string "taggable_type" + t.integer "tagger_id" + t.string "tagger_type" + t.string "context" + t.datetime "created_at" + end + + add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" + add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context" + + create_table "tags", :force => true do |t| + t.string "name" + end + +end diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb new file mode 100644 index 0000000..a158e52 --- /dev/null +++ b/spec/dummy/db/seeds.rb @@ -0,0 +1,5 @@ +# Refinery seeds +Dir[Rails.root.join('db', 'seeds', '*.rb').to_s].each do |file| + puts "Loading db/seeds/#{file.split(File::SEPARATOR).last}" + load(file) +end diff --git a/spec/dummy/db/seeds/pages.rb b/spec/dummy/db/seeds/pages.rb new file mode 100644 index 0000000..668687f --- /dev/null +++ b/spec/dummy/db/seeds/pages.rb @@ -0,0 +1,63 @@ +module Refinery + ::Refinery::Page.reset_column_information + + # Check whether all columns are applied yet by seo_meta. + unless !defined?(::SeoMeta) || ::SeoMeta.attributes.keys.all? { |k| + ::Refinery::Page.translation_class.instance_methods.include?(k) + } + # Make pages model seo_meta because not all columns are accessible. + ::Refinery::Page.translation_class.send :is_seo_meta + end + + page_position = -1 + + unless ::Refinery::Page.where(:menu_match => "^/$").any? + home_page = ::Refinery::Page.create!({:title => "Home", + :deletable => false, + :link_url => "/", + :menu_match => "^/$", + :position => (page_position += 1)}) + home_page.parts.create({ + :title => "Body", + :body => "

Welcome to our site. This is just a place holder page while we gather our content.

", + :position => 0 + }) + home_page.parts.create({ + :title => "Side Body", + :body => "

This is another block of content over here.

", + :position => 1 + }) + + home_page_position = -1 + page_not_found_page = home_page.children.create(:title => "Page not found", + :menu_match => "^/404$", + :show_in_menu => false, + :deletable => false, + :position => (home_page_position += 1)) + page_not_found_page.parts.create({ + :title => "Body", + :body => "

Sorry, there was a problem...

The page you requested was not found.

Return to the home page

", + :position => 0 + }) + else + page_position += 1 + end + + unless ::Refinery::Page.by_title("About").any? + about_us_page = ::Refinery::Page.create(:title => "About", + :deletable => true, + :position => (page_position += 1)) + about_us_page.parts.create({ + :title => "Body", + :body => "

This is just a standard text page example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus dolor, hendrerit sit amet, aliquet nec, posuere sed, purus. Nullam et velit iaculis odio sagittis placerat. Duis metus tellus, pellentesque ut, luctus id, egestas a, lorem. Praesent vitae mauris. Aliquam sed nulla. Sed id nunc vitae leo suscipit viverra. Proin at leo ut lacus consequat rhoncus. In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibus.\n\nInteger interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus. Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.

", + :position => 0 + }) + about_us_page.parts.create({ + :title => "Side Body", + :body => "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus fringilla nisi a elit. Duis ultricies orci ut arcu. Ut ac nibh. Duis blandit rhoncus magna. Pellentesque semper risus ut magna. Etiam pulvinar tellus eget diam. Morbi blandit. Donec pulvinar mauris at ligula. Sed pellentesque, ipsum id congue molestie, lectus risus egestas pede, ac viverra diam lacus ac urna. Aenean elit.

", + :position => 1 + }) + else + page_position += 1 + end +end diff --git a/spec/dummy/lib/assets/.gitkeep b/spec/dummy/lib/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/log/.gitkeep b/spec/dummy/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/public/404.html b/spec/dummy/public/404.html new file mode 100644 index 0000000..9a48320 --- /dev/null +++ b/spec/dummy/public/404.html @@ -0,0 +1,26 @@ + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+ + diff --git a/spec/dummy/public/422.html b/spec/dummy/public/422.html new file mode 100644 index 0000000..83660ab --- /dev/null +++ b/spec/dummy/public/422.html @@ -0,0 +1,26 @@ + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+ + diff --git a/spec/dummy/public/500.html b/spec/dummy/public/500.html new file mode 100644 index 0000000..b80307f --- /dev/null +++ b/spec/dummy/public/500.html @@ -0,0 +1,26 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+
+ + diff --git a/spec/dummy/public/favicon.ico b/spec/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/script/rails b/spec/dummy/script/rails new file mode 100755 index 0000000..f8da2cf --- /dev/null +++ b/spec/dummy/script/rails @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) +require 'rails/commands' diff --git a/spec/factories/blog_categories.rb b/spec/factories/blog_categories.rb new file mode 100644 index 0000000..c3701dd --- /dev/null +++ b/spec/factories/blog_categories.rb @@ -0,0 +1,3 @@ +Factory.define :blog_category, :class => 'refinery/blog_category' do |f| + f.sequence(:title) { |n| "Shopping #{n}" } +end diff --git a/spec/factories/blog_comments.rb b/spec/factories/blog_comments.rb new file mode 100644 index 0000000..d738cac --- /dev/null +++ b/spec/factories/blog_comments.rb @@ -0,0 +1,6 @@ +Factory.define :blog_comment, :class => 'refinery/blog_comment' do |f| + f.name "Joe Commenter" + f.sequence(:email) { |n| "person#{n}@example.com" } + f.body "Which one is the best for picking up new shoes?" + f.association :post, :factory => :blog_post +end diff --git a/spec/factories/blog_posts.rb b/spec/factories/blog_posts.rb new file mode 100644 index 0000000..548636d --- /dev/null +++ b/spec/factories/blog_posts.rb @@ -0,0 +1,7 @@ +Factory.define :blog_post, :class => 'refinery/blog_post' do |f| + f.sequence(:title) { |n| "Top #{n} Shopping Centers in Chicago" } + f.body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it." + f.draft false + f.tag_list "chicago, shopping, fun times" + f.published_at Time.now +end diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 0000000..94fe1d0 --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,27 @@ +require 'refinerycms/all' +require 'refinery/role' + +Factory.define :user, :class => ::Refinery::User do |u| + u.sequence(:username) { |n| "person#{n}" } + u.sequence(:email) { |n| "person#{n}@cucumber.com" } + u.password "greenandjuicy" + u.password_confirmation "greenandjuicy" +end + +Factory.define :refinery_user, :parent => :user do |u| + u.roles { [ ::Refinery::Role[:refinery] ] } + + u.after_create do |user| + ::Refinery::Plugins.registered.each_with_index do |plugin, index| + user.plugins.create(:name => plugin.name, :position => index) + end + end +end + +Factory.define :refinery_translator, :parent => :user do |u| + u.roles { [ ::Refinery::Role[:refinery], ::Refinery::Role[:translator] ] } + + u.after_create do |user| + user.plugins.create(:name => 'refinery_pages', :position => 0) + end +end diff --git a/spec/models/refinery/blog_post_spec.rb b/spec/models/refinery/blog_post_spec.rb index d5000f1..2501a24 100644 --- a/spec/models/refinery/blog_post_spec.rb +++ b/spec/models/refinery/blog_post_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' module Refinery - describe BlogPost do - let(:blog_post ) { Factory.create(:blog_post) } + describe BlogPost do + let(:blog_post) { Factory.create(:blog_post) } describe "validations" do it "requires title" do diff --git a/spec/rcov.opts b/spec/rcov.opts new file mode 100644 index 0000000..274ed51 --- /dev/null +++ b/spec/rcov.opts @@ -0,0 +1,2 @@ +--exclude "spec/*,gems/*" +--rails \ No newline at end of file diff --git a/spec/requests/blog_categories_spec.rb b/spec/requests/blog_categories_spec.rb index 2ba5f82..33d330b 100644 --- a/spec/requests/blog_categories_spec.rb +++ b/spec/requests/blog_categories_spec.rb @@ -1,9 +1,8 @@ require "spec_helper" describe "blog categories" do - login_refinery_user - before(:each) do + Factory.create(:refinery_user) @blog_post = Factory(:blog_post, :title => "Refinery CMS blog post") @blog_category = Factory(:blog_category, :title => "Video Games") @blog_post.categories << @blog_category @@ -17,5 +16,4 @@ describe "blog categories" do page.should have_content("Video Games") end end - end diff --git a/spec/requests/blog_posts_spec.rb b/spec/requests/blog_posts_spec.rb index e7ab573..8695d9a 100644 --- a/spec/requests/blog_posts_spec.rb +++ b/spec/requests/blog_posts_spec.rb @@ -1,22 +1,22 @@ require "spec_helper" -describe "blog" do - login_refinery_user - - it "displays the blog rss feed" do - get blog_rss_feed_path - response.should be_success - response.content_type.should eq("application/rss+xml") +describe "blog posts" do + before(:each) do + Factory.create(:refinery_user) end - - describe "posts" do - let!(:blog_post) { Factory(:blog_post, :title => "Refinery CMS blog post") } - - context "has blog posts" do - it "Displays blog post" do - visit blog_post_path(blog_post) - page.should have_content("Refinery CMS blog post") - end + + context "when has blog posts" do + let(:blog_post) { Factory(:blog_post, :title => "Refinery CMS blog post") } + + it "should display blog post" do + visit blog_post_path(blog_post) + page.should have_content("Refinery CMS blog post") + end + + it "should display the blog rss feed" do + get blog_rss_feed_path + response.should be_success + response.content_type.should eq("application/rss+xml") end end end diff --git a/spec/requests/manage_blog_posts_spec.rb b/spec/requests/manage_blog_posts_spec.rb index 724cc59..8b1097d 100644 --- a/spec/requests/manage_blog_posts_spec.rb +++ b/spec/requests/manage_blog_posts_spec.rb @@ -1,7 +1,14 @@ require "spec_helper" describe "manage blog posts" do - login_refinery_user + # TODO: share this with other request specs + before(:each) do + user = Factory.create(:refinery_user) + visit new_refinery_user_session_url + fill_in "Login", :with => user.username + fill_in "Password", :with => user.password + click_button "Sign in" + end let!(:blog_post) { Factory(:blog_post, :title => "Refinery CMS blog post") } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..441da1d --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,48 @@ +require 'rubygems' +require 'spork' + +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. + + # Configure Rails Environment + ENV["RAILS_ENV"] ||= 'test' + require File.expand_path("../dummy/config/environment.rb", __FILE__) + + require 'rspec/rails' + require 'capybara/rspec' + require 'factory_girl' + require 'devise' + require 'database_cleaner' + + Rails.backtrace_cleaner.remove_silencers! + + Dir[ + File.expand_path("../support/*.rb", __FILE__), + File.expand_path("../factories/*.rb", __FILE__) + ].each {|f| require f} + + RSpec.configure do |config| + config.mock_with :rspec + config.use_transactional_fixtures = false + + config.before(:suite) do + DatabaseCleaner.strategy = :truncation + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + end + + config.include Devise::TestHelpers, :type => :controller + end +end + +Spork.each_run do + # This code will be run each time you run your specs. +end diff --git a/spec/support/refinery/factories/blog_categories.rb b/spec/support/refinery/factories/blog_categories.rb deleted file mode 100644 index c3701dd..0000000 --- a/spec/support/refinery/factories/blog_categories.rb +++ /dev/null @@ -1,3 +0,0 @@ -Factory.define :blog_category, :class => 'refinery/blog_category' do |f| - f.sequence(:title) { |n| "Shopping #{n}" } -end diff --git a/spec/support/refinery/factories/blog_comments.rb b/spec/support/refinery/factories/blog_comments.rb deleted file mode 100644 index d738cac..0000000 --- a/spec/support/refinery/factories/blog_comments.rb +++ /dev/null @@ -1,6 +0,0 @@ -Factory.define :blog_comment, :class => 'refinery/blog_comment' do |f| - f.name "Joe Commenter" - f.sequence(:email) { |n| "person#{n}@example.com" } - f.body "Which one is the best for picking up new shoes?" - f.association :post, :factory => :blog_post -end diff --git a/spec/support/refinery/factories/blog_posts.rb b/spec/support/refinery/factories/blog_posts.rb deleted file mode 100644 index 548636d..0000000 --- a/spec/support/refinery/factories/blog_posts.rb +++ /dev/null @@ -1,7 +0,0 @@ -Factory.define :blog_post, :class => 'refinery/blog_post' do |f| - f.sequence(:title) { |n| "Top #{n} Shopping Centers in Chicago" } - f.body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it." - f.draft false - f.tag_list "chicago, shopping, fun times" - f.published_at Time.now -end -- cgit v1.2.3