Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove Diesel dependency

+ Updated installer to remove Diesel
+ Added new templates for generating features
+ Removed unused step definitions
  • Loading branch information...
commit 337ba1b5e0405f1e55f845615e1b78db74645807 1 parent 0cc57b7
@harlow harlow authored
Showing with 304 additions and 118 deletions.
  1. +1 −4 Gemfile.lock
  2. +0 −1  Rakefile
  3. +0 −1  clearance.gemspec
  4. +7 −0 features/step_definitions/gem_file_steps.rb
  5. +8 −18 features/support/env.rb
  6. +1 −4 gemfiles/3.0.17.gemfile.lock
  7. +1 −4 gemfiles/3.1.8.gemfile.lock
  8. +1 −4 gemfiles/3.2.8.gemfile.lock
  9. +0 −9 features/support/clearance.rb → lib/clearance/testing/app/controllers/application_controller.rb
  10. +46 −0 lib/clearance/testing/application.rb
  11. +11 −0 lib/clearance/testing/config/database.yml
  12. +3 −0  lib/clearance/testing/config/routes.rb
  13. +5 −0 lib/generators/clearance/features/USAGE
  14. +11 −2 lib/generators/clearance/features/features_generator.rb
  15. 0  ...gine → lib/generators/clearance/features/templates/features/clearance}/visitor_resets_password.feature
  16. 0  ...ures/engine → lib/generators/clearance/features/templates/features/clearance}/visitor_signs_in.feature
  17. 0  ...res/engine → lib/generators/clearance/features/templates/features/clearance}/visitor_signs_out.feature
  18. 0  ...ures/engine → lib/generators/clearance/features/templates/features/clearance}/visitor_signs_up.feature
  19. 0  ...ons/engine → lib/generators/clearance/features/templates/features/step_definitions}/clearance_steps.rb
  20. +10 −0 lib/generators/clearance/features/templates/spec/factories/clearance.rb
  21. +103 −22 lib/generators/clearance/install/install_generator.rb
  22. +14 −7 lib/generators/clearance/install/templates/README
  23. +21 −0 lib/generators/clearance/install/templates/db/migrate/add_clearance_to_users.rb
  24. +18 −0 lib/generators/clearance/install/templates/db/migrate/create_users.rb
  25. +0 −37 lib/generators/clearance/install/templates/db/migrate/upgrade_clearance_to_diesel.rb
  26. +15 −0 lib/generators/clearance/views/USAGE
  27. +23 −2 lib/generators/clearance/views/views_generator.rb
  28. +5 −3 spec/spec_helper.rb
