require 'test_helper' <% module_namespacing do -%> class <%= controller_class_name %>ControllerTest < ActionController::TestCase setup do @<%= resource_name %> = <%= resource_name.pluralize %>(:one) end test "should get new" do get :new assert_response :success end <% goma_config.authentication_keys.each do |key| -%> test "should login with <%= key %>" do <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %> <% if resource_name.to_sym == goma_config.default_scope -%> assert logged_in? <% else -%> assert <%= resource_name %>_logged_in? <% end -%> assert_redirected_to root_path assert_match /Login successful/, flash[:notice] end test "should not login with <%= key %> with wrong password" do <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'wrongpass'" %> <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> assert_template :new assert_match /Login failed/, flash[:alert] end <% if goma_config.modules.include? :confirmable -%> <% if goma_config.allow_unactivated_access_for > 0 -%> test "should login unactivated <%= resource_name %> with <%= key %> for <%= goma_config.allow_unactivated_access_for %>" do unactivated_<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>) <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %> <% if resource_name.to_sym == goma_config.default_scope -%> assert logged_in? <% else -%> assert <%= resource_name %>_logged_in? <% end -%> assert_redirected_to root_path assert_match /Login successful/, flash[:alert] end test "should not login unactivated <%= resource_name %> with <%= key %> <%= goma_config.allow_unactivated_access_for %> passed after registration" do unactivated_<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>) unactivated_<%= resource_name %>.update_column(:created_at, <%= expire(goma_config.allow_unactivated_access_for) %>.ago) <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %> <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> assert_template :new assert_match /Not activated/, flash[:alert] end <% else -%> test "should not login unactivated <%= resource_name %> with <%= key %>" do unactivated_<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>) <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> post :create, <%= "#{goma_config.authentication_keys.to_field_name}: unactivated_#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %> <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> assert_template :new assert_match /Not activated/, flash[:alert] end <% end # if goma_config.allow_unactivated_access_for > 0 -%> <% end # if goma_config.modules.include? :confirmable -%> <% end # goma_config.authentication_keys.each do |key| -%> test "should logout <%= resource_name %>" do force_login(@<%= resource_name %>) <% if resource_name.to_sym == goma_config.default_scope -%> assert logged_in? <% else -%> assert <%= resource_name %>_logged_in? <% end -%> delete :destroy, id: <%= "@#{resource_name}" %> assert_redirected_to root_path assert_match /Logged out/, flash[:notice] <% if resource_name.to_sym == goma_config.default_scope -%> refute logged_in? <% else -%> refute <%= resource_name %>_logged_in? <% end -%> end end <% end -%>