importable_attachments 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +24 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +38 -0
- data/MIT-LICENSE +20 -0
- data/README.md +8 -0
- data/README.rdoc +3 -0
- data/Rakefile +29 -0
- data/app/assets/images/importable_attachments/.gitkeep +0 -0
- data/app/assets/images/importable_attachments/buttons/.htaccess +5 -0
- data/app/assets/images/importable_attachments/buttons/download_32.png +0 -0
- data/app/assets/images/importable_attachments/buttons/upload_32.png +0 -0
- data/app/assets/javascripts/importable_attachments/application.js +14 -0
- data/app/assets/javascripts/importable_attachments/attachments.coffee +41 -0
- data/app/assets/stylesheets/importable_attachments/application.css +14 -0
- data/app/assets/stylesheets/importable_attachments/attachments.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/importable_attachments/application_controller.rb +4 -0
- data/app/controllers/importable_attachments/attachments_controller.rb +190 -0
- data/app/controllers/importable_attachments/versions_controller.rb +87 -0
- data/app/helpers/importable_attachments/application_helper.rb +4 -0
- data/app/models/attachment.rb +24 -0
- data/app/models/importable_attachments/attachment.rb +143 -0
- data/app/models/importable_attachments/version.rb +50 -0
- data/app/validators/existing_class_validator.rb +17 -0
- data/app/validators/importable_attachments/csv_validator.rb +36 -0
- data/app/validators/importable_attachments/excel.rb +18 -0
- data/app/validators/importable_attachments/excel_validator.rb +18 -0
- data/app/views/importable_attachments/attachments/_attachment.html.haml +9 -0
- data/app/views/importable_attachments/attachments/_form.html.haml +22 -0
- data/app/views/importable_attachments/attachments/_nested_form.html.haml +20 -0
- data/app/views/importable_attachments/attachments/edit.html.haml +39 -0
- data/app/views/importable_attachments/attachments/index.html.haml +23 -0
- data/app/views/importable_attachments/attachments/index.xml.builder +23 -0
- data/app/views/importable_attachments/attachments/new.html.haml +10 -0
- data/app/views/importable_attachments/attachments/show.html.haml +43 -0
- data/app/views/importable_attachments/versions/_form.html.haml +25 -0
- data/app/views/importable_attachments/versions/edit.html.haml +7 -0
- data/app/views/importable_attachments/versions/index.html.haml +27 -0
- data/app/views/importable_attachments/versions/new.html.haml +5 -0
- data/app/views/importable_attachments/versions/show.html.haml +21 -0
- data/app/views/layouts/_version.html.haml +33 -0
- data/app/views/layouts/importable_attachments/application.html.haml +48 -0
- data/bin/set_lc.sh +47 -0
- data/config/database.yml +25 -0
- data/config/features/attachments.rb +8 -0
- data/config/features/mark_requirements.rb +3 -0
- data/config/features/smarter_dates.rb +3 -0
- data/config/features/versioning.rb +7 -0
- data/config/initializers/0_configuration.rb +7 -0
- data/config/initializers/formtastic.rb +76 -0
- data/config/initializers/generators.rb +10 -0
- data/config/initializers/paperclip.rb +27 -0
- data/config/locales/responders.en.yml +10 -0
- data/config/routes.rb +11 -0
- data/db/migrate/001_create_importable_attachments_versions.rb +14 -0
- data/db/migrate/100_create_attachments.rb +19 -0
- data/importable_attachments.gemspec +81 -0
- data/lib/generators/importable_attachments/install_generator.rb +66 -0
- data/lib/generators/importable_attachments/templates/features/attachments.rb.erb +7 -0
- data/lib/generators/importable_attachments/templates/features/versioning.rb +7 -0
- data/lib/generators/importable_attachments/templates/initializers/paperclip.rb +27 -0
- data/lib/importable_attachments/base.rb +108 -0
- data/lib/importable_attachments/blueprints.rb +9 -0
- data/lib/importable_attachments/engine.rb +8 -0
- data/lib/importable_attachments/importers/csv.rb +208 -0
- data/lib/importable_attachments/importers/excel.rb +37 -0
- data/lib/importable_attachments/importers.rb +7 -0
- data/lib/importable_attachments/version.rb +3 -0
- data/lib/importable_attachments.rb +9 -0
- data/lib/paperclip_processors/save_upload.rb +33 -0
- data/lib/tasks/importable_attachments_tasks.rake +4 -0
- data/script/rails +8 -0
- data/spec/attachments/books.csv +6 -0
- data/spec/attachments/books.txt +6 -0
- data/spec/attachments/books2.csv +4 -0
- data/spec/attachments/empty.csv +0 -0
- data/spec/attachments/failed_instances.csv +3 -0
- data/spec/attachments/invalid_headers.csv +3 -0
- data/spec/attachments/just_headers.csv +1 -0
- data/spec/attachments/mostly_empty.csv +2 -0
- data/spec/attachments/mostly_empty_copy.xls +0 -0
- data/spec/controllers/importable_attachments/attachments_controller_spec.rb +236 -0
- data/spec/controllers/importable_attachments/versions_controller_spec.rb +158 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/book.rb +13 -0
- data/spec/dummy/app/models/library.rb +54 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/0_configuration.rb +7 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/101_create_libraries.rb +10 -0
- data/spec/dummy/db/migrate/102_create_books.rb +12 -0
- data/spec/dummy/db/schema.rb +57 -0
- data/spec/dummy/features/person_uploads_generic_file.feature +11 -0
- data/spec/dummy/features/step_definitions/person_uploads_generic_file_steps.rb +11 -0
- data/spec/dummy/features/step_definitions/web_steps.rb +211 -0
- data/spec/dummy/features/support/capybara.rb +6 -0
- data/spec/dummy/features/support/database_cleaner.rb +26 -0
- data/spec/dummy/features/support/developer_helpers.rb +47 -0
- data/spec/dummy/features/support/env.rb +53 -0
- data/spec/dummy/features/support/paths.rb +33 -0
- data/spec/dummy/features/support/poltergeist.rb +1 -0
- data/spec/dummy/features/support/selectors.rb +39 -0
- data/spec/dummy/features/support/transactional_fixtures.rb +14 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +38 -0
- data/spec/dummy/public/422.html +38 -0
- data/spec/dummy/public/500.html +36 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/support/.gitkeep +0 -0
- data/spec/dummy/spec/support/paperclip.rb +1 -0
- data/spec/models/importable_attachments/attachment_spec.rb +177 -0
- data/spec/models/importable_attachments/library_spec.rb +155 -0
- data/spec/models/importable_attachments/version_spec.rb +25 -0
- data/spec/routing/importable_attachments/versions_routing_spec.rb +43 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +30 -0
- metadata +737 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Dummy::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
+
|
|
4
|
+
# In the development environment your application's code is reloaded on
|
|
5
|
+
# every request. This slows down response time but is perfect for development
|
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
|
7
|
+
config.cache_classes = false
|
|
8
|
+
|
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
|
10
|
+
config.whiny_nils = true
|
|
11
|
+
|
|
12
|
+
# Show full error reports and disable caching
|
|
13
|
+
config.consider_all_requests_local = true
|
|
14
|
+
config.action_controller.perform_caching = false
|
|
15
|
+
|
|
16
|
+
# Don't care if the mailer can't send
|
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
|
18
|
+
|
|
19
|
+
# Print deprecation notices to the Rails logger
|
|
20
|
+
config.active_support.deprecation = :log
|
|
21
|
+
|
|
22
|
+
# Only use best-standards-support built into browsers
|
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
|
24
|
+
|
|
25
|
+
# Raise exception on mass assignment protection for Active Record models
|
|
26
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
|
27
|
+
|
|
28
|
+
# Log the query plan for queries taking more than this (works
|
|
29
|
+
# with SQLite, MySQL, and PostgreSQL)
|
|
30
|
+
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
|
31
|
+
|
|
32
|
+
# Do not compress assets
|
|
33
|
+
config.assets.compress = false
|
|
34
|
+
|
|
35
|
+
# Expands the lines which load the assets
|
|
36
|
+
config.assets.debug = true
|
|
37
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Dummy::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
+
|
|
4
|
+
# Code is not reloaded between requests
|
|
5
|
+
config.cache_classes = true
|
|
6
|
+
|
|
7
|
+
# Full error reports are disabled and caching is turned on
|
|
8
|
+
config.consider_all_requests_local = false
|
|
9
|
+
config.action_controller.perform_caching = true
|
|
10
|
+
|
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
|
12
|
+
config.serve_static_assets = false
|
|
13
|
+
|
|
14
|
+
# Compress JavaScripts and CSS
|
|
15
|
+
config.assets.compress = true
|
|
16
|
+
|
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
|
18
|
+
config.assets.compile = false
|
|
19
|
+
|
|
20
|
+
# Generate digests for assets URLs
|
|
21
|
+
config.assets.digest = true
|
|
22
|
+
|
|
23
|
+
# Defaults to nil and saved in location specified by config.assets.prefix
|
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
|
25
|
+
|
|
26
|
+
# Specifies the header that your server uses for sending files
|
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
|
29
|
+
|
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
|
31
|
+
# config.force_ssl = true
|
|
32
|
+
|
|
33
|
+
# See everything in the log (default is :info)
|
|
34
|
+
# config.log_level = :debug
|
|
35
|
+
|
|
36
|
+
# Prepend all log lines with the following tags
|
|
37
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
|
38
|
+
|
|
39
|
+
# Use a different logger for distributed setups
|
|
40
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
|
41
|
+
|
|
42
|
+
# Use a different cache store in production
|
|
43
|
+
# config.cache_store = :mem_cache_store
|
|
44
|
+
|
|
45
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
|
46
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
|
47
|
+
|
|
48
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
|
49
|
+
# config.assets.precompile += %w( search.js )
|
|
50
|
+
|
|
51
|
+
# Disable delivery errors, bad email addresses will be ignored
|
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
|
53
|
+
|
|
54
|
+
# Enable threaded mode
|
|
55
|
+
# config.threadsafe!
|
|
56
|
+
|
|
57
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
|
58
|
+
# the I18n.default_locale when a translation can not be found)
|
|
59
|
+
config.i18n.fallbacks = true
|
|
60
|
+
|
|
61
|
+
# Send deprecation notices to registered listeners
|
|
62
|
+
config.active_support.deprecation = :notify
|
|
63
|
+
|
|
64
|
+
# Log the query plan for queries taking more than this (works
|
|
65
|
+
# with SQLite, MySQL, and PostgreSQL)
|
|
66
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
|
67
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Dummy::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
|
3
|
+
|
|
4
|
+
# The test environment is used exclusively to run your application's
|
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
|
8
|
+
config.cache_classes = true
|
|
9
|
+
|
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
|
11
|
+
config.serve_static_assets = true
|
|
12
|
+
config.static_cache_control = 'public, max-age=3600'
|
|
13
|
+
|
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
|
15
|
+
config.whiny_nils = true
|
|
16
|
+
|
|
17
|
+
# Show full error reports and disable caching
|
|
18
|
+
config.consider_all_requests_local = true
|
|
19
|
+
config.action_controller.perform_caching = false
|
|
20
|
+
|
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
|
22
|
+
config.action_dispatch.show_exceptions = false
|
|
23
|
+
|
|
24
|
+
# Disable request forgery protection in test environment
|
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
|
26
|
+
|
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
|
29
|
+
# ActionMailer::Base.deliveries array.
|
|
30
|
+
config.action_mailer.delivery_method = :test
|
|
31
|
+
|
|
32
|
+
# Raise exception on mass assignment protection for Active Record models
|
|
33
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
|
34
|
+
|
|
35
|
+
# Print deprecation notices to the stderr
|
|
36
|
+
config.active_support.deprecation = :stderr
|
|
37
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
|
5
|
+
|
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Add new inflection rules using the following format
|
|
4
|
+
# (all these examples are active by default):
|
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
|
8
|
+
# inflect.irregular 'person', 'people'
|
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
|
10
|
+
# end
|
|
11
|
+
#
|
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
|
14
|
+
# inflect.acronym 'RESTful'
|
|
15
|
+
# end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
|
7
|
+
Dummy::Application.config.secret_token = 'a00dbc3165d8755822c7ee14c79866117462eaacbdd96259c68c52d5db18fe60e333ddf6eb8a865a253e7b94b6411afa967730d2f988a438279a9c50f66291ee'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
|
4
|
+
|
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
|
6
|
+
# which shouldn't be used to store highly confidential information
|
|
7
|
+
# (create the session table with "rails generate session_migration")
|
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
#
|
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
|
4
|
+
# is enabled by default.
|
|
5
|
+
|
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
|
8
|
+
wrap_parameters format: [:json]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Disable root element in JSON by default.
|
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
|
13
|
+
self.include_root_in_json = false
|
|
14
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
|
5
|
+
#
|
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
|
7
|
+
# database schema. If you need to create the application database on another
|
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
11
|
+
#
|
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
|
13
|
+
|
|
14
|
+
ActiveRecord::Schema.define(:version => 102) do
|
|
15
|
+
|
|
16
|
+
create_table "books", :force => true do |t|
|
|
17
|
+
t.string "title"
|
|
18
|
+
t.string "author"
|
|
19
|
+
t.datetime "last_checkout_at"
|
|
20
|
+
t.integer "library_id", :null => false
|
|
21
|
+
t.datetime "created_at", :null => false
|
|
22
|
+
t.datetime "updated_at", :null => false
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
create_table "importable_attachments_attachments", :force => true do |t|
|
|
26
|
+
t.string "attachable_type"
|
|
27
|
+
t.string "attachable_id"
|
|
28
|
+
t.string "io_stream_file_name"
|
|
29
|
+
t.string "io_stream_content_type"
|
|
30
|
+
t.integer "io_stream_file_size", :limit => 8
|
|
31
|
+
t.datetime "io_stream_updated_at"
|
|
32
|
+
t.datetime "created_at", :null => false
|
|
33
|
+
t.datetime "updated_at", :null => false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
add_index "importable_attachments_attachments", ["attachable_type", "attachable_id"], :name => "idx_importable_attachments_on_attachable_type_and_id"
|
|
37
|
+
add_index "importable_attachments_attachments", ["io_stream_file_name"], :name => "index_importable_attachments_attachments_on_io_stream_file_name"
|
|
38
|
+
|
|
39
|
+
create_table "importable_attachments_versions", :force => true do |t|
|
|
40
|
+
t.string "item_type", :null => false
|
|
41
|
+
t.string "item_id", :null => false
|
|
42
|
+
t.string "event", :null => false
|
|
43
|
+
t.string "whodunnit"
|
|
44
|
+
t.text "object"
|
|
45
|
+
t.datetime "created_at"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
add_index "importable_attachments_versions", ["item_type", "item_id"], :name => "index_importable_attachments_versions_on_item_type_and_item_id"
|
|
49
|
+
|
|
50
|
+
create_table "libraries", :force => true do |t|
|
|
51
|
+
t.string "name"
|
|
52
|
+
t.string "address"
|
|
53
|
+
t.datetime "created_at", :null => false
|
|
54
|
+
t.datetime "updated_at", :null => false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Feature: administrator uploads generic file
|
|
2
|
+
As an administrator
|
|
3
|
+
I want to upload a generic file
|
|
4
|
+
So that I can confirm the uploading machina is working
|
|
5
|
+
|
|
6
|
+
@javascript
|
|
7
|
+
Scenario: upload file
|
|
8
|
+
Given I am on the new attachment page
|
|
9
|
+
And I upload the spec file "mostly_empty.csv" as "attachment_io_stream"
|
|
10
|
+
Then I should see "Successfully created attachment."
|
|
11
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Given /^(?:|I *) upload the spec file "([^"]*)" as "([^"]*)"$/ do |path, field|
|
|
2
|
+
icon = page.find('#icon_file_upload')
|
|
3
|
+
icon.click
|
|
4
|
+
path = Rails.root.join('spec', 'attachments', path)
|
|
5
|
+
attach_file(field, File.expand_path(path))
|
|
6
|
+
if page.driver.respond_to? :console_messages
|
|
7
|
+
error_msgs = page.driver.console_messages
|
|
8
|
+
Rails.logger.info error_msgs.inspect
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# TL;DR: YOU SHOULD DELETE THIS FILE
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Cucumber-Rails and is only here to get you a head start
|
|
4
|
+
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
|
|
5
|
+
# visit pages, interact with widgets and make assertions about page content.
|
|
6
|
+
#
|
|
7
|
+
# If you use these step definitions as basis for your features you will quickly end up
|
|
8
|
+
# with features that are:
|
|
9
|
+
#
|
|
10
|
+
# * Hard to maintain
|
|
11
|
+
# * Verbose to read
|
|
12
|
+
#
|
|
13
|
+
# A much better approach is to write your own higher level step definitions, following
|
|
14
|
+
# the advice in the following blog posts:
|
|
15
|
+
#
|
|
16
|
+
# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
|
|
17
|
+
# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
|
|
18
|
+
# * http://elabs.se/blog/15-you-re-cuking-it-wrong
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
require 'uri'
|
|
23
|
+
require 'cgi'
|
|
24
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
|
25
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
|
|
26
|
+
|
|
27
|
+
module WithinHelpers
|
|
28
|
+
def with_scope(locator)
|
|
29
|
+
locator ? within(*selector_for(locator)) { yield } : yield
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
World(WithinHelpers)
|
|
33
|
+
|
|
34
|
+
# Single-line step scoper
|
|
35
|
+
When /^(.*) within (.*[^:])$/ do |step, parent|
|
|
36
|
+
with_scope(parent) { When step }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Multi-line step scoper
|
|
40
|
+
When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
|
|
41
|
+
with_scope(parent) { When "#{step}:", table_or_string }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Given /^(?:|I )am on (.+)$/ do |page_name|
|
|
45
|
+
visit path_to(page_name)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
When /^(?:|I )go to (.+)$/ do |page_name|
|
|
49
|
+
visit path_to(page_name)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
When /^(?:|I )press "([^"]*)"$/ do |button|
|
|
53
|
+
click_button(button)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
When /^(?:|I )follow "([^"]*)"$/ do |link|
|
|
57
|
+
click_link(link)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
|
61
|
+
fill_in(field, :with => value)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
|
|
65
|
+
fill_in(field, :with => value)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Use this to fill in an entire form with data from a table. Example:
|
|
69
|
+
#
|
|
70
|
+
# When I fill in the following:
|
|
71
|
+
# | Account Number | 5002 |
|
|
72
|
+
# | Expiry date | 2009-11-01 |
|
|
73
|
+
# | Note | Nice guy |
|
|
74
|
+
# | Wants Email? | |
|
|
75
|
+
#
|
|
76
|
+
# TODO: Add support for checkbox, select og option
|
|
77
|
+
# based on naming conventions.
|
|
78
|
+
#
|
|
79
|
+
When /^(?:|I )fill in the following:$/ do |fields|
|
|
80
|
+
fields.rows_hash.each do |name, value|
|
|
81
|
+
When %{I fill in "#{name}" with "#{value}"}
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
|
86
|
+
select(value, :from => field)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
When /^(?:|I )check "([^"]*)"$/ do |field|
|
|
90
|
+
check(field)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
|
94
|
+
uncheck(field)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
|
98
|
+
choose(field)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
|
102
|
+
attach_file(field, File.expand_path(path))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
|
106
|
+
if page.respond_to? :should
|
|
107
|
+
page.should have_content(text)
|
|
108
|
+
else
|
|
109
|
+
assert page.has_content?(text)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
|
114
|
+
regexp = Regexp.new(regexp)
|
|
115
|
+
|
|
116
|
+
if page.respond_to? :should
|
|
117
|
+
page.should have_xpath('//*', :text => regexp)
|
|
118
|
+
else
|
|
119
|
+
assert page.has_xpath?('//*', :text => regexp)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
|
124
|
+
if page.respond_to? :should
|
|
125
|
+
page.should have_no_content(text)
|
|
126
|
+
else
|
|
127
|
+
assert page.has_no_content?(text)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
|
132
|
+
regexp = Regexp.new(regexp)
|
|
133
|
+
|
|
134
|
+
if page.respond_to? :should
|
|
135
|
+
page.should have_no_xpath('//*', :text => regexp)
|
|
136
|
+
else
|
|
137
|
+
assert page.has_no_xpath?('//*', :text => regexp)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
|
142
|
+
with_scope(parent) do
|
|
143
|
+
field = find_field(field)
|
|
144
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
|
145
|
+
if field_value.respond_to? :should
|
|
146
|
+
field_value.should =~ /#{value}/
|
|
147
|
+
else
|
|
148
|
+
assert_match(/#{value}/, field_value)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
|
154
|
+
with_scope(parent) do
|
|
155
|
+
field = find_field(field)
|
|
156
|
+
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
|
157
|
+
if field_value.respond_to? :should_not
|
|
158
|
+
field_value.should_not =~ /#{value}/
|
|
159
|
+
else
|
|
160
|
+
assert_no_match(/#{value}/, field_value)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
|
166
|
+
with_scope(parent) do
|
|
167
|
+
field_checked = find_field(label)['checked']
|
|
168
|
+
if field_checked.respond_to? :should
|
|
169
|
+
field_checked.should be_true
|
|
170
|
+
else
|
|
171
|
+
assert field_checked
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
|
177
|
+
with_scope(parent) do
|
|
178
|
+
field_checked = find_field(label)['checked']
|
|
179
|
+
if field_checked.respond_to? :should
|
|
180
|
+
field_checked.should be_false
|
|
181
|
+
else
|
|
182
|
+
assert !field_checked
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
|
188
|
+
current_path = URI.parse(current_url).path
|
|
189
|
+
if current_path.respond_to? :should
|
|
190
|
+
current_path.should == path_to(page_name)
|
|
191
|
+
else
|
|
192
|
+
assert_equal path_to(page_name), current_path
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
|
197
|
+
query = URI.parse(current_url).query
|
|
198
|
+
actual_params = query ? CGI.parse(query) : {}
|
|
199
|
+
expected_params = {}
|
|
200
|
+
expected_pairs.rows_hash.each_pair { |k, v| expected_params[k] = v.split(',') }
|
|
201
|
+
|
|
202
|
+
if actual_params.respond_to? :should
|
|
203
|
+
actual_params.should == expected_params
|
|
204
|
+
else
|
|
205
|
+
assert_equal expected_params, actual_params
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
Then /^show me the page$/ do
|
|
210
|
+
save_and_open_page
|
|
211
|
+
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
|
2
|
+
# order to ease the transition to Capybara we set the default here. If you'd
|
|
3
|
+
# prefer to use XPath just remove this line and adjust any selectors in your
|
|
4
|
+
# steps to use the XPath syntax.
|
|
5
|
+
Capybara.default_selector = :css
|
|
6
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
DatabaseCleaner.clean_with(:truncation)
|
|
2
|
+
|
|
3
|
+
# Remove/comment out the lines below if your app doesn't have a database.
|
|
4
|
+
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
|
|
5
|
+
begin
|
|
6
|
+
DatabaseCleaner.strategy = :transaction
|
|
7
|
+
rescue NameError
|
|
8
|
+
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
Before('@no-txn,@selenium,@culerity,@celerity') do
|
|
12
|
+
DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Before('@webkit,@javascript,@js') do
|
|
16
|
+
DatabaseCleaner.strategy = :transaction
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
After('@webkit,@javascript,@js') do
|
|
20
|
+
DatabaseCleaner.clean_with(:truncation)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Before('~@no-txn', '~@selenium', '~@webkit', '~@culerity', '~@celerity', '~@javascript', '~@js') do
|
|
24
|
+
DatabaseCleaner.strategy = :transaction
|
|
25
|
+
end
|
|
26
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module DeveloperHelpers
|
|
2
|
+
# :call-seq:
|
|
3
|
+
# pretty_response_body
|
|
4
|
+
#
|
|
5
|
+
# displays the response body on multiple, indexed, lines
|
|
6
|
+
|
|
7
|
+
def pretty_response_body
|
|
8
|
+
pretty_body = response.body.split(/\n/)
|
|
9
|
+
pretty_body.each_with_index { |line, idx| line.gsub("\t", " ").gsub!(/^/, "#{idx+1}: ") }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# :call-seq:
|
|
13
|
+
# pretty_page_html
|
|
14
|
+
#
|
|
15
|
+
# displays the response body on multiple, indexed, lines
|
|
16
|
+
|
|
17
|
+
def pretty_page_html
|
|
18
|
+
page.html.split(/\n/).each { |line, idx| line.gsub("\t", " ") }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# :call-seq:
|
|
22
|
+
# safe_attributes :object
|
|
23
|
+
#
|
|
24
|
+
# yields an array of accessible attributes...
|
|
25
|
+
# ... without *_ids relations
|
|
26
|
+
# ... with foo_id AND without foo
|
|
27
|
+
|
|
28
|
+
def safe_attrs(obj)
|
|
29
|
+
accessible_attrs = obj._accessible_attributes[:default].to_a
|
|
30
|
+
relation_attrs = accessible_attrs.select { |obj| obj.match(/_(?:ids|attributes)$/) }
|
|
31
|
+
accessible_attrs -= relation_attrs
|
|
32
|
+
id_attrs = accessible_attrs.select { |obj| obj.match(/_id$/) }
|
|
33
|
+
accessible_attrs -= id_attrs.map { |obj| obj.sub(/_id$/, "") }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# :call-seq:
|
|
37
|
+
# post_safe_attrs :object
|
|
38
|
+
#
|
|
39
|
+
# yields the object-as-a-hash of accessible keys => values
|
|
40
|
+
|
|
41
|
+
def post_safe_attrs(obj)
|
|
42
|
+
safe_attrs(serialized_obj).inject({}) { |res, obj|
|
|
43
|
+
val = serialized_obj.send(obj); val.is_a?(Array) ? res : res.merge({obj => val}) }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
World(DeveloperHelpers)
|
|
47
|
+
|