2010-12-18 02:22:01 -05:00
|
|
|
require "test_helper"
|
2010-10-18 16:05:04 -04:00
|
|
|
|
|
|
|
class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
|
|
tests Devise::Generators::ViewsGenerator
|
2010-12-09 20:52:30 -05:00
|
|
|
destination File.expand_path("../../tmp", __FILE__)
|
2010-10-18 16:05:04 -04:00
|
|
|
setup :prepare_destination
|
|
|
|
|
|
|
|
test "Assert all views are properly created with no params" do
|
|
|
|
run_generator
|
2010-10-18 16:52:29 -04:00
|
|
|
assert_files
|
2013-02-06 13:37:12 -05:00
|
|
|
assert_shared_links
|
2010-10-18 16:52:29 -04:00
|
|
|
end
|
|
|
|
|
2013-02-06 13:37:12 -05:00
|
|
|
test "Assert all views are properly created with scope param" do
|
2010-10-18 16:52:29 -04:00
|
|
|
run_generator %w(users)
|
|
|
|
assert_files "users"
|
2013-02-06 13:37:12 -05:00
|
|
|
assert_shared_links "users"
|
2010-10-18 16:52:29 -04:00
|
|
|
|
|
|
|
run_generator %w(admins)
|
|
|
|
assert_files "admins"
|
2013-02-06 13:37:12 -05:00
|
|
|
assert_shared_links "admins"
|
2010-10-18 16:52:29 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 10:50:28 -04:00
|
|
|
test "Assert views with simple form" do
|
|
|
|
run_generator %w(-b simple_form_for)
|
|
|
|
assert_files
|
2011-11-10 07:19:57 -05:00
|
|
|
assert_file "app/views/devise/confirmations/new.html.erb", /simple_form_for/
|
2011-06-27 10:50:28 -04:00
|
|
|
|
|
|
|
run_generator %w(users -b simple_form_for)
|
|
|
|
assert_files "users"
|
2011-11-10 07:19:57 -05:00
|
|
|
assert_file "app/views/users/confirmations/new.html.erb", /simple_form_for/
|
2011-09-14 01:50:39 -04:00
|
|
|
end
|
|
|
|
|
2011-10-01 01:41:02 -04:00
|
|
|
test "Assert views with markerb" do
|
2011-09-14 01:50:39 -04:00
|
|
|
run_generator %w(--markerb)
|
2014-02-25 11:42:55 -05:00
|
|
|
assert_files nil, mail_template_engine: "markerb"
|
2011-09-14 23:20:20 -04:00
|
|
|
end
|
|
|
|
|
2014-03-03 12:30:00 -05:00
|
|
|
|
|
|
|
test "Assert only views within specified directories" do
|
2014-03-06 16:41:11 -05:00
|
|
|
run_generator %w(-v sessions registrations)
|
2014-03-03 12:30:00 -05:00
|
|
|
assert_file "app/views/devise/sessions/new.html.erb"
|
|
|
|
assert_file "app/views/devise/registrations/new.html.erb"
|
|
|
|
assert_file "app/views/devise/registrations/edit.html.erb"
|
|
|
|
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
2014-03-04 17:47:19 -05:00
|
|
|
assert_no_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
|
|
|
end
|
|
|
|
|
2015-08-27 11:12:13 -04:00
|
|
|
test "Assert mailer specific directory with simple form" do
|
|
|
|
run_generator %w(-v mailer -b simple_form_for)
|
|
|
|
assert_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
|
|
|
assert_file "app/views/devise/mailer/reset_password_instructions.html.erb"
|
|
|
|
assert_file "app/views/devise/mailer/unlock_instructions.html.erb"
|
|
|
|
end
|
|
|
|
|
2014-03-04 17:47:19 -05:00
|
|
|
test "Assert specified directories with scope" do
|
2014-03-06 16:41:11 -05:00
|
|
|
run_generator %w(users -v sessions)
|
2014-03-04 17:47:19 -05:00
|
|
|
assert_file "app/views/users/sessions/new.html.erb"
|
|
|
|
assert_no_file "app/views/users/confirmations/new.html.erb"
|
|
|
|
end
|
2014-03-03 12:30:00 -05:00
|
|
|
|
2014-03-04 17:47:19 -05:00
|
|
|
test "Assert specified directories with simple form" do
|
2014-03-06 16:41:11 -05:00
|
|
|
run_generator %w(-v registrations -b simple_form_for)
|
2014-03-04 17:47:19 -05:00
|
|
|
assert_file "app/views/devise/registrations/new.html.erb", /simple_form_for/
|
|
|
|
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "Assert specified directories with markerb" do
|
2014-03-06 16:41:11 -05:00
|
|
|
run_generator %w(--markerb -v passwords mailer)
|
2014-03-04 17:47:19 -05:00
|
|
|
assert_file "app/views/devise/passwords/new.html.erb"
|
|
|
|
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
|
|
|
assert_file "app/views/devise/mailer/reset_password_instructions.markerb"
|
2014-03-03 12:30:00 -05:00
|
|
|
end
|
|
|
|
|
2011-09-13 03:19:48 -04:00
|
|
|
def assert_files(scope = nil, options={})
|
2010-10-18 16:52:29 -04:00
|
|
|
scope = "devise" if scope.nil?
|
2011-11-10 07:19:57 -05:00
|
|
|
mail_template_engine = options[:mail_template_engine] || "html.erb"
|
2011-09-13 03:19:48 -04:00
|
|
|
|
2010-12-09 20:52:30 -05:00
|
|
|
assert_file "app/views/#{scope}/confirmations/new.html.erb"
|
2011-09-13 03:19:48 -04:00
|
|
|
assert_file "app/views/#{scope}/mailer/confirmation_instructions.#{mail_template_engine}"
|
|
|
|
assert_file "app/views/#{scope}/mailer/reset_password_instructions.#{mail_template_engine}"
|
|
|
|
assert_file "app/views/#{scope}/mailer/unlock_instructions.#{mail_template_engine}"
|
2010-12-09 20:52:30 -05:00
|
|
|
assert_file "app/views/#{scope}/passwords/edit.html.erb"
|
|
|
|
assert_file "app/views/#{scope}/passwords/new.html.erb"
|
|
|
|
assert_file "app/views/#{scope}/registrations/new.html.erb"
|
|
|
|
assert_file "app/views/#{scope}/registrations/edit.html.erb"
|
|
|
|
assert_file "app/views/#{scope}/sessions/new.html.erb"
|
2014-08-17 18:15:25 -04:00
|
|
|
assert_file "app/views/#{scope}/shared/_links.html.erb"
|
2010-12-09 20:52:30 -05:00
|
|
|
assert_file "app/views/#{scope}/unlocks/new.html.erb"
|
2010-10-18 16:05:04 -04:00
|
|
|
end
|
2013-02-06 13:37:12 -05:00
|
|
|
|
|
|
|
def assert_shared_links(scope = nil)
|
|
|
|
scope = "devise" if scope.nil?
|
|
|
|
link = /<%= render \"#{scope}\/shared\/links\" %>/
|
|
|
|
|
|
|
|
assert_file "app/views/#{scope}/passwords/edit.html.erb", link
|
|
|
|
assert_file "app/views/#{scope}/passwords/new.html.erb", link
|
|
|
|
assert_file "app/views/#{scope}/confirmations/new.html.erb", link
|
|
|
|
assert_file "app/views/#{scope}/registrations/new.html.erb", link
|
|
|
|
assert_file "app/views/#{scope}/sessions/new.html.erb", link
|
|
|
|
assert_file "app/views/#{scope}/unlocks/new.html.erb", link
|
|
|
|
end
|
2010-10-18 16:05:04 -04:00
|
|
|
end
|