forked from scambra/devise_invitable
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* devise_invitable:install * devise_invitable MODEL * devise_invitable:views (thanks to robotblake for this one) See README for more info. Added :slow => true for slow generators' specs
- Loading branch information
Rémy Coutable
committed
Sep 2, 2010
1 parent
1d37456
commit 443fe59
Showing
14 changed files
with
229 additions
and
21 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
lib/generators/active_record/devise_invitable_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rails/generators/active_record' | ||
|
||
module ActiveRecord | ||
module Generators | ||
class DeviseInvitableGenerator < ActiveRecord::Generators::Base | ||
source_root File.expand_path("../templates", __FILE__) | ||
|
||
def copy_devise_migration | ||
migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration | ||
def self.up | ||
change_table :<%= table_name %> do |t| | ||
t.string :invitation_token, :limit => 20 | ||
t.datetime :invitation_sent_at | ||
t.index :invitation_token # for invitable | ||
end | ||
|
||
# And allow null encrypted_password and password_salt: | ||
change_column :<%= table_name %>, :encrypted_password, :string, :null => true | ||
change_column :<%= table_name %>, :password_salt, :string, :null => true | ||
end | ||
|
||
def self.down | ||
remove_column :<%= table_name %>, :invitation_sent_at | ||
remove_column :<%= table_name %>, :invitation_token | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
lib/generators/devise_invitable/devise_invitable_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module DeviseInvitable | ||
module Generators | ||
class DeviseInvitableGenerator < Rails::Generators::NamedBase | ||
namespace "devise_invitable" | ||
|
||
desc "Add :invitable directive in the given model. Also generate migration for ActiveRecord" | ||
|
||
def inject_devise_invitable_content | ||
path = File.join("app", "models", "#{file_path}.rb") | ||
inject_into_file(path, "invitable, :", :after => "devise :") if File.exists?(path) | ||
end | ||
|
||
hook_for :orm | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module DeviseInvitable | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../../templates", __FILE__) | ||
|
||
desc "Add DeviseInvitable config variables to the Devise initializer and copy DeviseInvitable locale files to your application." | ||
|
||
def add_config_options_to_initializer | ||
devise_initializer_path = "config/initializers/devise.rb" | ||
if File.exist?(devise_initializer_path) | ||
old_content = File.read(devise_initializer_path) | ||
|
||
if old_content.match(Regexp.new(/^\s# ==> Configuration for :invitable\n/)) | ||
false | ||
else | ||
inject_into_file(devise_initializer_path, :before => " # ==> Configuration for :confirmable\n") do | ||
<<-CONTENT | ||
# ==> Configuration for :invitable | ||
# Time interval where the invitation token is valid (default: 0). | ||
# If invite_for is 0 or nil, the invitation will never expire. | ||
# config.invite_for = 2.weeks | ||
# Flag that force a record to be valid before being actually invited | ||
# (default: false). | ||
# config.validate_on_invite = true | ||
CONTENT | ||
end | ||
end | ||
end | ||
end | ||
|
||
def copy_locale | ||
copy_file "../../../config/locales/en.yml", "config/locales/devise_invitable.en.yml" | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
require 'spec_helper' | ||
require 'rails/generators' | ||
require 'generators/devise_invitable/devise_invitable_generator' | ||
|
||
describe DeviseInvitable::Generators::DeviseInvitableGenerator, :slow => true do | ||
RAILS_APP_PATH = File.expand_path("../../rails_app", __FILE__) | ||
|
||
describe "rails g" do | ||
before(:each) { @output = `cd #{RAILS_APP_PATH} && rails g` } | ||
|
||
it "should include the 3 generators" do | ||
@output.should include("DeviseInvitable:\n devise_invitable\n devise_invitable:install\n devise_invitable:views") | ||
end | ||
end | ||
|
||
describe "rails g devise_invitable:install" do | ||
before(:all) { @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p` } | ||
|
||
it "should include inject config/initializers/devise.rb" do | ||
@output.should =~ %r(inject.+ config/initializers/devise\.rb\n) | ||
end | ||
it "should include create config/locales/devise_invitable.en.yml" do | ||
@output.should =~ %r(create.+ config/locales/devise_invitable\.en\.yml\n) | ||
end | ||
end | ||
|
||
describe "rails g devise_invitable:views" do | ||
context "not scoped" do | ||
before(:all) { @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views -p` } | ||
|
||
it "should include create app/views/devise" do | ||
@output.should =~ %r(create.+ app/views/devise\n) | ||
end | ||
it "should include create app/views/devise/invitations/edit.html.erb" do | ||
@output.should =~ %r(create.+ app/views/devise/invitations/edit\.html\.erb\n) | ||
end | ||
it "should include create app/views/devise/invitations/new.html.erb" do | ||
@output.should =~ %r(create.+ app/views/devise/invitations/new\.html\.erb\n) | ||
end | ||
it "should include app/views/devise/mailer/invitation_instructions.html.erb" do | ||
@output.should =~ %r(create.+ app/views/devise/mailer/invitation_instructions\.html\.erb\n) | ||
end | ||
end | ||
|
||
context "scoped" do | ||
before(:all) { @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views octopussies -p` } | ||
|
||
it "should include create app/views/octopussies" do | ||
@output.should =~ %r(create.+ app/views/octopussies\n) | ||
end | ||
it "should include create app/views/octopussies/invitations/edit.html.erb" do | ||
@output.should =~ %r(create.+ app/views/octopussies/invitations/edit\.html\.erb\n) | ||
end | ||
it "should include create app/views/octopussies/invitations/new.html.erb" do | ||
@output.should =~ %r(create.+ app/views/octopussies/invitations/new\.html\.erb\n) | ||
end | ||
it "should include app/views/octopussies/mailer/invitation_instructions.html.erb" do | ||
@output.should =~ %r(create.+ app/views/octopussies/mailer/invitation_instructions\.html\.erb\n) | ||
end | ||
end | ||
|
||
pending "haml" do | ||
before(:all) do | ||
RailsApp::Application.config.generators.options[:rails][:template_engine] = :haml | ||
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views octopussies -p` | ||
puts RailsApp::Application.config.generators.options[:rails][:template_engine] | ||
end | ||
|
||
it "should include create app/views/octopussies" do | ||
@output.should =~ %r(create.+ app/views/octopussies\n) | ||
end | ||
it "should include create app/views/octopussies/invitations/edit.html.haml" do | ||
@output.should =~ %r(create.+ app/views/octopussies/invitations/edit\.html\.haml\n) | ||
end | ||
it "should include create app/views/octopussies/invitations/new.html.erb" do | ||
@output.should =~ %r(create.+ app/views/octopussies/invitations/new\.html\.haml\n) | ||
end | ||
it "should include app/views/octopussies/mailer/invitation_instructions.html.erb" do | ||
@output.should =~ %r(create.+ app/views/octopussies/mailer/invitation_instructions\.html\.haml\n) | ||
end | ||
end | ||
end | ||
|
||
describe "rails g devise_invitable Octopussy" do | ||
before(:each) { @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p` } | ||
|
||
it "should include inject app/models/octopussy.rb" do | ||
@output.should =~ %r(inject.+ app/models/octopussy\.rb\n) | ||
end | ||
it "should include invoke active_record" do | ||
@output.should =~ %r(invoke.+ #{DEVISE_ORM}\n) | ||
end | ||
it "should include create db/migrate/\d{14}_devise_invitable_add_to_octopussies.rb if orm is ActiveRecord" do | ||
if DEVISE_ORM == :active_record | ||
@output.should =~ %r(create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n) | ||
elsif DEVISE_ORM == :mongoid | ||
@output.should_not =~ %r(create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "spec_helper" | ||
require 'spec_helper' | ||
|
||
describe Devise::Models::Invitable do | ||
before(:each) do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "spec_helper" | ||
require 'spec_helper' | ||
|
||
describe Devise::Models::Invitable do | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This model is here for the generators' specs | ||
if DEVISE_ORM == :active_record | ||
class Octopussy < ActiveRecord::Base | ||
devise :database_authenticatable, :validatable, :confirmable | ||
end | ||
elsif DEVISE_ORM == :mongoid | ||
class Octopussy | ||
include Mongoid::Document | ||
devise :database_authenticatable, :validatable, :confirmable | ||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters