Welcome <%= @resource.email %>!
+ +You can confirm your account email through the link below:
+ +<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..ae9e888 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +Hello <%= @resource.email %>!
+ +Someone has requested a link to change your password, and you can do this through the link below.
+ +<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
+ +If you didn't request this, please ignore this email.
+Your password won't change until you access the link above and create a new one.
diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..2263c21 --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +Hello <%= @resource.email %>!
+ +Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
+ +Click the link below to unlock your account:
+ +<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000..e75c937 --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,16 @@ +<%= f.label :name %>
+<%= f.text_field :name %>
Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.
+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000..8e5d0a2 --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,20 @@ +<%= f.label :name %>
+<%= f.text_field :name %>
User: <%=link_to user.name, user %>
+<% end %> diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb new file mode 100644 index 0000000..0e52c5a --- /dev/null +++ b/app/views/layouts/_navigation.html.erb @@ -0,0 +1,26 @@ +<%= link_to "Rails3 Bootstrap Devise Cancan", root_path, :class => 'brand' %> + \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..fc03c31 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,43 @@ + + + + + + +Find me in app/views/users/index.html.erb
+Find me in app/views/users/show.html.erb
+User: <%= @user.name %>
+Email: <%= @user.email if @user.email %>
diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..836f45a --- /dev/null +++ b/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 Rails3BootstrapDeviseCancan::Application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..2e4c9a6 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,75 @@ +require File.expand_path('../boot', __FILE__) + +# Pick the frameworks you want: +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "active_resource/railtie" +require "sprockets/railtie" +# require "rails/test_unit/railtie" + +if defined?(Bundler) + # If you precompile assets before deploying to production, use this line + Bundler.require(*Rails.groups(:assets => %w(development test))) + # If you want your assets lazily compiled in production, use this line + # Bundler.require(:default, :assets, Rails.env) +end + +module Rails3BootstrapDeviseCancan + class Application < Rails::Application + + # don't generate RSpec tests for views and helpers + config.generators do |g| + g.view_specs false + g.helper_specs false + + end + + # 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) + config.autoload_paths += %W(#{config.root}/lib) + + + # 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, :password_confirmation] + + # Use SQL instead of Active Record's schema dumper when creating the 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 + + # Enforce whitelist mode for mass assignment. + # This will create an empty whitelist of attributes available for mass-assignment for all models + # in your app. As such, your models will need to explicitly whitelist or blacklist accessible + # parameters by using an attr_accessible or attr_protected declaration. + config.active_record.whitelist_attributes = true + + # Enable the asset pipeline + config.assets.enabled = true + + # Version of your assets, change this if you want to expire all your assets + config.assets.version = '1.0' + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..4489e58 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,6 @@ +require 'rubygems' + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/config/cucumber.yml b/config/cucumber.yml new file mode 100644 index 0000000..2f0d8ce --- /dev/null +++ b/config/cucumber.yml @@ -0,0 +1,8 @@ +<% +rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" +rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" +std_opts = "-r features/support/ -r features/step_definitions --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip" +%> +default: <%= std_opts %> features +wip: --tags @wip:3 --wip features +rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..7a3f570 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the rails application +require File.expand_path('../application', __FILE__) + +# Initialize the rails application +Rails3BootstrapDeviseCancan::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..a18a45e --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,54 @@ +Rails3BootstrapDeviseCancan::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 + + # ActionMailer Config + config.action_mailer.default_url_options = { :host => 'localhost:3000' } + config.action_mailer.delivery_method = :smtp + # change to false to prevent email from being sent during development + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = true + config.action_mailer.default :charset => "utf-8" + + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "example.com", + authentication: "plain", + enable_starttls_auto: true, + user_name: ENV["GMAIL_USERNAME"], + password: ENV["GMAIL_PASSWORD"] + } + + + + # 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 + + # Raise exception on mass assignment protection for Active Record models + config.active_record.mass_assignment_sanitizer = :strict + + # Log the query plan for queries taking more than this (works + # with SQLite, MySQL, and PostgreSQL) + config.active_record.auto_explain_threshold_in_seconds = 0.5 + + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..b17c5aa --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,87 @@ +Rails3BootstrapDeviseCancan::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 = false + + # Compress JavaScripts and CSS + config.assets.compress = true + + # Don't fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true + + # Defaults to Rails.root.join("public/assets") + # config.assets.manifest = YOUR_PATH + + # Specifies the header that your server uses for sending files + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = '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 + + # Prepend all log lines with the following tags + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups + # config.logger = ActiveSupport::TaggedLogging.new(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 + + config.action_mailer.default_url_options = { :host => 'example.com' } + # ActionMailer Config + # Setup for production - deliveries, no errors raised + config.action_mailer.delivery_method = :smtp + config.action_mailer.perform_deliveries = true + config.action_mailer.raise_delivery_errors = false + config.action_mailer.default :charset => "utf-8" + + config.action_mailer.smtp_settings = { + address: "smtp.gmail.com", + port: 587, + domain: "example.com", + authentication: "plain", + enable_starttls_auto: true, + user_name: ENV["GMAIL_USERNAME"], + password: ENV["GMAIL_PASSWORD"] + } + + + + # Log the query plan for queries taking more than this (works + # with SQLite, MySQL, and PostgreSQL) + # config.active_record.auto_explain_threshold_in_seconds = 0.5 +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..4e0cbed --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,41 @@ +Rails3BootstrapDeviseCancan::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 = true + + # 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 + + # Raise exception on mass assignment protection for Active Record models + config.active_record.mass_assignment_sanitizer = :strict + + # Print deprecation notices to the stderr + config.active_support.deprecation = :stderr + + # ActionMailer Config + config.action_mailer.default_url_options = { :host => 'example.com' } + +end diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/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/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000..3538bbe --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,223 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class with default "from" parameter. + config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" + + # Configure the class responsible to send e-mails. + # config.mailer = "Devise::Mailer" + + # Automatically apply schema changes in tableless databases + config.apply_schema = false + + # ==> 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 a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a 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. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [ :email ] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [ :email ] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [ :email ] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Basic Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:token]` will + # enable it only for token authentication. + # config.http_authenticatable = false + + # If http headers should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. "Application" by default. + # config.http_authentication_realm = "Application" + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # :http_auth and :token_auth by adding those symbols to the array below. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing :skip => :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # ==> 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. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. + config.stretches = Rails.env.test? ? 1 : 10 + + # Setup a pepper to generate the encrypted password. + # config.pepper = "3fb11f24c9c436c1b105b405f8493bb6bd13b01e52b71cef31ab527a38158efaa13cd94b09e0908ddee9a8507ed10dcf6bae72b0042d87a7f8e384c9a98baa7c" + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming his account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming his account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming his account. + # config.allow_unconfirmed_access_for = 2.days + + # If true, requires any email changes to be confirmed (exctly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed new email is stored in + # unconfirmed email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [ :email ] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # If true, uses the password salt as remember token. This should be turned + # to false if you are not using database authenticatable. + config.use_salt_as_remember_token = true + + # Options to be passed to the created cookie. For instance, you can set + # :secure => true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. Default is 6..128. + # config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # an one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + # config.email_regexp = /\A[^@]+@[^@]+\z/ + + # ==> 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. Default is 30 minutes. + # config.timeout_in = 30.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 key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + + # 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 :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # ==> Configuration for :encryptable + # Allow you to use another encryption algorithm besides bcrypt (default). You can use + # :sha1, :sha512 or 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 = :sha512 + + # ==> 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 = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Configure sign_out behavior. + # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). + # The default is true, which means any logout action will sign out all active scopes. + # config.sign_out_all_scopes = true + + # ==> 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. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ["*/*", :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = Rails.env.test? ? :get : :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(:scope => :user).unshift :some_external_strategy + # end +end diff --git a/config/initializers/generators.rb b/config/initializers/generators.rb new file mode 100644 index 0000000..4b3d83a --- /dev/null +++ b/config/initializers/generators.rb @@ -0,0 +1,2 @@ +Rails.application.config.generators do |g| +end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..5d8d9be --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,15 @@ +# 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 +# +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/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/config/initializers/rolify.rb b/config/initializers/rolify.rb new file mode 100644 index 0000000..e792a6e --- /dev/null +++ b/config/initializers/rolify.rb @@ -0,0 +1,7 @@ +Rolify.configure do |config| + # By default ORM adapter is ActiveRecord. uncomment to use mongoid + # config.use_mongoid + + # Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false + # config.use_dynamic_shortcuts +end \ No newline at end of file diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb new file mode 100644 index 0000000..257b053 --- /dev/null +++ b/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. +Rails3BootstrapDeviseCancan::Application.config.secret_token = 'a6cd68af2c0c93e2f0bd4c576aab509f59b7ae839d02018caa4c8ce3cc46ea012fdc4f1dc93bbb14137bc646fb697907e9649260d02b77eed838717d20dff479' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..da98e7f --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +Rails3BootstrapDeviseCancan::Application.config.session_store :cookie_store, key: '_rails3-bootstrap-devise-cancan_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") +# Rails3BootstrapDeviseCancan::Application.config.session_store :active_record_store diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..999df20 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# 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. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# Disable root element in JSON by default. +ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 0000000..2c0df7d --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,57 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + errors: + messages: + expired: "has expired, please request a new one" + not_found: "not found" + already_confirmed: "was already confirmed, please try signing in" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" + + devise: + failure: + already_authenticated: 'You are already signed in.' + unauthenticated: 'You need to sign in or sign up before continuing.' + unconfirmed: 'You have to confirm your account before continuing.' + locked: 'Your account is locked.' + invalid: 'Invalid email or password.' + invalid_token: 'Invalid authentication token.' + timeout: 'Your session expired, please sign in again to continue.' + inactive: 'Your account was not activated yet.' + sessions: + signed_in: 'Signed in successfully.' + signed_out: 'Signed out successfully.' + passwords: + send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.' + updated: 'Your password was changed successfully. You are now signed in.' + updated_not_active: 'Your password was changed successfully.' + send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail" + confirmations: + send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' + send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.' + confirmed: 'Your account was successfully confirmed. You are now signed in.' + registrations: + signed_up: 'Welcome! You have signed up successfully.' + signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' + signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' + signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' + updated: 'You updated your account successfully.' + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." + destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' + unlocks: + send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' + unlocked: 'Your account has been unlocked successfully. Please sign in to continue.' + send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.' + omniauth_callbacks: + success: 'Successfully authenticated from %{kind} account.' + failure: 'Could not authenticate you from %{kind} because "%{reason}".' + mailer: + confirmation_instructions: + subject: 'Confirmation instructions' + reset_password_instructions: + subject: 'Reset password instructions' + unlock_instructions: + subject: 'Unlock Instructions' diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..179c14c --- /dev/null +++ b/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/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..3f8f51b --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,8 @@ +Rails3BootstrapDeviseCancan::Application.routes.draw do + authenticated :user do + root :to => 'home#index' + end + root :to => "home#index" + devise_for :users + resources :users, :only => [:show, :index] +end diff --git a/db/migrate/20120418171104_devise_create_users.rb b/db/migrate/20120418171104_devise_create_users.rb new file mode 100644 index 0000000..540333c --- /dev/null +++ b/db/migrate/20120418171104_devise_create_users.rb @@ -0,0 +1,49 @@ +class DeviseCreateUsers < ActiveRecord::Migration + def change + create_table(:users) do |t| + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Encryptable + # t.string :password_salt + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + ## Token authenticatable + # t.string :authentication_token + + + t.timestamps + end + + add_index :users, :email, :unique => true + add_index :users, :reset_password_token, :unique => true + # add_index :users, :confirmation_token, :unique => true + # add_index :users, :unlock_token, :unique => true + # add_index :users, :authentication_token, :unique => true + end +end diff --git a/db/migrate/20120418171110_rolify_create_roles.rb b/db/migrate/20120418171110_rolify_create_roles.rb new file mode 100644 index 0000000..999c94a --- /dev/null +++ b/db/migrate/20120418171110_rolify_create_roles.rb @@ -0,0 +1,19 @@ +class RolifyCreateRoles < ActiveRecord::Migration + def change + create_table(:roles) do |t| + t.string :name + t.references :resource, :polymorphic => true + + t.timestamps + end + + create_table(:users_roles, :id => false) do |t| + t.references :user + t.references :role + end + + add_index(:roles, :name) + add_index(:roles, [ :name, :resource_type, :resource_id ]) + add_index(:users_roles, [ :user_id, :role_id ]) + end +end diff --git a/db/migrate/20120418171112_add_name_to_users.rb b/db/migrate/20120418171112_add_name_to_users.rb new file mode 100644 index 0000000..bac750e --- /dev/null +++ b/db/migrate/20120418171112_add_name_to_users.rb @@ -0,0 +1,5 @@ +class AddNameToUsers < ActiveRecord::Migration + def change + add_column :users, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..8635729 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,53 @@ +# encoding: UTF-8 +# 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 => 20120418171112) do + + create_table "roles", :force => true do |t| + t.string "name" + t.integer "resource_id" + t.string "resource_type" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + add_index "roles", ["name", "resource_type", "resource_id"], :name => "index_roles_on_name_and_resource_type_and_resource_id" + add_index "roles", ["name"], :name => "index_roles_on_name" + + create_table "users", :force => true do |t| + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", :default => 0 + 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.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "name" + end + + add_index "users", ["email"], :name => "index_users_on_email", :unique => true + add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true + + create_table "users_roles", :id => false, :force => true do |t| + t.integer "user_id" + t.integer "role_id" + end + + add_index "users_roles", ["user_id", "role_id"], :name => "index_users_roles_on_user_id_and_role_id" + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..253f8f5 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,13 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) +puts 'SETTING UP DEFAULT USER LOGIN' +user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please' +puts 'New user created: ' << user.name +user2 = User.create! :name => 'Second User', :email => 'user2@example.com', :password => 'please', :password_confirmation => 'please' +puts 'New user created: ' << user2.name +user.add_role :admin diff --git a/features/step_definitions/email_steps.rb b/features/step_definitions/email_steps.rb new file mode 100644 index 0000000..12bcb3f --- /dev/null +++ b/features/step_definitions/email_steps.rb @@ -0,0 +1,206 @@ +# Commonly used email steps +# +# To add your own steps make a custom_email_steps.rb +# The provided methods are: +# +# last_email_address +# reset_mailer +# open_last_email +# visit_in_email +# unread_emails_for +# mailbox_for +# current_email +# open_email +# read_emails_for +# find_email +# +# General form for email scenarios are: +# - clear the email queue (done automatically by email_spec) +# - execute steps that sends an email +# - check the user received an/no/[0-9] emails +# - open the email +# - inspect the email contents +# - interact with the email (e.g. click links) +# +# The Cucumber steps below are setup in this order. + +module EmailHelpers + def current_email_address + # Replace with your a way to find your current email. e.g @current_user.email + # last_email_address will return the last email address used by email spec to find an email. + # Note that last_email_address will be reset after each Scenario. + last_email_address || "example@example.com" + end +end + +World(EmailHelpers) + +# +# Reset the e-mail queue within a scenario. +# This is done automatically before each scenario. +# + +Given /^(?:a clear email queue|no emails have been sent)$/ do + reset_mailer +end + +# +# Check how many emails have been sent/received +# + +Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount| + unread_emails_for(address).size.should == parse_email_count(amount) +end + +Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount| + mailbox_for(address).size.should == parse_email_count(amount) +end + +Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject| + unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount) +end + +Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject| + unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount) +end + +Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body| + open_email(address, :with_text => expected_body) +end + +# +# Accessing emails +# + +# Opens the most recently received email +When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address| + open_email(address) +end + +When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject| + open_email(address, :with_subject => subject) +end + +When /^(?:I|they|"([^"]*?)") opens? the email with subject \/([^"]*?)\/$/ do |address, subject| + open_email(address, :with_subject => Regexp.new(subject)) +end + +When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text| + open_email(address, :with_text => text) +end + +When /^(?:I|they|"([^"]*?)") opens? the email with text \/([^"]*?)\/$/ do |address, text| + open_email(address, :with_text => Regexp.new(text)) +end + +# +# Inspect the Email Contents +# + +Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text| + current_email.should have_subject(text) +end + +Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text| + current_email.should have_subject(Regexp.new(text)) +end + +Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text| + current_email.default_part_body.to_s.should include(text) +end + +Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text| + current_email.default_part_body.to_s.should =~ Regexp.new(text) +end + +Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text| + current_email.should be_delivered_from(text) +end + +Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name| + current_email.should have_header(name, text) +end + +Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name| + current_email.should have_header(name, Regexp.new(text)) +end + +Then /^I should see it is a multi\-part email$/ do + current_email.should be_multipart +end + +Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text| + current_email.html_part.body.to_s.should include(text) +end + +Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text| + current_email.text_part.body.to_s.should include(text) +end + +# +# Inspect the Email Attachments +# + +Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount| + current_email_attachments.size.should == parse_email_count(amount) +end + +Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename| + current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount) +end + +Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename| + current_email_attachments[(index.to_i - 1)].filename.should == filename +end + +Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type| + current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount) +end + +Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type| + current_email_attachments[(index.to_i - 1)].content_type.should include(content_type) +end + +Then /^all attachments should not be blank$/ do + current_email_attachments.each do |attachment| + attachment.read.size.should_not == 0 + end +end + +Then /^show me a list of email attachments$/ do + EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email) +end + +# +# Interact with Email Contents +# + +When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link| + visit_in_email(link) +end + +When /^(?:I|they) click the first link in the email$/ do + click_first_link_in_email +end + +# +# Debugging +# These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command. +# Patches accepted. ;) +# + +Then /^save and open current email$/ do + EmailSpec::EmailViewer::save_and_open_email(current_email) +end + +Then /^save and open all text emails$/ do + EmailSpec::EmailViewer::save_and_open_all_text_emails +end + +Then /^save and open all html emails$/ do + EmailSpec::EmailViewer::save_and_open_all_html_emails +end + +Then /^save and open all raw emails$/ do + EmailSpec::EmailViewer::save_and_open_all_raw_emails +end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb new file mode 100644 index 0000000..942444a --- /dev/null +++ b/features/step_definitions/user_steps.rb @@ -0,0 +1,191 @@ +### UTILITY METHODS ### + +def create_visitor + @visitor ||= { :name => "Testy McUserton", :email => "example@example.com", + :password => "please", :password_confirmation => "please" } +end + +def find_user + @user ||= User.first conditions: {:email => @visitor[:email]} +end + +def create_unconfirmed_user + create_visitor + delete_user + sign_up + visit '/users/sign_out' +end + +def create_user + create_visitor + delete_user + @user = FactoryGirl.create(:user, email: @visitor[:email]) +end + +def delete_user + @user ||= User.first conditions: {:email => @visitor[:email]} + @user.destroy unless @user.nil? +end + +def sign_up + delete_user + visit '/users/sign_up' + fill_in "Name", :with => @visitor[:name] + fill_in "Email", :with => @visitor[:email] + fill_in "Password", :with => @visitor[:password] + fill_in "Password confirmation", :with => @visitor[:password_confirmation] + click_button "Sign up" + find_user +end + +def sign_in + visit '/users/sign_in' + fill_in "Email", :with => @visitor[:email] + fill_in "Password", :with => @visitor[:password] + click_button "Sign in" +end + +### GIVEN ### +Given /^I am not logged in$/ do + visit '/users/sign_out' +end + +Given /^I am logged in$/ do + create_user + sign_in +end + +Given /^I exist as a user$/ do + create_user +end + +Given /^I do not exist as a user$/ do + create_visitor + delete_user +end + +Given /^I exist as an unconfirmed user$/ do + create_unconfirmed_user +end + +### WHEN ### +When /^I sign in with valid credentials$/ do + create_visitor + sign_in +end + +When /^I sign out$/ do + visit '/users/sign_out' +end + +When /^I sign up with valid user data$/ do + create_visitor + sign_up +end + +When /^I sign up with an invalid email$/ do + create_visitor + @visitor = @visitor.merge(:email => "notanemail") + sign_up +end + +When /^I sign up without a password confirmation$/ do + create_visitor + @visitor = @visitor.merge(:password_confirmation => "") + sign_up +end + +When /^I sign up without a password$/ do + create_visitor + @visitor = @visitor.merge(:password => "") + sign_up +end + +When /^I sign up with a mismatched password confirmation$/ do + create_visitor + @visitor = @visitor.merge(:password_confirmation => "please123") + sign_up +end + +When /^I return to the site$/ do + visit '/' +end + +When /^I sign in with a wrong email$/ do + @visitor = @visitor.merge(:email => "wrong@example.com") + sign_in +end + +When /^I sign in with a wrong password$/ do + @visitor = @visitor.merge(:password => "wrongpass") + sign_in +end + +When /^I edit my account details$/ do + click_link "Edit account" + fill_in "Name", :with => "newname" + fill_in "Current password", :with => @visitor[:password] + click_button "Update" +end + +When /^I look at the list of users$/ do + visit '/' +end + +### THEN ### +Then /^I should be signed in$/ do + page.should have_content "Logout" + page.should_not have_content "Sign up" + page.should_not have_content "Login" +end + +Then /^I should be signed out$/ do + page.should have_content "Sign up" + page.should have_content "Login" + page.should_not have_content "Logout" +end + +Then /^I see an unconfirmed account message$/ do + page.should have_content "You have to confirm your account before continuing." +end + +Then /^I see a successful sign in message$/ do + page.should have_content "Signed in successfully." +end + +Then /^I should see a successful sign up message$/ do + page.should have_content "Welcome! You have signed up successfully." +end + +Then /^I should see an invalid email message$/ do + page.should have_content "Email is invalid" +end + +Then /^I should see a missing password message$/ do + page.should have_content "Password can't be blank" +end + +Then /^I should see a missing password confirmation message$/ do + page.should have_content "Password doesn't match confirmation" +end + +Then /^I should see a mismatched password message$/ do + page.should have_content "Password doesn't match confirmation" +end + +Then /^I should see a signed out message$/ do + page.should have_content "Signed out successfully." +end + +Then /^I see an invalid login message$/ do + page.should have_content "Invalid email or password." +end + +Then /^I should see an account edited message$/ do + page.should have_content "You updated your account successfully." +end + +Then /^I should see my name$/ do + create_user + page.should have_content @user[:name] +end diff --git a/features/support/email_spec.rb b/features/support/email_spec.rb new file mode 100644 index 0000000..797d3b2 --- /dev/null +++ b/features/support/email_spec.rb @@ -0,0 +1 @@ +require 'email_spec/cucumber' diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..29f204c --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,59 @@ +# 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 'cucumber/rails' + +# 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 + +# Remove/comment out the lines below if your app doesn't have a database. +# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. +begin + DatabaseCleaner.strategy = :transaction +rescue NameError + raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." +end + +# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. +# See the DatabaseCleaner documentation for details. Example: +# +# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do +# # { :except => [:widgets] } may not do what you expect here +# # as tCucumber::Rails::Database.javascript_strategy overrides +# # this setting. +# DatabaseCleaner.strategy = :truncation +# end +# +# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do +# DatabaseCleaner.strategy = :transaction +# end +# + +# Possible values are :truncation and :transaction +# The :transaction strategy is faster, but might give you threading problems. +# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature +Cucumber::Rails::Database.javascript_strategy = :truncation + diff --git a/features/support/paths.rb b/features/support/paths.rb new file mode 100644 index 0000000..cc4378d --- /dev/null +++ b/features/support/paths.rb @@ -0,0 +1,39 @@ +module NavigationHelpers + # Maps a name to a path. Used by the + # + # When /^I go to (.+)$/ do |page_name| + # + # step definition in web_steps.rb + # + def path_to(page_name) + case page_name + + when /the home\s?page/ + '/' + + when /the sign up page/ + '/users/sign_up' + + when /the sign in page/ + '/users/sign_in' + + # Add more mappings here. + # Here is an example that pulls values out of the Regexp: + # + # when /^(.*)'s profile page$/i + # user_profile_path(User.find_by_login($1)) + + else + begin + page_name =~ /the (.*) page/ + path_components = $1.split(/\s+/) + self.send(path_components.push('path').join('_').to_sym) + rescue Object => e + raise "Can't find mapping from \"#{page_name}\" to a path.\n" + + "Now, go and add a mapping in #{__FILE__}" + end + end + end +end + +World(NavigationHelpers) diff --git a/features/users/sign_in.feature b/features/users/sign_in.feature new file mode 100644 index 0000000..7c9ce76 --- /dev/null +++ b/features/users/sign_in.feature @@ -0,0 +1,34 @@ +Feature: Sign in + In order to get access to protected sections of the site + A user + Should be able to sign in + + Scenario: User is not signed up + Given I do not exist as a user + When I sign in with valid credentials + Then I see an invalid login message + And I should be signed out + + Scenario: User signs in successfully + Given I exist as a user + And I am not logged in + When I sign in with valid credentials + Then I see a successful sign in message + When I return to the site + Then I should be signed in + + Scenario: User enters wrong email + Given I exist as a user + And I am not logged in + When I sign in with a wrong email + Then I see an invalid login message + And I should be signed out + + Scenario: User enters wrong password + Given I exist as a user + And I am not logged in + When I sign in with a wrong password + Then I see an invalid login message + And I should be signed out + + \ No newline at end of file diff --git a/features/users/sign_out.feature b/features/users/sign_out.feature new file mode 100644 index 0000000..9e786d2 --- /dev/null +++ b/features/users/sign_out.feature @@ -0,0 +1,11 @@ +Feature: Sign out + To protect my account from unauthorized access + A signed in user + Should be able to sign out + + Scenario: User signs out + Given I am logged in + When I sign out + Then I should see a signed out message + When I return to the site + Then I should be signed out diff --git a/features/users/sign_up.feature b/features/users/sign_up.feature new file mode 100644 index 0000000..56606c3 --- /dev/null +++ b/features/users/sign_up.feature @@ -0,0 +1,27 @@ +Feature: Sign up + In order to get access to protected sections of the site + As a user + I want to be able to sign up + + Background: + Given I am not logged in + + Scenario: User signs up with valid data + When I sign up with valid user data + Then I should see a successful sign up message + + Scenario: User signs up with invalid email + When I sign up with an invalid email + Then I should see an invalid email message + + Scenario: User signs up without password + When I sign up without a password + Then I should see a missing password message + + Scenario: User signs up without password confirmation + When I sign up without a password confirmation + Then I should see a missing password confirmation message + + Scenario: User signs up with mismatched password and confirmation + When I sign up with a mismatched password confirmation + Then I should see a mismatched password message diff --git a/features/users/user_edit.feature b/features/users/user_edit.feature new file mode 100644 index 0000000..aea37f0 --- /dev/null +++ b/features/users/user_edit.feature @@ -0,0 +1,9 @@ +Feature: Edit User + As a registered user of the website + I want to edit my user profile + so I can change my username + + Scenario: I sign in and edit my account + Given I am logged in + When I edit my account details + Then I should see an account edited message diff --git a/features/users/user_show.feature b/features/users/user_show.feature new file mode 100644 index 0000000..cc02fe7 --- /dev/null +++ b/features/users/user_show.feature @@ -0,0 +1,9 @@ +Feature: Show Users + As a visitor to the website + I want to see registered users listed on the homepage + so I can know if the site has users + + Scenario: Viewing users + Given I exist as a user + When I look at the list of users + Then I should see my name diff --git a/lib/assets/.gitkeep b/lib/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake new file mode 100644 index 0000000..83f7947 --- /dev/null +++ b/lib/tasks/cucumber.rake @@ -0,0 +1,65 @@ +# 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. + + +unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks + +vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first +$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? + +begin + require 'cucumber/rake/task' + + namespace :cucumber do + Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| + t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. + t.fork = true # You may get faster startup if you set this to false + t.profile = 'default' + end + + Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = 'wip' + end + + Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = 'rerun' + end + + desc 'Run all features' + task :all => [:ok, :wip] + + task :statsetup do + require 'rails/code_statistics' + ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') + ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') + end + end + desc 'Alias for cucumber:ok' + task :cucumber => 'cucumber:ok' + + task :default => :cucumber + + task :features => :cucumber do + STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" + end + + # In case we don't have ActiveRecord, append a no-op task that we can depend upon. + task 'db:test:prepare' do + end + + task :stats => 'cucumber:statsetup' +rescue LoadError + desc 'cucumber rake task not available (cucumber not installed)' + task :cucumber do + abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' + end +end + +end diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..9a48320 --- /dev/null +++ b/public/404.html @@ -0,0 +1,26 @@ + + + +You may have mistyped the address or the page may have moved.
+Maybe you tried to change something you didn't have access to.
+