View
5 Gemfile.lock
@@ -3,7 +3,6 @@ PATH
specs:
clearance (1.0.0.rc2)
bcrypt-ruby
- diesel (= 0.1.5)
rails (>= 3.0)
GEM
@@ -69,8 +68,6 @@ GEM
cucumber (>= 1.1.0)
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
- diesel (0.1.5)
- railties
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (3.5.0)
@@ -152,7 +149,7 @@ GEM
thor (0.15.4)
tilt (1.3.3)
timecop (0.3.5)
- treetop (1.4.10)
+ treetop (1.4.11)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
View
1  Rakefile
@@ -5,7 +5,6 @@ require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake'
-require 'diesel/tasks'
require 'cucumber/rake/task'
require 'rspec/core/rake_task'
require 'appraisal'
View
1  clearance.gemspec
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
s.add_dependency 'bcrypt-ruby'
- s.add_dependency 'diesel', '0.1.5'
s.add_dependency 'rails', '>= 3.0'
s.add_development_dependency 'appraisal', '0.4.1'
s.add_development_dependency 'aruba', '0.4.11'
View
7 features/step_definitions/gem_file_steps.rb
@@ -0,0 +1,7 @@
+When /^I add the "([^"]*)" gem$/ do |gem_name|
+ append_to_file('Gemfile', %{\ngem "#{gem_name}"\n})
+end
+
+When /^I add the "([^"]*)" gem from this project$/ do |gem_name|
+ append_to_file('Gemfile', %{\ngem "#{gem_name}", :path => "../../.."\n})
+end
View
26 features/support/env.rb
@@ -1,35 +1,25 @@
-# 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.
-
ENV['RAILS_ENV'] ||= 'test'
PROJECT_ROOT = File.expand_path('../../..', __FILE__)
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
require 'rails/all'
+require 'rails/test_help'
Bundler.require
-require 'diesel/testing'
-require 'diesel/testing/integration'
-require 'cucumber/rails/application'
+require 'aruba/cucumber'
+require 'clearance/testing/application'
require 'cucumber/rails/action_controller'
-require 'rails/test_help'
-require 'cucumber/rails/world'
-require 'cucumber/rails/hooks'
+require 'cucumber/rails/application'
require 'cucumber/rails/capybara'
+require 'cucumber/rails/hooks'
+require 'cucumber/rails/world'
-# 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.
+ActionController::Base.allow_rescue = false
Capybara.default_selector = :css
Capybara.save_and_open_page_path = 'tmp'
-
-ActionController::Base.allow_rescue = false
+Clearance::Testing::Application.initialize!
begin
DatabaseCleaner.strategy = :transaction
View
5 gemfiles/3.0.17.gemfile.lock
@@ -1,9 +1,8 @@
PATH
- remote: /Users/croaky/dev/clearance
+ remote: /Users/harlow/Sites/clearance
specs:
clearance (1.0.0.rc2)
bcrypt-ruby
- diesel (= 0.1.5)
rails (>= 3.0)
GEM
@@ -69,8 +68,6 @@ GEM
cucumber (>= 1.1.0)
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
- diesel (0.1.5)
- railties
diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
View
5 gemfiles/3.1.8.gemfile.lock
@@ -1,9 +1,8 @@
PATH
- remote: /Users/croaky/dev/clearance
+ remote: /Users/harlow/Sites/clearance
specs:
clearance (1.0.0.rc2)
bcrypt-ruby
- diesel (= 0.1.5)
rails (>= 3.0)
GEM
@@ -70,8 +69,6 @@ GEM
cucumber (>= 1.1.0)
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
- diesel (0.1.5)
- railties
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (3.5.0)
View
5 gemfiles/3.2.8.gemfile.lock
@@ -1,9 +1,8 @@
PATH
- remote: /Users/croaky/dev/clearance
+ remote: /Users/harlow/Sites/clearance
specs:
clearance (1.0.0.rc2)
bcrypt-ruby
- diesel (= 0.1.5)
rails (>= 3.0)
GEM
@@ -69,8 +68,6 @@ GEM
cucumber (>= 1.1.0)
nokogiri (>= 1.5.0)
database_cleaner (0.8.0)
- diesel (0.1.5)
- railties
diff-lcs (1.1.3)
erubis (2.7.0)
factory_girl (3.5.0)
View
9 features/support/clearance.rb → ...testing/app/controllers/application_controller.rb
@@ -1,8 +1,3 @@
-require 'clearance'
-
-Clearance.configure do |config|
-end
-
class ApplicationController < ActionController::Base
include Clearance::Authentication
@@ -10,7 +5,3 @@ def show
render :text => '', :layout => 'application'
end
end
-
-class User < ActiveRecord::Base
- include Clearance::User
-end
View
46 lib/clearance/testing/application.rb
@@ -0,0 +1,46 @@
+require 'rails/all'
+
+module Clearance
+ module Testing
+ APP_ROOT = File.expand_path('..', __FILE__).freeze
+
+ class Application < Rails::Application
+ config.encoding = "utf-8"
+ config.action_mailer.default_url_options = { :host => 'localhost' }
+
+ if Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR >= 1
+ config.paths['config/database'] = "#{APP_ROOT}/config/database.yml"
+ config.paths['config/routes'] << "#{APP_ROOT}/config/routes.rb"
+ config.paths['app/controllers'] << "#{APP_ROOT}/app/controllers"
+ config.paths['app/views'] << "#{APP_ROOT}/app/views"
+ config.paths['log'] = "tmp/log/development.log"
+ config.assets.enabled = true
+ else
+ config.paths.config.database = "#{APP_ROOT}/config/database.yml"
+ config.paths.config.routes << "#{APP_ROOT}/config/routes.rb"
+ config.paths.app.controllers << "#{APP_ROOT}/app/controllers"
+ config.paths.app.views << "#{APP_ROOT}/app/views"
+ config.paths.log = "tmp/log"
+ end
+
+ config.cache_classes = true
+ config.whiny_nils = true
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+ config.action_dispatch.show_exceptions = false
+ config.action_controller.allow_forgery_protection = false
+ config.action_mailer.delivery_method = :test
+ config.active_support.deprecation = :stderr
+ config.secret_token = "SECRET_TOKEN_IS_MIN_30_CHARS_LONG"
+
+ def require_environment!
+ initialize!
+ end
+
+ def initialize!
+ FileUtils.mkdir_p(Rails.root.join("db").to_s)
+ super unless @initialized
+ end
+ end
+ end
+end
View
11 lib/clearance/testing/config/database.yml
@@ -0,0 +1,11 @@
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
View
3  lib/clearance/testing/config/routes.rb
@@ -0,0 +1,3 @@
+Rails.application.routes.draw do
+ root :to => "application#show"
+end
View
5 lib/generators/clearance/features/USAGE
@@ -0,0 +1,5 @@
+Description:
+ Generate Cucumber features and step definitions
+
+Examples:
+ rails generate clearance:cucumber_features
View
13 lib/generators/clearance/features/features_generator.rb
@@ -1,8 +1,17 @@
-require 'diesel/generators/features_base'
+require 'rails/generators/base'
module Clearance
module Generators
- class FeaturesGenerator < Diesel::Generators::FeaturesBase
+ class FeaturesGenerator < Rails::Generators::Base
+ source_root File.expand_path('../templates', __FILE__)
+
+ def create_features
+ directory 'features'
+ end
+
+ def create_factories
+ directory 'spec'
+ end
end
end
end
View
0  features/engine/visitor_resets_password.feature → ...eatures/clearance/visitor_resets_password.feature
File renamed without changes
View
0  features/engine/visitor_signs_in.feature → ...lates/features/clearance/visitor_signs_in.feature
File renamed without changes
View
0  features/engine/visitor_signs_out.feature → ...ates/features/clearance/visitor_signs_out.feature
File renamed without changes
View
0  features/engine/visitor_signs_up.feature → ...lates/features/clearance/visitor_signs_up.feature
File renamed without changes
View
0  features/step_definitions/engine/clearance_steps.rb → ...ates/features/step_definitions/clearance_steps.rb
File renamed without changes
View
10 lib/generators/clearance/features/templates/spec/factories/clearance.rb
@@ -0,0 +1,10 @@
+FactoryGirl.define do
+ sequence :email do |n|
+ "user#{n}@example.com"
+ end
+
+ factory :user do
+ email
+ password "password"
+ end
+end
View
125 lib/generators/clearance/install/install_generator.rb
@@ -1,46 +1,127 @@
-require 'diesel/generators/install_base'
+require 'rails/generators/base'
+require 'rails/generators/active_record'
module Clearance
module Generators
- class InstallGenerator < Diesel::Generators::InstallBase
- def install
- template "clearance.rb", "config/initializers/clearance.rb"
+ class InstallGenerator < Rails::Generators::Base
+ include Rails::Generators::Migration
+ source_root File.expand_path('../templates', __FILE__)
- inject_into_class "app/controllers/application_controller.rb", ApplicationController do
- " include Clearance::Authentication\n"
- end
+ def create_clearance_initializer
+ copy_file 'clearance.rb', 'config/initializers/clearance.rb'
+ end
- user_model = "app/models/user.rb"
- if File.exists?(user_model)
- inject_into_class user_model, User do
- "include Clearance::User"
- end
+ def inject_clearance_into_application_controller
+ inject_into(
+ ApplicationController,
+ 'app/controllers/application_controller.rb',
+ 'include Clearance::Authentication'
+ )
+ end
+
+ def create_or_inject_clearance_into_user_model
+ if File.exists? 'app/models/user.rb'
+ inject_into User, 'app/models/user.rb', 'include Clearance::User'
else
- template "user.rb", user_model
+ copy_file 'user.rb', 'app/models/user.rb'
end
+ end
- if File.exists?("spec")
- template "spec/factories.rb", "spec/factories/clearance.rb"
+ def create_clearance_migration
+ if users_table_exists?
+ create_add_columns_migration
else
- template "spec/factories.rb", "test/factories/clearance.rb"
+ create_migration 'create_users.rb'
end
+ end
- readme "README"
+ def display_readme_in_terminal
+ readme 'README'
end
private
- def migrations
- if users_table_exists?
- super.reject { |name| name.include?("create") } + ["db/migrate/upgrade_clearance_to_diesel.rb"]
- else
- super
+ def create_add_columns_migration
+ if migration_needed?
+ config = {
+ :new_columns => new_columns,
+ :new_indexes => new_indexes
+ }
+
+ create_migration('add_clearance_to_users.rb', config)
end
end
+ def create_migration(migration_name, config = {})
+ unless migration_exists?(migration_name)
+ migration_template(
+ "db/migrate/#{migration_name}",
+ "db/migrate/#{migration_name}",
+ config
+ )
+ end
+ end
+
+ def inject_into(class_name, file, text)
+ if file_does_not_contain?(file, text)
+ inject_into_class file, class_name, " #{text}\n"
+ end
+ end
+
+ def file_does_not_contain?(file, text)
+ File.readlines(file).grep(/#{text}/).none?
+ end
+
+ def migration_needed?
+ new_columns.any? || new_indexes.any?
+ end
+
+ def new_columns
+ @new_columns ||= {
+ :email => 't.string :email',
+ :encrypted_password => 't.string :encrypted_password, :limit => 128',
+ :confirmation_token => 't.string :confirmation_token, :limit => 128',
+ :remember_token => 't.string :remember_token, :limit => 128'
+ }.reject { |column| existing_users_columns.include?(column.to_s) }
+ end
+
+ def new_indexes
+ @new_indexes ||= {
+ :index_users_on_email => 'add_index :users, :email',
+ :index_users_on_remember_token => 'add_index :users, :remember_token'
+ }.reject { |index| existing_users_indexes.include?(index.to_s) }
+ end
+
+ def migration_exists?(name)
+ existing_migrations.include?(name)
+ end
+
+ def existing_migrations
+ @existing_migrations ||= Dir.glob("db/migrate/*.rb").map do |file|
+ migration_name_without_timestamp(file)
+ end
+ end
+
+ def migration_name_without_timestamp(file)
+ file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, '')
+ end
+
def users_table_exists?
ActiveRecord::Base.connection.table_exists?(:users)
end
+
+ def existing_users_columns
+ ActiveRecord::Base.connection.columns(:users).map(&:name)
+ end
+
+ def existing_users_indexes
+ ActiveRecord::Base.connection.indexes(:users).map(&:name)
+ end
+
+ # for generating a timestamp when using `create_migration`
+ def self.next_migration_number(dir)
+ ActiveRecord::Generators::Base.next_migration_number(dir)
+ end
end
end
end
View
21 lib/generators/clearance/install/templates/README
@@ -5,19 +5,26 @@ Next steps:
1. Configure the mailer to create full URLs in emails:
- # config/environments/{development,test}.rb
- config.action_mailer.default_url_options = { :host => 'localhost:3000' }
+ # config/environments/{development,test}.rb
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
- In production it should be your app's domain name.
+ In production it should be your app's domain name.
-2. Display flashes. For example, in your application layout:
+2. Display user session and flashes. For example, in your application layout:
- <% flash.each do |key, value| -%>
+ <% if signed_in? %>
+ Signed in as: <%= current_user.email %>
+ <%= link_to 'Sign out', sign_out_path, :method => :delete %>
+ <% else %>
+ <%= link_to 'Sign in', sign_in_path %>
+ <% end %>
+
+ <% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
- <% end -%>
+ <% end %>
3. Migrate:
- rake db:migrate
+ rake db:migrate
*******************************************************************************
View
21 lib/generators/clearance/install/templates/db/migrate/add_clearance_to_users.rb
@@ -0,0 +1,21 @@
+class AddClearanceToUsers < ActiveRecord::Migration
+ def self.up
+ change_table :users do |t|
+<% config[:new_columns].values.each do |column| -%>
+ <%= column %>
+<% end -%>
+ end
+
+<% config[:new_indexes].values.each do |index| -%>
+ <%= index %>
+<% end -%>
+ end
+
+ def self.down
+ change_table :users do |t|
+<% if config[:new_columns].any? -%>
+ t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(',') %>
+<% end -%>
+ end
+ end
+end
View
18 lib/generators/clearance/install/templates/db/migrate/create_users.rb
@@ -0,0 +1,18 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ t.timestamps :null => false
+ t.string :email, :null => false
+ t.string :encrypted_password, :limit => 128, :null => false
+ t.string :confirmation_token, :limit => 128
+ t.string :remember_token, :limit => 128, :null => false
+ end
+
+ add_index :users, :email
+ add_index :users, :remember_token
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
View
37 lib/generators/clearance/install/templates/db/migrate/upgrade_clearance_to_diesel.rb
@@ -1,37 +0,0 @@
-<%
- existing_columns = ActiveRecord::Base.connection.columns(:users).map(&:name)
- new_columns = {
- :email => 't.string :email',
- :encrypted_password => 't.string :encrypted_password, :limit => 128',
- :confirmation_token => 't.string :confirmation_token, :limit => 128',
- :remember_token => 't.string :remember_token, :limit => 128'
- }.reject { |column| existing_columns.include?(column.to_s) }
--%>
-<%
- existing_indexes = ActiveRecord::Base.connection.indexes(:users).map(&:name)
- new_indexes = {
- :index_users_on_email => 'add_index :users, :email',
- :index_users_on_remember_token => 'add_index :users, :remember_token'
- }.reject { |index| existing_indexes.include?(index.to_s) }
--%>
-class UpgradeClearanceToDiesel < ActiveRecord::Migration
- def self.up
- change_table :users do |t|
-<% new_columns.values.each do |column| -%>
- <%= column %>
-<% end -%>
- end
-
-<% new_indexes.values.each do |index| -%>
- <%= index %>
-<% end -%>
- end
-
- def self.down
- change_table :users do |t|
-<% if new_columns.any? -%>
- t.remove <%= new_columns.keys.map { |column| ":#{column}" }.join(',') %>
-<% end -%>
- end
- end
-end
View
15 lib/generators/clearance/views/USAGE
@@ -0,0 +1,15 @@
+Description:
+ Override the default clearance views. This generator will copy all off the
+ base clearance views into your project.
+
+Examples:
+ rails generate clearance:views
+
+ View: app/views/clearance_mailer/change_password.html.erb
+ View: app/views/passwords/create.html.erb
+ View: app/views/passwords/edit.html.erb
+ View: app/views/passwords/new.html.erb
+ View: app/views/sessions/_form.html.erb
+ View: app/views/sessions/new.html.erb
+ View: app/views/users/_form.html.erb
+ View: app/views/users/new.html.erb
View
25 lib/generators/clearance/views/views_generator.rb
@@ -1,8 +1,29 @@
-require 'diesel/generators/views_base'
+require 'rails/generators/base'
module Clearance
module Generators
- class ViewsGenerator < Diesel::Generators::ViewsBase
+ class ViewsGenerator < Rails::Generators::Base
+ source_root Clearance.root
+
+ def create_views
+ views.each do |view|
+ copy_file view
+ end
+ end
+
+ private
+
+ def views
+ files_within_root('.', 'app/views/**/*.*')
+ end
+
+ def files_within_root(prefix, glob)
+ root = "#{self.class.source_root}/#{prefix}"
+
+ Dir["#{root}/#{glob}"].sort.map do |full_path|
+ full_path.sub(root, '.').gsub('/./', '/')
+ end
+ end
end
end
end
View
8 spec/spec_helper.rb
@@ -8,15 +8,17 @@
Bundler.require
-require 'diesel/testing'
+require 'clearance/testing/application'
require 'rspec/rails'
require 'bourne'
-require 'timecop'
require 'factory_girl_rails'
require 'shoulda-matchers'
require 'clearance/testing'
+require 'timecop'
+
+Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
-Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
+Clearance::Testing::Application.initialize!
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
Please sign in to comment.
Something went wrong with that request. Please try again.