diff --git a/Gemfile b/Gemfile index 59cffb6..7e5a115 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,9 @@ source 'https://rubygems.org' gemspec +gem 'rails', '>= 7.2' +gem 'sqlite3' +gem 'rake', '>= 13' gem 'jquery-rails' gem 'simple_form' +gem 'sprockets-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 83e4539..6e3dce0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,172 +2,254 @@ PATH remote: . specs: actionform (1.0) - rails (>= 6) GEM remote: https://rubygems.org/ specs: - actioncable (6.1.4.7) - actionpack (= 6.1.4.7) - activesupport (= 6.1.4.7) + action_text-trix (2.1.16) + railties + actioncable (8.1.2) + actionpack (= 8.1.2) + activesupport (= 8.1.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.4.7) - actionpack (= 6.1.4.7) - activejob (= 6.1.4.7) - activerecord (= 6.1.4.7) - activestorage (= 6.1.4.7) - activesupport (= 6.1.4.7) - mail (>= 2.7.1) - actionmailer (6.1.4.7) - actionpack (= 6.1.4.7) - actionview (= 6.1.4.7) - activejob (= 6.1.4.7) - activesupport (= 6.1.4.7) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.4.7) - actionview (= 6.1.4.7) - activesupport (= 6.1.4.7) - rack (~> 2.0, >= 2.0.9) + zeitwerk (~> 2.6) + actionmailbox (8.1.2) + actionpack (= 8.1.2) + activejob (= 8.1.2) + activerecord (= 8.1.2) + activestorage (= 8.1.2) + activesupport (= 8.1.2) + mail (>= 2.8.0) + actionmailer (8.1.2) + actionpack (= 8.1.2) + actionview (= 8.1.2) + activejob (= 8.1.2) + activesupport (= 8.1.2) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.1.2) + actionview (= 8.1.2) + activesupport (= 8.1.2) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.4.7) - actionpack (= 6.1.4.7) - activerecord (= 6.1.4.7) - activestorage (= 6.1.4.7) - activesupport (= 6.1.4.7) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.1.2) + action_text-trix (~> 2.1.15) + actionpack (= 8.1.2) + activerecord (= 8.1.2) + activestorage (= 8.1.2) + activesupport (= 8.1.2) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.4.7) - activesupport (= 6.1.4.7) + actionview (8.1.2) + activesupport (= 8.1.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.4.7) - activesupport (= 6.1.4.7) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.1.2) + activesupport (= 8.1.2) globalid (>= 0.3.6) - activemodel (6.1.4.7) - activesupport (= 6.1.4.7) - activerecord (6.1.4.7) - activemodel (= 6.1.4.7) - activesupport (= 6.1.4.7) - activestorage (6.1.4.7) - actionpack (= 6.1.4.7) - activejob (= 6.1.4.7) - activerecord (= 6.1.4.7) - activesupport (= 6.1.4.7) - marcel (~> 1.0.0) - mini_mime (>= 1.1.0) - activesupport (6.1.4.7) - concurrent-ruby (~> 1.0, >= 1.0.2) + activemodel (8.1.2) + activesupport (= 8.1.2) + activerecord (8.1.2) + activemodel (= 8.1.2) + activesupport (= 8.1.2) + timeout (>= 0.4.0) + activestorage (8.1.2) + actionpack (= 8.1.2) + activejob (= 8.1.2) + activerecord (= 8.1.2) + activesupport (= 8.1.2) + marcel (~> 1.0) + activesupport (8.1.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) + json + logger (>= 1.4.2) minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - builder (3.2.4) - concurrent-ruby (1.2.2) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + base64 (0.3.0) + bigdecimal (4.0.1) + builder (3.3.0) + concurrent-ruby (1.3.6) + connection_pool (3.0.2) crass (1.0.6) - date (3.3.3) - erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) - i18n (1.14.1) + date (3.5.1) + drb (2.2.3) + erb (6.0.1) + erubi (1.13.1) + globalid (1.3.0) + activesupport (>= 6.1) + i18n (1.14.8) concurrent-ruby (~> 1.0) - jquery-rails (4.6.0) + io-console (0.8.2) + irb (1.17.0) + pp (>= 0.6.0) + prism (>= 1.3.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jquery-rails (4.6.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - loofah (2.21.3) + json (2.18.1) + logger (1.7.0) + loofah (2.25.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) - mail (2.8.1) + mail (2.9.0) + logger mini_mime (>= 0.1.1) net-imap net-pop net-smtp - marcel (1.0.2) - method_source (1.0.0) + marcel (1.1.0) mini_mime (1.1.5) - mini_portile2 (2.8.4) - minitest (5.19.0) - net-imap (0.3.7) + minitest (6.0.1) + prism (~> 1.5) + net-imap (0.6.2) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.5.1) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4) - mini_portile2 (~> 2.8.2) + nio4r (2.7.5) + nokogiri (1.19.0-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.0-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.19.0-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.0-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.19.0-arm64-darwin) racc (~> 1.4) - racc (1.7.1) - rack (2.2.8) - rack-test (2.1.0) + nokogiri (1.19.0-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.19.0-x86_64-linux-musl) + racc (~> 1.4) + pp (0.6.3) + prettyprint + prettyprint (0.2.0) + prism (1.9.0) + psych (5.3.1) + date + stringio + racc (1.8.1) + rack (3.2.4) + rack-session (2.1.1) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) rack (>= 1.3) - rails (6.1.4.7) - actioncable (= 6.1.4.7) - actionmailbox (= 6.1.4.7) - actionmailer (= 6.1.4.7) - actionpack (= 6.1.4.7) - actiontext (= 6.1.4.7) - actionview (= 6.1.4.7) - activejob (= 6.1.4.7) - activemodel (= 6.1.4.7) - activerecord (= 6.1.4.7) - activestorage (= 6.1.4.7) - activesupport (= 6.1.4.7) + rackup (2.3.1) + rack (>= 3) + rails (8.1.2) + actioncable (= 8.1.2) + actionmailbox (= 8.1.2) + actionmailer (= 8.1.2) + actionpack (= 8.1.2) + actiontext (= 8.1.2) + actionview (= 8.1.2) + activejob (= 8.1.2) + activemodel (= 8.1.2) + activerecord (= 8.1.2) + activestorage (= 8.1.2) + activesupport (= 8.1.2) bundler (>= 1.15.0) - railties (= 6.1.4.7) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.2.0) + railties (= 8.1.2) + rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) - nokogiri (~> 1.14) - railties (6.1.4.7) - actionpack (= 6.1.4.7) - activesupport (= 6.1.4.7) - method_source - rake (>= 0.13) - thor (~> 1.0) - rake (13.0.6) - simple_form (5.2.0) - actionpack (>= 5.2) - activemodel (>= 5.2) - sprockets (4.2.0) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.1.2) + actionpack (= 8.1.2) + activesupport (= 8.1.2) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) + rake (13.3.1) + rdoc (7.2.0) + erb + psych (>= 4.0.0) + tsort + reline (0.6.3) + io-console (~> 0.5) + securerandom (0.4.1) + simple_form (5.4.1) + actionpack (>= 7.0) + activemodel (>= 7.0) + sprockets (4.2.2) concurrent-ruby (~> 1.0) + logger rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - sqlite3 (1.6.3) - mini_portile2 (~> 2.8.0) - thor (1.2.2) - timeout (0.4.0) + sqlite3 (2.9.0-aarch64-linux-gnu) + sqlite3 (2.9.0-aarch64-linux-musl) + sqlite3 (2.9.0-arm-linux-gnu) + sqlite3 (2.9.0-arm-linux-musl) + sqlite3 (2.9.0-arm64-darwin) + sqlite3 (2.9.0-x86_64-darwin) + sqlite3 (2.9.0-x86_64-linux-gnu) + sqlite3 (2.9.0-x86_64-linux-musl) + stringio (3.2.0) + thor (1.5.0) + timeout (0.6.0) + tsort (0.2.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - websocket-driver (0.7.6) + uri (1.1.1) + useragent (0.16.11) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.11) + zeitwerk (2.7.4) PLATFORMS - ruby + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES actionform! jquery-rails + rails (>= 7.2) rake (>= 13) simple_form + sprockets-rails sqlite3 BUNDLED WITH - 2.3.15 + 2.6.9 diff --git a/actionform.gemspec b/actionform.gemspec index 12d0848..cdfbdb1 100644 --- a/actionform.gemspec +++ b/actionform.gemspec @@ -13,10 +13,4 @@ Gem::Specification.new do |s| s.license = 'MIT' s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md'] - s.test_files = Dir['test/**/*'] - - s.add_dependency 'rails', '>= 6' - - s.add_development_dependency 'sqlite3' - s.add_development_dependency 'rake', '>= 13' end diff --git a/lib/action_form/form_collection.rb b/lib/action_form/form_collection.rb index 8902010..97ac622 100644 --- a/lib/action_form/form_collection.rb +++ b/lib/action_form/form_collection.rb @@ -19,6 +19,7 @@ def update_models end def submit(params) + params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h) params.each do |key, value| if parent.persisted? create_or_update_record(value) diff --git a/lib/action_form/form_helpers.rb b/lib/action_form/form_helpers.rb index 673229b..9cf0d2b 100644 --- a/lib/action_form/form_helpers.rb +++ b/lib/action_form/form_helpers.rb @@ -3,6 +3,7 @@ module FormHelpers ATTRIBUTES_KEY_REGEXP = /^(.+)_attributes$/ def submit(params) + params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h) params.each do |key, value| if nested_params?(key) fill_association_with_attributes(key, value) diff --git a/lib/action_form/version.rb b/lib/action_form/version.rb index aaec9f6..0b5363a 100644 --- a/lib/action_form/version.rb +++ b/lib/action_form/version.rb @@ -1,3 +1,3 @@ module ActionForm - VERSION = '1.0' + VERSION = '1.1' end diff --git a/lib/action_form/view_helpers.rb b/lib/action_form/view_helpers.rb index 974adf3..29604df 100644 --- a/lib/action_form/view_helpers.rb +++ b/lib/action_form/view_helpers.rb @@ -45,7 +45,7 @@ def link_to_add_association(name, f, association, html_options={}) new_object = create_object(f, association) - html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, override_partial).to_str).html_safe + html_options[:'data-association-insertion-template'] = ERB::Util.html_escape(render_association(association, f, new_object, render_options, override_partial).to_str).html_safe link_to(name, '#', html_options) end diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index ddf0e90..1691aa7 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -4,7 +4,7 @@ # 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 + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -27,10 +27,6 @@ # number of complex assets. config.assets.debug = true - # Adds additional error checking when serving assets at runtime. - # Checks for improperly declared sprockets dependencies. - # Raises helpful error messages. - config.assets.raise_runtime_errors = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index a8836c3..5f05bf3 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -2,7 +2,7 @@ # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers @@ -20,10 +20,9 @@ # config.action_dispatch.rack_cache = true # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_assets = false + config.public_file_server.enabled = false # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 82ca386..0b848cf 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -5,7 +5,7 @@ # 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 = false + config.enable_reloading = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that @@ -13,15 +13,15 @@ config.eager_load = false # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true - config.static_cache_control = 'public, max-age=3600' + config.public_file_server.enabled = true + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # 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 + config.action_dispatch.show_exceptions = :none # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false diff --git a/test/dummy/config/initializers/simple_form.rb b/test/dummy/config/initializers/simple_form.rb index 4937a4d..df9ece3 100644 --- a/test/dummy/config/initializers/simple_form.rb +++ b/test/dummy/config/initializers/simple_form.rb @@ -78,7 +78,7 @@ # config.collection_value_methods = [ :id, :to_s ] # How the label text should be generated altogether with the required text. - config.label_text = lambda { |label, required| "#{label} #{required}" } + config.label_text = lambda { |label, required, _explicit_label| "#{label} #{required}" } # You can define the class to use on all labels. Default is nil. # config.label_class = nil diff --git a/test/dummy/db/migrate/20140729162110_create_tables.rb b/test/dummy/db/migrate/20140729162110_create_tables.rb new file mode 100644 index 0000000..07063b5 --- /dev/null +++ b/test/dummy/db/migrate/20140729162110_create_tables.rb @@ -0,0 +1,128 @@ +class CreateTables < ActiveRecord::Migration[7.2] + def change + create_table :users do |t| + t.string :name + t.integer :age + t.integer :gender + t.timestamps null: false + end + + create_table :emails do |t| + t.string :address + t.references :user, index: true + t.timestamps null: false + end + + create_table :profiles do |t| + t.string :twitter_name + t.string :github_name + t.references :user, index: true + t.timestamps null: false + end + + create_table :songs do |t| + t.string :title + t.string :length + t.timestamps null: false + end + + create_table :artists do |t| + t.string :name + t.references :song, index: true + t.timestamps null: false + end + + create_table :producers do |t| + t.string :name + t.string :studio + t.references :artist, index: true + t.timestamps null: false + end + + create_table :conferences do |t| + t.string :name + t.string :city + t.timestamps null: false + end + + create_table :speakers do |t| + t.string :name + t.string :occupation + t.references :conference, index: true + t.timestamps null: false + end + + create_table :presentations do |t| + t.string :topic + t.string :duration + t.references :speaker, index: true + t.timestamps null: false + end + + create_table :surveys do |t| + t.string :name + t.timestamps null: false + end + + create_table :questions do |t| + t.text :content + t.references :survey, index: true + t.timestamps null: false + end + + create_table :answers do |t| + t.text :content + t.references :question, index: true + t.timestamps null: false + end + + create_table :projects do |t| + t.string :name + t.string :description + t.integer :owner_id + t.timestamps null: false + end + + create_table :tasks do |t| + t.string :name + t.string :description + t.boolean :done + t.references :project, index: true + t.timestamps null: false + end + + create_table :sub_tasks do |t| + t.string :name + t.string :description + t.boolean :done + t.references :task, index: true + t.timestamps null: false + end + + create_table :people do |t| + t.string :name + t.string :description + t.string :role + t.references :project, index: true + t.timestamps null: false + end + + create_table :tags do |t| + t.string :name + t.timestamps null: false + end + + create_table :project_tags do |t| + t.references :project, index: true + t.references :tag, index: true + t.timestamps null: false + end + + create_table :assignments do |t| + t.string :name + t.timestamps null: false + end + + add_reference :tasks, :assignment, index: true + end +end diff --git a/test/dummy/db/migrate/20140729162110_create_users.rb b/test/dummy/db/migrate/20140729162110_create_users.rb deleted file mode 100644 index e476742..0000000 --- a/test/dummy/db/migrate/20140729162110_create_users.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateUsers < ActiveRecord::Migration[6.1] - def change - create_table :users do |t| - t.string :name - t.integer :age - t.integer :gender - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729162246_create_emails.rb b/test/dummy/db/migrate/20140729162246_create_emails.rb deleted file mode 100644 index a27fe2e..0000000 --- a/test/dummy/db/migrate/20140729162246_create_emails.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateEmails < ActiveRecord::Migration[6.1] - def change - create_table :emails do |t| - t.string :address - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729162335_create_profiles.rb b/test/dummy/db/migrate/20140729162335_create_profiles.rb deleted file mode 100644 index f0da6c4..0000000 --- a/test/dummy/db/migrate/20140729162335_create_profiles.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateProfiles < ActiveRecord::Migration[6.1] - def change - create_table :profiles do |t| - t.string :twitter_name - t.string :github_name - t.references :user, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729164623_create_songs.rb b/test/dummy/db/migrate/20140729164623_create_songs.rb deleted file mode 100644 index 98b08db..0000000 --- a/test/dummy/db/migrate/20140729164623_create_songs.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateSongs < ActiveRecord::Migration[6.1] - def change - create_table :songs do |t| - t.string :title - t.string :length - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729164653_create_artists.rb b/test/dummy/db/migrate/20140729164653_create_artists.rb deleted file mode 100644 index c7dd673..0000000 --- a/test/dummy/db/migrate/20140729164653_create_artists.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateArtists < ActiveRecord::Migration[6.1] - def change - create_table :artists do |t| - t.string :name - t.references :song, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729164713_create_producers.rb b/test/dummy/db/migrate/20140729164713_create_producers.rb deleted file mode 100644 index f219695..0000000 --- a/test/dummy/db/migrate/20140729164713_create_producers.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateProducers < ActiveRecord::Migration[6.1] - def change - create_table :producers do |t| - t.string :name - t.string :studio - t.references :artist, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729165425_create_conferences.rb b/test/dummy/db/migrate/20140729165425_create_conferences.rb deleted file mode 100644 index d1e89a3..0000000 --- a/test/dummy/db/migrate/20140729165425_create_conferences.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateConferences < ActiveRecord::Migration[6.1] - def change - create_table :conferences do |t| - t.string :name - t.string :city - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729165445_create_speakers.rb b/test/dummy/db/migrate/20140729165445_create_speakers.rb deleted file mode 100644 index a47a999..0000000 --- a/test/dummy/db/migrate/20140729165445_create_speakers.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateSpeakers < ActiveRecord::Migration[6.1] - def change - create_table :speakers do |t| - t.string :name - t.string :occupation - t.references :conference, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729165506_create_presentations.rb b/test/dummy/db/migrate/20140729165506_create_presentations.rb deleted file mode 100644 index 197d8e9..0000000 --- a/test/dummy/db/migrate/20140729165506_create_presentations.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreatePresentations < ActiveRecord::Migration[6.1] - def change - create_table :presentations do |t| - t.string :topic - t.string :duration - t.references :speaker, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729170014_create_surveys.rb b/test/dummy/db/migrate/20140729170014_create_surveys.rb deleted file mode 100644 index db23fa8..0000000 --- a/test/dummy/db/migrate/20140729170014_create_surveys.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSurveys < ActiveRecord::Migration[6.1] - def change - create_table :surveys do |t| - t.string :name - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729170034_create_questions.rb b/test/dummy/db/migrate/20140729170034_create_questions.rb deleted file mode 100644 index a2ddceb..0000000 --- a/test/dummy/db/migrate/20140729170034_create_questions.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateQuestions < ActiveRecord::Migration[6.1] - def change - create_table :questions do |t| - t.text :content - t.references :survey, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140729170112_create_answers.rb b/test/dummy/db/migrate/20140729170112_create_answers.rb deleted file mode 100644 index 882c243..0000000 --- a/test/dummy/db/migrate/20140729170112_create_answers.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateAnswers < ActiveRecord::Migration[6.1] - def change - create_table :answers do |t| - t.text :content - t.references :question, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140806122636_create_projects.rb b/test/dummy/db/migrate/20140806122636_create_projects.rb deleted file mode 100644 index 56d6e67..0000000 --- a/test/dummy/db/migrate/20140806122636_create_projects.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateProjects < ActiveRecord::Migration[6.1] - def change - create_table :projects do |t| - t.string :name - t.string :description - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140806122735_create_tasks.rb b/test/dummy/db/migrate/20140806122735_create_tasks.rb deleted file mode 100644 index ebbe712..0000000 --- a/test/dummy/db/migrate/20140806122735_create_tasks.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateTasks < ActiveRecord::Migration[6.1] - def change - create_table :tasks do |t| - t.string :name - t.string :description - t.boolean :done - t.references :project, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140806122805_create_sub_tasks.rb b/test/dummy/db/migrate/20140806122805_create_sub_tasks.rb deleted file mode 100644 index d430a53..0000000 --- a/test/dummy/db/migrate/20140806122805_create_sub_tasks.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateSubTasks < ActiveRecord::Migration[6.1] - def change - create_table :sub_tasks do |t| - t.string :name - t.string :description - t.boolean :done - t.references :task, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140806122834_create_people.rb b/test/dummy/db/migrate/20140806122834_create_people.rb deleted file mode 100644 index b4a884a..0000000 --- a/test/dummy/db/migrate/20140806122834_create_people.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreatePeople < ActiveRecord::Migration[6.1] - def change - create_table :people do |t| - t.string :name - t.string :role - t.string :description - t.references :project, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140806122911_add_owner_to_projects.rb b/test/dummy/db/migrate/20140806122911_add_owner_to_projects.rb deleted file mode 100644 index efa3bd9..0000000 --- a/test/dummy/db/migrate/20140806122911_add_owner_to_projects.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddOwnerToProjects < ActiveRecord::Migration[6.1] - def change - add_column :projects, :owner_id, :integer - end -end diff --git a/test/dummy/db/migrate/20140806122945_create_tags.rb b/test/dummy/db/migrate/20140806122945_create_tags.rb deleted file mode 100644 index b5e41f6..0000000 --- a/test/dummy/db/migrate/20140806122945_create_tags.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateTags < ActiveRecord::Migration[6.1] - def change - create_table :tags do |t| - t.string :name - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140806123008_create_project_tags.rb b/test/dummy/db/migrate/20140806123008_create_project_tags.rb deleted file mode 100644 index 4a51a36..0000000 --- a/test/dummy/db/migrate/20140806123008_create_project_tags.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateProjectTags < ActiveRecord::Migration[6.1] - def change - create_table :project_tags do |t| - t.references :project, index: true - t.references :tag, index: true - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140820071344_create_assignments.rb b/test/dummy/db/migrate/20140820071344_create_assignments.rb deleted file mode 100644 index 37b7901..0000000 --- a/test/dummy/db/migrate/20140820071344_create_assignments.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateAssignments < ActiveRecord::Migration[6.1] - def change - create_table :assignments do |t| - t.string :name - - t.timestamps - end - end -end diff --git a/test/dummy/db/migrate/20140821074917_add_assignment_ref_to_tasks.rb b/test/dummy/db/migrate/20140821074917_add_assignment_ref_to_tasks.rb deleted file mode 100644 index 9cd3cd9..0000000 --- a/test/dummy/db/migrate/20140821074917_add_assignment_ref_to_tasks.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAssignmentRefToTasks < ActiveRecord::Migration[6.1] - def change - add_reference :tasks, :assignment, index: true - end -end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 679cc0f..ed824d1 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,163 +10,161 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2014_08_21_074917) do - +ActiveRecord::Schema[8.1].define(version: 2014_08_21_074917) do create_table "answers", force: :cascade do |t| t.text "content" + t.datetime "created_at", null: false t.integer "question_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["question_id"], name: "index_answers_on_question_id" end create_table "artists", force: :cascade do |t| + t.datetime "created_at", null: false t.string "name" t.integer "song_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["song_id"], name: "index_artists_on_song_id" end create_table "assignments", force: :cascade do |t| + t.datetime "created_at", null: false t.string "name" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false end create_table "conferences", force: :cascade do |t| - t.string "name" t.string "city" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.string "name" + t.datetime "updated_at", null: false end create_table "emails", force: :cascade do |t| t.string "address" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "user_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false t.index ["user_id"], name: "index_emails_on_user_id" end create_table "people", force: :cascade do |t| - t.string "name" - t.string "role" + t.datetime "created_at", null: false t.string "description" + t.string "name" t.integer "project_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.string "role" + t.datetime "updated_at", null: false t.index ["project_id"], name: "index_people_on_project_id" end create_table "presentations", force: :cascade do |t| - t.string "topic" + t.datetime "created_at", null: false t.string "duration" t.integer "speaker_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.string "topic" + t.datetime "updated_at", null: false t.index ["speaker_id"], name: "index_presentations_on_speaker_id" end create_table "producers", force: :cascade do |t| + t.integer "artist_id" + t.datetime "created_at", null: false t.string "name" t.string "studio" - t.integer "artist_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["artist_id"], name: "index_producers_on_artist_id" end create_table "profiles", force: :cascade do |t| - t.string "twitter_name" + t.datetime "created_at", null: false t.string "github_name" + t.string "twitter_name" + t.datetime "updated_at", null: false t.integer "user_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false t.index ["user_id"], name: "index_profiles_on_user_id" end create_table "project_tags", force: :cascade do |t| + t.datetime "created_at", null: false t.integer "project_id" t.integer "tag_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["project_id"], name: "index_project_tags_on_project_id" t.index ["tag_id"], name: "index_project_tags_on_tag_id" end create_table "projects", force: :cascade do |t| - t.string "name" + t.datetime "created_at", null: false t.string "description" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.string "name" t.integer "owner_id" + t.datetime "updated_at", null: false end create_table "questions", force: :cascade do |t| t.text "content" + t.datetime "created_at", null: false t.integer "survey_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["survey_id"], name: "index_questions_on_survey_id" end create_table "songs", force: :cascade do |t| - t.string "title" + t.datetime "created_at", null: false t.string "length" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.string "title" + t.datetime "updated_at", null: false end create_table "speakers", force: :cascade do |t| + t.integer "conference_id" + t.datetime "created_at", null: false t.string "name" t.string "occupation" - t.integer "conference_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["conference_id"], name: "index_speakers_on_conference_id" end create_table "sub_tasks", force: :cascade do |t| - t.string "name" + t.datetime "created_at", null: false t.string "description" t.boolean "done" + t.string "name" t.integer "task_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false t.index ["task_id"], name: "index_sub_tasks_on_task_id" end create_table "surveys", force: :cascade do |t| + t.datetime "created_at", null: false t.string "name" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false end create_table "tags", force: :cascade do |t| + t.datetime "created_at", null: false t.string "name" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "updated_at", null: false end create_table "tasks", force: :cascade do |t| - t.string "name" + t.integer "assignment_id" + t.datetime "created_at", null: false t.string "description" t.boolean "done" + t.string "name" t.integer "project_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.integer "assignment_id" + t.datetime "updated_at", null: false t.index ["assignment_id"], name: "index_tasks_on_assignment_id" t.index ["project_id"], name: "index_tasks_on_project_id" end create_table "users", force: :cascade do |t| - t.string "name" t.integer "age" + t.datetime "created_at", null: false t.integer "gender" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.string "name" + t.datetime "updated_at", null: false end - end diff --git a/test/dummy/test/controllers/assignments_controller_test.rb b/test/dummy/test/controllers/assignments_controller_test.rb index d2b916d..cb3be8a 100644 --- a/test/dummy/test/controllers/assignments_controller_test.rb +++ b/test/dummy/test/controllers/assignments_controller_test.rb @@ -10,7 +10,6 @@ class AssignmentsControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success - assert_not_nil assigns(:assignments) end test "should get new" do @@ -19,74 +18,57 @@ class AssignmentsControllerTest < ActionController::TestCase end test "should create assignment" do - assert_difference('Assignment.count') do - post :create, assignment: { - name: "Life", - - tasks_attributes: { - "0" => { name: "Eat" }, - "1" => { name: "Pray" }, - "2" => { name: "Love" }, - } - } + assert_difference('Assignment.count', 1) do + assert_difference('Task.count', 3) do + post :create, params: { assignment: { + name: "Life", + + tasks_attributes: { + "0" => { name: "Eat" }, + "1" => { name: "Pray" }, + "2" => { name: "Love" }, + } + } } + end end - assignment_form = assigns(:assignment_form) - - assert assignment_form.valid? - assert_redirected_to assignment_path(assignment_form) - - assert_equal "Life", assignment_form.name - - assert_equal "Eat", assignment_form.tasks[0].name - assert_equal "Pray", assignment_form.tasks[1].name - assert_equal "Love", assignment_form.tasks[2].name - - assignment_form.tasks.each do |task_form| - assert task_form.persisted? - end + assignment = Assignment.last + assert_equal "Life", assignment.name + assert_equal 3, assignment.tasks.size - assert_equal "Assignment: Life was successfully created.", flash[:notice] + assert_redirected_to assignment_path(assignment) + assert_match /was successfully created/, flash[:notice] end test "should not create assignment with invalid params" do - assignment = assignments(:yard) - assert_difference('Assignment.count', 0) do - post :create, assignment: { - name: assignment.name, + post :create, params: { assignment: { + name: @assignment.name, tasks_attributes: { "0" => { name: nil }, "1" => { name: nil }, "2" => { name: nil }, } - } + } } end - assignment_form = assigns(:assignment_form) - - assert_not assignment_form.valid? - assert_includes assignment_form.errors.messages[:name], "has already been taken" - - assignment_form.tasks.each do |task_form| - assert_includes task_form.errors.messages[:name], "can't be blank" - end + assert_response :success end test "should show assignment" do - get :show, id: @assignment + get :show, params: { id: @assignment } assert_response :success end test "should get edit" do - get :edit, id: @assignment + get :edit, params: { id: @assignment } assert_response :success end test "should update assignment" do assert_difference('Assignment.count', 0) do - patch :update, id: @assignment, assignment: { + patch :update, params: { id: @assignment, assignment: { name: "Car service", tasks_attributes: { @@ -94,25 +76,19 @@ class AssignmentsControllerTest < ActionController::TestCase "1" => { name: "Clean inside", id: tasks(:paint).id }, "2" => { name: "Check breaks", id: tasks(:clean).id }, } - } + } } end - assignment_form = assigns(:assignment_form) - - assert_redirected_to assignment_path(assignment_form) - - assert_equal "Car service", assignment_form.name - - assert_equal "Wash tires", assignment_form.tasks[0].name - assert_equal "Clean inside", assignment_form.tasks[1].name - assert_equal "Check breaks", assignment_form.tasks[2].name + @assignment.reload + assert_equal "Car service", @assignment.name - assert_equal "Assignment: Car service was successfully updated.", flash[:notice] + assert_redirected_to assignment_path(@assignment) + assert_match /was successfully updated/, flash[:notice] end test "should destroy assignment" do assert_difference('Assignment.count', -1) do - delete :destroy, id: @assignment + delete :destroy, params: { id: @assignment } end assert_redirected_to assignments_path diff --git a/test/dummy/test/controllers/conferences_controller_test.rb b/test/dummy/test/controllers/conferences_controller_test.rb index b631832..389ff66 100644 --- a/test/dummy/test/controllers/conferences_controller_test.rb +++ b/test/dummy/test/controllers/conferences_controller_test.rb @@ -10,7 +10,6 @@ class ConferencesControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success - assert_not_nil assigns(:conferences) end test "should get new" do @@ -19,8 +18,8 @@ class ConferencesControllerTest < ActionController::TestCase end test "should create conference" do - assert_difference('Conference.count') do - post :create, conference: { + assert_difference(['Conference.count', 'Speaker.count']) do + post :create, params: { conference: { name: "Euruco", city: "Athens", @@ -33,36 +32,23 @@ class ConferencesControllerTest < ActionController::TestCase "1" => { topic: "Ruby Closures", duration: "1h" }, } } - } + } } end - conference_form = assigns(:conference_form) - - assert conference_form.valid? - assert_redirected_to conference_path(conference_form) - - assert_equal "Euruco", conference_form.name - assert_equal "Athens", conference_form.city - - assert_equal "Petros Markou", conference_form.speaker.name - assert_equal "Developer", conference_form.speaker.occupation - - assert_equal "Ruby OOP", conference_form.speaker.presentations[0].topic - assert_equal "1h", conference_form.speaker.presentations[0].duration - assert_equal "Ruby Closures", conference_form.speaker.presentations[1].topic - assert_equal "1h", conference_form.speaker.presentations[1].duration - - assert conference_form.speaker.persisted? - conference_form.speaker.presentations.each do |presentation| - presentation.persisted? - end - - assert_equal "Conference: #{conference_form.name} was successfully created.", flash[:notice] + conference = Conference.last + assert_equal "Euruco", conference.name + assert_equal "Athens", conference.city + assert_equal "Petros Markou", conference.speaker.name + assert_equal "Developer", conference.speaker.occupation + assert_equal 2, conference.speaker.presentations.size + + assert_redirected_to conference_path(conference) + assert_match /was successfully created/, flash[:notice] end test "should create dynamically added presentation to speaker" do assert_difference('Conference.count') do - post :create, conference: { + post :create, params: { conference: { name: "Euruco", city: "Athens", @@ -76,47 +62,24 @@ class ConferencesControllerTest < ActionController::TestCase "12312" => { topic: "Ruby Metaprogramming", duration: "2h" } } } - } + } } end - conference_form = assigns(:conference_form) - - assert conference_form.valid? - assert_redirected_to conference_path(conference_form) - - assert_equal "Euruco", conference_form.name - assert_equal "Athens", conference_form.city - - assert_equal "Petros Markou", conference_form.speaker.name - assert_equal "Developer", conference_form.speaker.occupation - - assert_equal 3, conference_form.speaker.presentations.size - - assert_equal "Ruby OOP", conference_form.speaker.presentations[0].topic - assert_equal "1h", conference_form.speaker.presentations[0].duration - assert_equal "Ruby Closures", conference_form.speaker.presentations[1].topic - assert_equal "1h", conference_form.speaker.presentations[1].duration - assert_equal "Ruby Metaprogramming", conference_form.speaker.presentations[2].topic - assert_equal "2h", conference_form.speaker.presentations[2].duration - - assert conference_form.speaker.persisted? - conference_form.speaker.presentations.each do |presentation| - presentation.persisted? - end - - assert_equal "Conference: #{conference_form.name} was successfully created.", flash[:notice] + conference = Conference.last + assert_equal 3, conference.speaker.presentations.size + + assert_redirected_to conference_path(conference) + assert_match /was successfully created/, flash[:notice] end test "should not create conference with invalid params" do - conference = conferences(:ruby) - assert_difference(['Conference.count', 'Speaker.count'], 0) do - post :create, conference: { - name: conference.name, + post :create, params: { conference: { + name: @conference.name, city: nil, speaker_attributes: { - name: conference.speaker.name, + name: @conference.speaker.name, occupation: "Developer", presentations_attributes: { @@ -124,35 +87,25 @@ class ConferencesControllerTest < ActionController::TestCase "1" => { topic: "Ruby Closures", duration: nil }, } } - } + } } end - conference_form = assigns(:conference_form) - - assert_not conference_form.valid? - - assert_includes conference_form.errors.messages[:name], "has already been taken" - assert_includes conference_form.errors.messages[:city], "can't be blank" - - assert_includes conference_form.speaker.errors.messages[:name], "has already been taken" - - assert_includes conference_form.speaker.presentations[0].errors.messages[:topic], "can't be blank" - assert_includes conference_form.speaker.presentations[1].errors.messages[:duration], "can't be blank" + assert_response :success end test "should show conference" do - get :show, id: @conference + get :show, params: { id: @conference } assert_response :success end test "should get edit" do - get :edit, id: @conference + get :edit, params: { id: @conference } assert_response :success end test "should update conference" do assert_difference('Conference.count', 0) do - patch :update, id: @conference, conference: { + patch :update, params: { id: @conference, conference: { name: "GoGaruco", city: "Golden State", @@ -165,30 +118,21 @@ class ConferencesControllerTest < ActionController::TestCase "1" => { topic: "Rails Patterns", duration: "1h", id: presentations(:ruby_closures).id }, } } - } + } } end - conference_form = assigns(:conference_form) - - assert_redirected_to conference_path(conference_form) - - assert_equal "GoGaruco", conference_form.name - assert_equal "Golden State", conference_form.city - - assert_equal "John Doe", conference_form.speaker.name - assert_equal "Developer", conference_form.speaker.occupation - - assert_equal "Rails Patterns", conference_form.speaker.presentations[0].topic - assert_equal "1h", conference_form.speaker.presentations[0].duration - assert_equal "Rails OOP", conference_form.speaker.presentations[1].topic - assert_equal "1h", conference_form.speaker.presentations[1].duration - - assert_equal "Conference: #{conference_form.name} was successfully updated.", flash[:notice] + @conference.reload + assert_equal "GoGaruco", @conference.name + assert_equal "Golden State", @conference.city + assert_equal "John Doe", @conference.speaker.name + + assert_redirected_to conference_path(@conference) + assert_match /was successfully updated/, flash[:notice] end test "should destroy dynamically removed presentation from speaker" do - assert_difference('Conference.count', 0) do - patch :update, id: @conference, conference: { + assert_difference('Presentation.count', -1) do + patch :update, params: { id: @conference, conference: { name: "GoGaruco", city: "Golden State", @@ -201,30 +145,19 @@ class ConferencesControllerTest < ActionController::TestCase "1" => { topic: "Rails Patterns", duration: "1h", id: presentations(:ruby_closures).id, _destroy: "1" }, } } - } + } } end - conference_form = assigns(:conference_form) - - assert_redirected_to conference_path(conference_form) - - assert_equal "GoGaruco", conference_form.name - assert_equal "Golden State", conference_form.city - - assert_equal "John Doe", conference_form.speaker.name - assert_equal "Developer", conference_form.speaker.occupation - - assert_equal "Rails OOP", conference_form.speaker.presentations[0].topic - assert_equal "1h", conference_form.speaker.presentations[0].duration - - assert_equal 1, conference_form.speaker.presentations.size - - assert_equal "Conference: #{conference_form.name} was successfully updated.", flash[:notice] + @conference.reload + assert_equal 1, @conference.speaker.presentations.size + + assert_redirected_to conference_path(@conference) + assert_match /was successfully updated/, flash[:notice] end test "should destroy conference" do assert_difference('Conference.count', -1) do - delete :destroy, id: @conference + delete :destroy, params: { id: @conference } end assert_redirected_to conferences_path diff --git a/test/dummy/test/controllers/projects_controller_test.rb b/test/dummy/test/controllers/projects_controller_test.rb index d2d0ca0..c8f3cb8 100644 --- a/test/dummy/test/controllers/projects_controller_test.rb +++ b/test/dummy/test/controllers/projects_controller_test.rb @@ -2,7 +2,7 @@ class ProjectsControllerTest < ActionController::TestCase fixtures :projects - + setup do @project = projects(:yard) end @@ -10,7 +10,6 @@ class ProjectsControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success - assert_not_nil assigns(:projects) end test "should get new" do @@ -20,30 +19,34 @@ class ProjectsControllerTest < ActionController::TestCase test "should create project" do assert_difference('Project.count') do - post :create, project: { description: @project.description, name: @project.name } + post :create, params: { project: { description: @project.description, name: @project.name } } end - assert_redirected_to project_path(assigns(:project)) + assert_redirected_to project_path(Project.last) end test "should show project" do - get :show, id: @project + get :show, params: { id: @project } assert_response :success end test "should get edit" do - get :edit, id: @project + get :edit, params: { id: @project } assert_response :success end test "should update project" do - patch :update, id: @project, project: { description: @project.description, name: @project.name } - assert_redirected_to project_path(assigns(:project)) + patch :update, params: { id: @project, project: { name: "new name" } } + + @project.reload + assert_equal "new name", @project.name + + assert_redirected_to project_path(@project) end test "should destroy project" do assert_difference('Project.count', -1) do - delete :destroy, id: @project + delete :destroy, params: { id: @project } end assert_redirected_to projects_path diff --git a/test/dummy/test/controllers/songs_controller_test.rb b/test/dummy/test/controllers/songs_controller_test.rb index 3e04a8c..364881b 100644 --- a/test/dummy/test/controllers/songs_controller_test.rb +++ b/test/dummy/test/controllers/songs_controller_test.rb @@ -10,7 +10,6 @@ class SongsControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success - assert_not_nil assigns(:songs) end test "should get new" do @@ -20,7 +19,7 @@ class SongsControllerTest < ActionController::TestCase test "should create song" do assert_difference(['Song.count', 'Artist.count', 'Producer.count']) do - post :create, song: { + post :create, params: { song: { title: "Diamonds", length: "360", @@ -32,31 +31,23 @@ class SongsControllerTest < ActionController::TestCase studio: "MADog" } } - } + } } end - song_form = assigns(:song_form) + song = Song.last + assert_equal "Diamonds", song.title + assert_equal "360", song.length + assert_equal "Karras", song.artist.name + assert_equal "Phoebos", song.artist.producer.name + assert_equal "MADog", song.artist.producer.studio - assert song_form.valid? - assert_redirected_to song_path(song_form) - - assert_equal "Diamonds", song_form.title - assert_equal "360", song_form.length - - assert_equal "Karras", song_form.artist.name - - assert_equal "Phoebos", song_form.artist.producer.name - assert_equal "MADog", song_form.artist.producer.studio - - assert song_form.artist.persisted? - assert song_form.artist.producer.persisted? - - assert_equal "Song: Diamonds was successfully created.", flash[:notice] + assert_redirected_to song_path(song) + assert_match /was successfully created/, flash[:notice] end test "should not create song with invalid params" do assert_difference(['Song.count', 'Artist.count', 'Producer.count'], 0) do - post :create, song: { + post :create, params: { song: { title: nil, length: nil, @@ -68,39 +59,25 @@ class SongsControllerTest < ActionController::TestCase studio: nil } } - } + } } end - song_form = assigns(:song_form) - - assert_not song_form.valid? - - assert_includes song_form.errors[:title], "can't be blank" - assert_includes song_form.errors[:length], "can't be blank" - - assert_includes song_form.errors["artist.name"], "can't be blank" - assert_includes song_form.artist.errors[:name], "can't be blank" - - assert_includes song_form.artist.producer.errors[:name], "can't be blank" - assert_includes song_form.artist.producer.errors[:studio], "can't be blank" - - assert_includes song_form.errors["artist.producer.name"], "can't be blank" - assert_includes song_form.errors["artist.producer.studio"], "can't be blank" + assert_response :success end test "should show song" do - get :show, id: @song + get :show, params: { id: @song } assert_response :success end test "should get edit" do - get :edit, id: @song + get :edit, params: { id: @song } assert_response :success end test "should update song" do assert_difference(['Song.count', 'Artist.count', 'Producer.count'], 0) do - patch :update, id: @song, song: { + patch :update, params: { id: @song, song: { title: "Run this town", length: "355", @@ -112,27 +89,23 @@ class SongsControllerTest < ActionController::TestCase studio: "Marshall" } } - } + } } end - song_form = assigns(:song_form) - - assert_redirected_to song_path(song_form) - - assert_equal "Run this town", song_form.title - assert_equal "355", song_form.length - - assert_equal "Rihanna", song_form.artist.name - - assert_equal "Eminem", song_form.artist.producer.name - assert_equal "Marshall", song_form.artist.producer.studio + @song.reload + assert_equal "Run this town", @song.title + assert_equal "355", @song.length + assert_equal "Rihanna", @song.artist.name + assert_equal "Eminem", @song.artist.producer.name + assert_equal "Marshall", @song.artist.producer.studio - assert_equal "Song: Run this town was successfully updated.", flash[:notice] + assert_redirected_to song_path(@song) + assert_match /was successfully updated/, flash[:notice] end test "should destroy song" do assert_difference('Song.count', -1) do - delete :destroy, id: @song + delete :destroy, params: { id: @song } end assert_redirected_to songs_path diff --git a/test/dummy/test/controllers/surveys_controller_test.rb b/test/dummy/test/controllers/surveys_controller_test.rb index fa1bfcc..736107e 100644 --- a/test/dummy/test/controllers/surveys_controller_test.rb +++ b/test/dummy/test/controllers/surveys_controller_test.rb @@ -2,7 +2,7 @@ class SurveysControllerTest < ActionController::TestCase fixtures :surveys, :questions, :answers - + setup do @survey = surveys(:programming) end @@ -10,7 +10,6 @@ class SurveysControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success - assert_not_nil assigns(:surveys) end test "should get new" do @@ -19,49 +18,37 @@ class SurveysControllerTest < ActionController::TestCase end test "should create survey" do - assert_difference('Survey.count') do - post :create, survey: { - name: "Programming languages", - - questions_attributes: { - "0" => { - content: "Which language allows closures?", - - answers_attributes: { - "0" => { content: "Ruby Programming Language" }, - "1" => { content: "CSharp Programming Language" }, + assert_difference(['Survey.count', 'Question.count']) do + assert_difference('Answer.count', 2) do + post :create, params: { survey: { + name: "Programming languages", + + questions_attributes: { + "0" => { + content: "Which language allows closures?", + + answers_attributes: { + "0" => { content: "Ruby Programming Language" }, + "1" => { content: "CSharp Programming Language" }, + } } } - } - } + } } + end end - survey_form = assigns(:survey_form) - - assert survey_form.valid? - assert_redirected_to survey_path(assigns(:survey_form)) - - assert_equal "Programming languages", survey_form.name - - assert_equal "Which language allows closures?", survey_form.questions[0].content - - assert_equal "Ruby Programming Language", survey_form.questions[0].answers[0].content - assert_equal "CSharp Programming Language", survey_form.questions[0].answers[1].content - - survey_form.questions.each do |question| - assert question.persisted? + survey = Survey.last + assert_equal "Programming languages", survey.name + assert_equal "Which language allows closures?", survey.questions.first.content + assert_equal 2, survey.questions.first.answers.size - question.answers.each do |answer| - assert answer.persisted? - end - end - - assert_equal "Survey: #{survey_form.name} was successfully created.", flash[:notice] + assert_redirected_to survey_path(survey) + assert_match /was successfully created/, flash[:notice] end test "should create dynamically added question to a survey" do - assert_difference('Survey.count') do - post :create, survey: { + assert_difference('Question.count', 2) do + post :create, params: { survey: { name: "Programming languages", questions_attributes: { @@ -83,42 +70,19 @@ class SurveysControllerTest < ActionController::TestCase } } } - } + } } end - survey_form = assigns(:survey_form) - - assert survey_form.valid? - assert_redirected_to survey_path(assigns(:survey_form)) - - assert_equal "Programming languages", survey_form.name - - assert_equal 2, survey_form.questions.size - - assert_equal "Which language allows closures?", survey_form.questions[0].content - - assert_equal "Ruby Programming Language", survey_form.questions[0].answers[0].content - assert_equal "CSharp Programming Language", survey_form.questions[0].answers[1].content - - assert_equal "Which language allows objects?", survey_form.questions[1].content - - assert_equal "Ruby Programming Language", survey_form.questions[1].answers[0].content - assert_equal "C Programming Language", survey_form.questions[1].answers[1].content - - survey_form.questions.each do |question| - assert question.persisted? + survey = Survey.last + assert_equal 2, survey.questions.size - question.answers.each do |answer| - assert answer.persisted? - end - end - - assert_equal "Survey: #{survey_form.name} was successfully created.", flash[:notice] + assert_redirected_to survey_path(survey) + assert_match /was successfully created/, flash[:notice] end test "should create dynamically added answer to a question" do - assert_difference('Survey.count') do - post :create, survey: { + assert_difference('Answer.count', 3) do + post :create, params: { survey: { name: "Programming languages", questions_attributes: { @@ -132,39 +96,20 @@ class SurveysControllerTest < ActionController::TestCase } } } - } + } } end - survey_form = assigns(:survey_form) - - assert survey_form.valid? - assert_redirected_to survey_path(assigns(:survey_form)) - - assert_equal "Programming languages", survey_form.name - - assert_equal "Which language allows closures?", survey_form.questions[0].content + survey = Survey.last + assert_equal 3, survey.questions.first.answers.size - assert_equal 3, survey_form.questions[0].answers.size - - assert_equal "Ruby Programming Language", survey_form.questions[0].answers[0].content - assert_equal "CSharp Programming Language", survey_form.questions[0].answers[1].content - assert_equal "C Programming Language", survey_form.questions[0].answers[2].content - - survey_form.questions.each do |question| - assert question.persisted? - - question.answers.each do |answer| - assert answer.persisted? - end - end - - assert_equal "Survey: #{survey_form.name} was successfully created.", flash[:notice] + assert_redirected_to survey_path(survey) + assert_match /was successfully created/, flash[:notice] end test "should not create survey with invalid params" do assert_difference('Survey.count', 0) do - post :create, survey: { - name: surveys(:programming).name, + post :create, params: { survey: { + name: @survey.name, questions_attributes: { "0" => { @@ -176,33 +121,25 @@ class SurveysControllerTest < ActionController::TestCase } } } - } + } } end - survey_form = assigns(:survey_form) - - assert_not survey_form.valid? - - assert_includes survey_form.errors.messages[:name], "has already been taken" - - assert_includes survey_form.questions[0].errors.messages[:content], "can't be blank" - - assert_includes survey_form.questions[0].answers[1].errors.messages[:content], "can't be blank" + assert_response :success end test "should show survey" do - get :show, id: @survey + get :show, params: { id: @survey } assert_response :success end test "should get edit" do - get :edit, id: @survey + get :edit, params: { id: @survey } assert_response :success end test "should update survey" do assert_difference('Survey.count', 0) do - patch :update, id: @survey, survey: { + patch :update, params: { id: @survey, survey: { name: "Native languages", questions_attributes: { @@ -216,148 +153,116 @@ class SurveysControllerTest < ActionController::TestCase } }, } - } + } } end - survey_form = assigns(:survey_form) - - assert_redirected_to survey_path(survey_form) - - assert_equal "Native languages", survey_form.name - - assert_equal "Which language is spoken in England?", survey_form.questions[0].content - - assert_equal "The Latin Language", survey_form.questions[0].answers[0].content - assert_equal "The English Language", survey_form.questions[0].answers[1].content - - assert_equal "Survey: #{survey_form.name} was successfully updated.", flash[:notice] + @survey.reload + assert_equal "Native languages", @survey.name + assert_equal "Which language is spoken in England?", @survey.questions.first.content + + assert_redirected_to survey_path(@survey) + assert_match /was successfully updated/, flash[:notice] end test "should destroy dynamically removed question from survey" do - survey = Survey.new(name: "Oral languages") - survey.questions << Question.new(content: "Which language is spoken in England?") - survey.questions << Question.new(content: "Which language is spoken in America?") - survey.questions[0].answers << Answer.new(content: "English") - survey.questions[0].answers << Answer.new(content: "Latin") - survey.questions[1].answers << Answer.new(content: "English") - survey.questions[1].answers << Answer.new(content: "American") - survey.save - - assert_difference('Survey.count', 0) do - patch :update, id: survey, survey: { + survey = Survey.create!(name: "Oral languages") + q1 = survey.questions.create!(content: "Which language is spoken in England?") + q2 = survey.questions.create!(content: "Which language is spoken in America?") + q1.answers.create!(content: "English") + q1.answers.create!(content: "Latin") + q2.answers.create!(content: "English") + q2.answers.create!(content: "American") + + assert_difference('Question.count', -1) do + patch :update, params: { id: survey, survey: { name: "Native languages", questions_attributes: { "0" => { content: "Which language is spoken in England?", - id: survey.questions[0].id, + id: q1.id, answers_attributes: { - "0" => { content: "The English Language", id: survey.questions[0].answers[0].id }, - "1" => { content: "The Latin Language", id: survey.questions[0].answers[1].id }, + "0" => { content: "The English Language", id: q1.answers[0].id }, + "1" => { content: "The Latin Language", id: q1.answers[1].id }, } }, "1" => { content: "Which language is spoken in America?", - id: survey.questions[1].id, + id: q2.id, _destroy: "1", answers_attributes: { - "0" => { content: "The English Language", id: survey.questions[1].answers[0].id }, - "1" => { content: "The American Language", id: survey.questions[1].answers[1].id }, + "0" => { content: "The English Language", id: q2.answers[0].id }, + "1" => { content: "The American Language", id: q2.answers[1].id }, } } } - } + } } end - survey_form = assigns(:survey_form) + survey.reload + assert_equal 1, survey.questions.size + assert_equal "Native languages", survey.name - assert_redirected_to survey_path(survey_form) - - assert_equal "Native languages", survey_form.name - - assert_equal "Which language is spoken in England?", survey_form.questions[0].content - - assert_equal 1, survey_form.questions.size - - assert_equal "The English Language", survey_form.questions[0].answers[0].content - assert_equal "The Latin Language", survey_form.questions[0].answers[1].content - - assert_equal "Survey: #{survey_form.name} was successfully updated.", flash[:notice] + assert_redirected_to survey_path(survey) + assert_match /was successfully updated/, flash[:notice] end test "should destroy dynamically removed answer from question" do - survey = Survey.new(name: "Oral languages") - survey.questions << Question.new(content: "Which language is spoken in England?") - survey.questions << Question.new(content: "Which language is spoken in America?") - survey.questions[0].answers << Answer.new(content: "English") - survey.questions[0].answers << Answer.new(content: "Latin") - survey.questions[0].answers << Answer.new(content: "French") - survey.questions[1].answers << Answer.new(content: "English") - survey.questions[1].answers << Answer.new(content: "American") - survey.questions[1].answers << Answer.new(content: "Italian") - survey.save - - assert_difference('Survey.count', 0) do - patch :update, id: survey, survey: { + survey = Survey.create!(name: "Oral languages") + q1 = survey.questions.create!(content: "Which language is spoken in England?") + q2 = survey.questions.create!(content: "Which language is spoken in America?") + q1.answers.create!(content: "English") + q1.answers.create!(content: "Latin") + q1.answers.create!(content: "French") + q2.answers.create!(content: "English") + q2.answers.create!(content: "American") + q2.answers.create!(content: "Italian") + + assert_difference('Answer.count', -2) do + patch :update, params: { id: survey, survey: { name: "Native languages", questions_attributes: { "0" => { content: "Which language is spoken in England?", - id: survey.questions[0].id, + id: q1.id, answers_attributes: { - "0" => { content: "The English Language", id: survey.questions[0].answers[0].id }, - "1" => { content: "The Latin Language", id: survey.questions[0].answers[1].id }, - "2" => { content: "The French Language", id: survey.questions[0].answers[2].id, _destroy: "1" } + "0" => { content: "The English Language", id: q1.answers[0].id }, + "1" => { content: "The Latin Language", id: q1.answers[1].id }, + "2" => { content: "The French Language", id: q1.answers[2].id, _destroy: "1" } } }, "1" => { content: "Which language is spoken in America?", - id: survey.questions[1].id, + id: q2.id, answers_attributes: { - "0" => { content: "The English Language", id: survey.questions[1].answers[0].id }, - "1" => { content: "The American Language", id: survey.questions[1].answers[1].id }, - "2" => { content: "The Italian Language", id: survey.questions[1].answers[2].id, _destroy: "1" } + "0" => { content: "The English Language", id: q2.answers[0].id }, + "1" => { content: "The American Language", id: q2.answers[1].id }, + "2" => { content: "The Italian Language", id: q2.answers[2].id, _destroy: "1" } } } } - } + } } end - survey_form = assigns(:survey_form) - - assert_redirected_to survey_path(survey_form) - - assert_equal "Native languages", survey_form.name - - assert_equal 2, survey_form.questions.size - - assert_equal "Which language is spoken in England?", survey_form.questions[0].content - - assert_equal 2, survey_form.questions[0].answers.size - - assert_equal "The English Language", survey_form.questions[0].answers[0].content - assert_equal "The Latin Language", survey_form.questions[0].answers[1].content - - assert_equal "Which language is spoken in America?", survey_form.questions[1].content + survey.reload + assert_equal 2, survey.questions.size + assert_equal 2, survey.questions[0].answers.size + assert_equal 2, survey.questions[1].answers.size - assert_equal 2, survey_form.questions[1].answers.size - - assert_equal "The English Language", survey_form.questions[1].answers[0].content - assert_equal "The American Language", survey_form.questions[1].answers[1].content - - assert_equal "Survey: #{survey_form.name} was successfully updated.", flash[:notice] + assert_redirected_to survey_path(survey) + assert_match /was successfully updated/, flash[:notice] end test "should destroy survey" do assert_difference('Survey.count', -1) do - delete :destroy, id: @survey + delete :destroy, params: { id: @survey } end assert_redirected_to surveys_path diff --git a/test/dummy/test/controllers/users_controller_test.rb b/test/dummy/test/controllers/users_controller_test.rb index 4550e96..7b4214f 100644 --- a/test/dummy/test/controllers/users_controller_test.rb +++ b/test/dummy/test/controllers/users_controller_test.rb @@ -2,7 +2,7 @@ class UsersControllerTest < ActionController::TestCase fixtures :users, :emails, :profiles - + setup do @user = users(:peter) end @@ -10,7 +10,6 @@ class UsersControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success - assert_not_nil assigns(:users) end test "should get new" do @@ -20,85 +19,68 @@ class UsersControllerTest < ActionController::TestCase test "should create user" do assert_difference(['User.count', 'Email.count', 'Profile.count']) do - post :create, user: { + post :create, params: { user: { age: "23", gender: "0", name: "petrakos", email_attributes: { - address: "petrakos@gmail.com" + address: "petrakos@gmail.com" }, profile_attributes: { twitter_name: "t_peter", github_name: "g_peter" } - } + } } end - user_form = assigns(:user_form) - - assert user_form.valid? - assert_redirected_to user_path(user_form) - - assert_equal "petrakos", user_form.name - assert_equal 23, user_form.age - assert_equal 0, user_form.gender - - assert_equal "petrakos@gmail.com", user_form.email.address - - assert_equal "t_peter", user_form.profile.twitter_name - assert_equal "g_peter", user_form.profile.github_name - - assert_equal "User: #{user_form.name} was successfully created.", flash[:notice] + user = User.last + assert_equal "petrakos", user.name + assert_equal 23, user.age + assert_equal 0, user.gender + assert_equal "petrakos@gmail.com", user.email.address + assert_equal "t_peter", user.profile.twitter_name + assert_equal "g_peter", user.profile.github_name + + assert_redirected_to user_path(user) + assert_match /was successfully created/, flash[:notice] end test "should not create user with invalid params" do - peter = users(:peter) - assert_difference(['User.count', 'Email.count', 'Profile.count'], 0) do - post :create, user: { - name: peter.name, + post :create, params: { user: { + name: @user.name, age: nil, gender: "0", email_attributes: { - address: peter.email.address + address: @user.email.address }, profile_attributes: { - twitter_name: peter.profile.twitter_name, - github_name: peter.profile.github_name + twitter_name: @user.profile.twitter_name, + github_name: @user.profile.github_name } - } + } } end - user_form = assigns(:user_form) - - assert_not user_form.valid? - - assert_includes user_form.errors.messages[:name], "has already been taken" - assert_includes user_form.errors.messages[:age], "can't be blank" - - assert_includes user_form.email.errors.messages[:address], "has already been taken" - - assert_includes user_form.profile.errors.messages[:twitter_name], "has already been taken" - assert_includes user_form.profile.errors.messages[:github_name], "has already been taken" + assert_response :success end test "should show user" do - get :show, id: @user + get :show, params: { id: @user } assert_response :success end test "should get edit" do - get :edit, id: @user + get :edit, params: { id: @user } assert_response :success end test "should update user" do assert_difference(['User.count', 'Email.count', 'Profile.count'], 0) do - patch :update, id: @user, user: { + patch :update, params: { id: @user, user: { age: @user.age, gender: @user.gender, name: "petrakos", @@ -111,26 +93,22 @@ class UsersControllerTest < ActionController::TestCase twitter_name: "t_peter", github_name: "g_peter" } - } + } } end - user_form = assigns(:user_form) - - assert_redirected_to user_path(user_form) - - assert_equal "petrakos", user_form.name - - assert_equal "petrakos@gmail.com", user_form.email.address - - assert_equal "t_peter", user_form.profile.twitter_name - assert_equal "g_peter", user_form.profile.github_name - - assert_equal "User: #{user_form.name} was successfully updated.", flash[:notice] + @user.reload + assert_equal "petrakos", @user.name + assert_equal "petrakos@gmail.com", @user.email.address + assert_equal "t_peter", @user.profile.twitter_name + assert_equal "g_peter", @user.profile.github_name + + assert_redirected_to user_path(@user) + assert_match /was successfully updated/, flash[:notice] end test "should destroy user" do assert_difference('User.count', -1) do - delete :destroy, id: @user + delete :destroy, params: { id: @user } end assert_redirected_to users_path diff --git a/test/dummy/test/fixtures/demo.txt b/test/dummy/test/fixtures/files/demo.txt similarity index 100% rename from test/dummy/test/fixtures/demo.txt rename to test/dummy/test/fixtures/files/demo.txt diff --git a/test/forms/conference_form_test.rb b/test/forms/conference_form_test.rb index 295c44e..fa3d605 100644 --- a/test/forms/conference_form_test.rb +++ b/test/forms/conference_form_test.rb @@ -1,7 +1,7 @@ require 'test_helper' class ConferenceFormTest < ActiveSupport::TestCase - include ActiveModel::Lint::Tests + include ActionDispatch::TestProcess fixtures :conferences, :speakers, :presentations diff --git a/test/forms/nested_model_form_test.rb b/test/forms/nested_model_form_test.rb index e5ad250..78c245e 100644 --- a/test/forms/nested_model_form_test.rb +++ b/test/forms/nested_model_form_test.rb @@ -2,7 +2,7 @@ require_relative '../fixtures/user_with_email_form_fixture' class NestedModelFormTest < ActiveSupport::TestCase - include ActiveModel::Lint::Tests + fixtures :users, :emails def setup diff --git a/test/forms/nested_model_rendering_test.rb b/test/forms/nested_model_rendering_test.rb index f5c01dc..975ab35 100644 --- a/test/forms/nested_model_rendering_test.rb +++ b/test/forms/nested_model_rendering_test.rb @@ -9,6 +9,17 @@ def form_for(*) @output_buffer = super end + private + + def assert_input(attrs, buffer = output_buffer) + attrs.each do |attr, value| + assert_match(/#{Regexp.escape(attr)}="#{Regexp.escape(value.to_s)}"/, buffer, + "Expected #{attr}=\"#{value}\" in rendered output") + end + end + + public + test "form_for renders correctly a new instance of UserFormFixture" do user = User.new user_form = UserFormFixture.new(user) @@ -32,16 +43,16 @@ def form_for(*) assert_match(/method="post"/, output_buffer) assert_match(/