From 60b6cec6e15df81a5430f2321d2b34cb98e8bd1c Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Sat, 12 May 2018 23:04:31 -0400 Subject: [PATCH 001/148] initial commit --- .gitignore | 30 +++ .ruby-version | 1 + Gemfile | 68 +++++ Gemfile.lock | 239 ++++++++++++++++++ README.md | 12 +- Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 16 ++ app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 app/assets/javascripts/quotes.coffee | 3 + app/assets/stylesheets/application.css | 16 ++ app/assets/stylesheets/quotes.scss | 3 + app/assets/stylesheets/scaffolds.scss | 84 ++++++ app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 2 + app/controllers/concerns/.keep | 0 app/controllers/quotes_controller.rb | 74 ++++++ app/helpers/application_helper.rb | 2 + app/helpers/quotes_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/models/quote.rb | 2 + app/views/layouts/application.html.erb | 29 +++ app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + app/views/quotes/_form.html.erb | 22 ++ app/views/quotes/_quote.json.jbuilder | 2 + app/views/quotes/index.html.erb | 13 + app/views/quotes/index.json.jbuilder | 1 + app/views/quotes/new.html.erb | 5 + app/views/quotes/random.html.erb | 12 + app/views/quotes/show.html.erb | 11 + app/views/quotes/show.json.jbuilder | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 36 +++ bin/spring | 17 ++ bin/update | 31 +++ bin/yarn | 11 + config.ru | 5 + config/application.rb | 19 ++ config/boot.rb | 4 + config/cable.yml | 10 + config/credentials.yml.enc | 1 + config/database.yml | 25 ++ config/environment.rb | 5 + config/environments/development.rb | 61 +++++ config/environments/production.rb | 94 +++++++ config/environments/test.rb | 46 ++++ .../application_controller_renderer.rb | 8 + config/initializers/assets.rb | 14 + config/initializers/backtrace_silencers.rb | 7 + .../initializers/content_security_policy.rb | 25 ++ config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 ++ config/initializers/kaminari_config.rb | 12 + config/initializers/mime_types.rb | 4 + config/initializers/wrap_parameters.rb | 14 + config/locales/en.yml | 33 +++ config/puma.rb | 34 +++ config/routes.rb | 7 + config/spring.rb | 6 + config/storage.yml | 34 +++ db/migrate/20180512222706_create_quotes.rb | 11 + db/schema.rb | 23 ++ db/seeds.rb | 26 ++ lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 package.json | 5 + public/404.html | 67 +++++ public/422.html | 67 +++++ public/500.html | 66 +++++ public/apple-touch-icon-precomposed.png | 0 public/apple-touch-icon.png | 0 public/favicon.ico | 0 public/robots.txt | 1 + test/application_system_test_case.rb | 5 + test/controllers/.keep | 0 test/controllers/quotes_controller_test.rb | 48 ++++ test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/fixtures/quotes.yml | 9 + test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/quote_test.rb | 7 + test/system/.keep | 0 test/system/quotes_test.rb | 45 ++++ test/test_helper.rb | 10 + tmp/.keep | 0 vendor/.keep | 0 100 files changed, 1700 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/javascripts/quotes.coffee create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/assets/stylesheets/quotes.scss create mode 100644 app/assets/stylesheets/scaffolds.scss create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/quotes_controller.rb create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/quotes_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/models/quote.rb create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100644 app/views/quotes/_form.html.erb create mode 100644 app/views/quotes/_quote.json.jbuilder create mode 100644 app/views/quotes/index.html.erb create mode 100644 app/views/quotes/index.json.jbuilder create mode 100644 app/views/quotes/new.html.erb create mode 100644 app/views/quotes/random.html.erb create mode 100644 app/views/quotes/show.html.erb create mode 100644 app/views/quotes/show.json.jbuilder create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100755 bin/yarn create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/credentials.yml.enc create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/content_security_policy.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/kaminari_config.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/spring.rb create mode 100644 config/storage.yml create mode 100644 db/migrate/20180512222706_create_quotes.rb create mode 100644 db/schema.rb create mode 100644 db/seeds.rb create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 package.json create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/apple-touch-icon-precomposed.png create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 test/application_system_test_case.rb create mode 100644 test/controllers/.keep create mode 100644 test/controllers/quotes_controller_test.rb create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/fixtures/quotes.yml create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/models/quote_test.rb create mode 100644 test/system/.keep create mode 100644 test/system/quotes_test.rb create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec0b196 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore uploaded files in development +/storage/* + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..4fd0fe3 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..2cef8b3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,68 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.5.1' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.0' +# Use sqlite3 as the database for Active Record +gem 'sqlite3' +# Use Puma as the app server +gem 'puma', '~> 3.11' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'mini_racer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15', '< 4.0' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +# Use bootstrap gem for HTML/CSS/JS +gem 'bootstrap' + +# Use kaminari gem for pagination +gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..f3d73d3 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,239 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.0) + actionpack (= 5.2.0) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.0) + actionview (= 5.2.0) + activesupport (= 5.2.0) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.0) + activesupport (= 5.2.0) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.0) + activesupport (= 5.2.0) + globalid (>= 0.3.6) + activemodel (5.2.0) + activesupport (= 5.2.0) + activerecord (5.2.0) + activemodel (= 5.2.0) + activesupport (= 5.2.0) + arel (>= 9.0) + activestorage (5.2.0) + actionpack (= 5.2.0) + activerecord (= 5.2.0) + marcel (~> 0.3.1) + activesupport (5.2.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + archive-zip (0.11.0) + io-like (~> 0.3.0) + arel (9.0.0) + autoprefixer-rails (8.4.1) + execjs + bindex (0.5.0) + bootsnap (1.3.0) + msgpack (~> 1.0) + bootstrap (4.1.1) + autoprefixer-rails (>= 6.0.3) + popper_js (>= 1.12.9, < 2) + sass (>= 3.5.2) + builder (3.2.3) + byebug (10.0.2) + capybara (3.1.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + xpath (~> 3.0) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (1.2.0) + archive-zip (~> 0.10) + nokogiri (~> 1.8) + coffee-rails (4.2.2) + coffee-script (>= 2.2.0) + railties (>= 4.0.0) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + erubi (1.7.1) + execjs (2.7.0) + ffi (1.9.23) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (1.0.1) + concurrent-ruby (~> 1.0) + io-like (0.3.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + kaminari (1.1.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) + actionview + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) + activerecord + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.2.2) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.0) + mini_mime (>= 0.1.1) + marcel (0.3.2) + mimemagic (~> 0.3.2) + method_source (0.9.0) + mimemagic (0.3.2) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + msgpack (1.2.4) + multi_json (1.13.1) + nio4r (2.3.1) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + popper_js (1.12.9) + public_suffix (3.0.2) + puma (3.11.4) + rack (2.0.5) + rack-test (1.0.0) + rack (>= 1.0, < 3) + rails (5.2.0) + actioncable (= 5.2.0) + actionmailer (= 5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) + activemodel (= 5.2.0) + activerecord (= 5.2.0) + activestorage (= 5.2.0) + activesupport (= 5.2.0) + bundler (>= 1.3.0) + railties (= 5.2.0) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.2.0) + actionpack (= 5.2.0) + activesupport (= 5.2.0) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + ruby_dep (1.5.0) + rubyzip (1.2.1) + sass (3.5.6) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.12.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.1.1) + turbolinks-source (~> 5.1) + turbolinks-source (5.1.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.10) + execjs (>= 0.3.0, < 3) + web-console (3.6.2) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.0.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + bootsnap (>= 1.1.0) + bootstrap + byebug + capybara (>= 2.15, < 4.0) + chromedriver-helper + coffee-rails (~> 4.2) + jbuilder (~> 2.5) + kaminari + listen (>= 3.0.5, < 3.2) + puma (~> 3.11) + rails (~> 5.2.0) + sass-rails (~> 5.0) + selenium-webdriver + spring + spring-watcher-listen (~> 2.0.0) + sqlite3 + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +RUBY VERSION + ruby 2.5.1p57 + +BUNDLED WITH + 1.16.1 diff --git a/README.md b/README.md index 4bf363d..359e951 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ -# rqdb -Rash/Rails Quote Database +# README + +Setup: +* RVM +* Ruby 2.5.1 +* bundle install +* bundle exec rake db:migrate +* bundle exec rails server + +Browse to http://localhost:3000 \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e85f913 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..b16e53d --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..82e6f0f --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's +// vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require rails-ujs +//= require activestorage +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000..739aa5f --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/quotes.coffee b/app/assets/javascripts/quotes.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/quotes.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..f1784e0 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,16 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ +@import "bootstrap"; \ No newline at end of file diff --git a/app/assets/stylesheets/quotes.scss b/app/assets/stylesheets/quotes.scss new file mode 100644 index 0000000..93953b9 --- /dev/null +++ b/app/assets/stylesheets/quotes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Quotes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..6045188 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb new file mode 100644 index 0000000..9fa41b2 --- /dev/null +++ b/app/controllers/quotes_controller.rb @@ -0,0 +1,74 @@ +class QuotesController < ApplicationController + before_action :set_quote, only: [:show, :edit, :update, :destroy] + + # GET /quotes + # GET /quotes.json + def index + @quotes = Quote.page params[:page] + end + + # GET /quotes/1 + # GET /quotes/1.json + def show + end + + # GET /quotes/new + def new + @quote = Quote.new + end + + # GET /browse + # GET /browse.json + def browse + @quotes = Quote.all + end + + # GET /random + # GET /random.json + def random + quote_ids = 25.times.map{ rand(1..Quote.count) } + @quotes = quote_ids.map{|id| Quote.exists?(id) && Quote.find(id) }.select{|quote| quote unless quote.nil?} + end + + # POST /quotes + # POST /quotes.json + def create + @quote = Quote.new(quote_params) + + respond_to do |format| + if @quote.score != 0 or @quote.approved + format.html { render :new } + format.json { render json: @quote.errors, status: :unprocessable_entity } + end + + if @quote.save + format.html { redirect_to @quote, notice: 'Quote was successfully created.' } + format.json { render :show, status: :created, location: @quote } + else + format.html { render :new } + format.json { render json: @quote.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /quotes/1 + # DELETE /quotes/1.json + def destroy + @quote.destroy + respond_to do |format| + format.html { redirect_to quotes_url, notice: 'Quote was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_quote + @quote = Quote.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def quote_params + params.require(:quote).permit(:text, :score) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/quotes_helper.rb b/app/helpers/quotes_helper.rb new file mode 100644 index 0000000..32b09df --- /dev/null +++ b/app/helpers/quotes_helper.rb @@ -0,0 +1,2 @@ +module QuotesHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..a009ace --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..286b223 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/quote.rb b/app/models/quote.rb new file mode 100644 index 0000000..bfa5513 --- /dev/null +++ b/app/models/quote.rb @@ -0,0 +1,2 @@ +class Quote < ApplicationRecord +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..e495ffd --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,29 @@ + + + + QDB + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + - -
-
 
-
- <%= yield %> -
-
 
-
- - + +
+
+

RQDB

+
+ +
+
+
+ <%= yield %> +
+
 
+
+
+ From 5d31124a51e8207386f8f3500abcc41c4b64db29 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Mon, 14 May 2018 13:42:51 -0400 Subject: [PATCH 043/148] layout --- app/assets/stylesheets/application.scss | 7 ++-- app/views/layouts/application.html.erb | 45 ++++--------------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index f1a6421..eb0f3ed 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -28,10 +28,13 @@ a#admin_link:hover, a:hover, a:visited:hover{ color: #c08000; } -div#title { +#title, #versionbar { color: #FFFFFF; background-color: #336699; - width: 80%; +} + +#versionbar { + text-align: right; } pre.quote_output{ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3f2258d..67af692 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,45 +14,14 @@

RQDB

- From d819fdb290000c3a2f5eb3b4d9062a5e0f4e103a Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 15 May 2018 11:48:09 -0400 Subject: [PATCH 044/148] layout/pagination --- app/assets/stylesheets/application.scss | 1 + app/views/layouts/application.html.erb | 16 ++++++++++- app/views/quotes/_navbar.html.erb | 37 +++++++++++++++++++++++++ app/views/quotes/_show.html.erb | 17 ++++-------- app/views/quotes/index.html.erb | 6 ++-- app/views/quotes/latest.html.erb | 6 +++- app/views/quotes/top.html.erb | 6 ++-- config/initializers/kaminari_config.rb | 2 +- 8 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 app/views/quotes/_navbar.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index eb0f3ed..e08573c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -19,6 +19,7 @@ body { font-size: 10pt; font-family: Veranda, sans-serif; color: #000000; + align: center; } a, a#admin_link, a:link, a:visited{ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 67af692..025ca64 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,18 +10,32 @@ -
+
+

RQDB

+
+
+
<%= render 'quotes/navbar' %> +
+
+
<%= yield %>
+
+
+
<%= render 'quotes/navbar' %> +
+
+
RQDB Version: pre-alpha
+
diff --git a/app/views/quotes/_navbar.html.erb b/app/views/quotes/_navbar.html.erb new file mode 100644 index 0000000..f25dc48 --- /dev/null +++ b/app/views/quotes/_navbar.html.erb @@ -0,0 +1,37 @@ +
+ +
\ No newline at end of file diff --git a/app/views/quotes/_show.html.erb b/app/views/quotes/_show.html.erb index dbe7eae..d4385f0 100644 --- a/app/views/quotes/_show.html.erb +++ b/app/views/quotes/_show.html.erb @@ -1,11 +1,6 @@ -<% @quotes.each do |quote| %> -

- <%= link_to "##{quote.id}", quote %> - +(<%= quote.score %>)- - [X] - <%= link_to 'Delete', quote, method: :delete, data: { confirm: 'Are you sure?' } %> -

-

-

<%= quote.text %>
-

-<% end %> \ No newline at end of file +<%= link_to "##{quote.id}", quote %> ++(<%= quote.score %>)- +[X] +<%= link_to 'Delete', quote, method: :delete, data: { confirm: 'Are you sure?' } %> +
+
<%= quote.text %>
diff --git a/app/views/quotes/index.html.erb b/app/views/quotes/index.html.erb index 9caf38c..3095a0f 100644 --- a/app/views/quotes/index.html.erb +++ b/app/views/quotes/index.html.erb @@ -1,5 +1,5 @@

<%= notice %>

<%= paginate(@quotes) %> -<% @quotes.each do |quote| %> -<%= render 'quotes/show' %> -<% end %> +<% @quotes.each do |quote| -%> +<%= render 'quotes/show', :quote => quote %> +<% end -%> \ No newline at end of file diff --git a/app/views/quotes/latest.html.erb b/app/views/quotes/latest.html.erb index 8179946..3095a0f 100644 --- a/app/views/quotes/latest.html.erb +++ b/app/views/quotes/latest.html.erb @@ -1 +1,5 @@ -<%= render 'quotes/show' %> \ No newline at end of file +

<%= notice %>

+<%= paginate(@quotes) %> +<% @quotes.each do |quote| -%> +<%= render 'quotes/show', :quote => quote %> +<% end -%> \ No newline at end of file diff --git a/app/views/quotes/top.html.erb b/app/views/quotes/top.html.erb index 9caf38c..3095a0f 100644 --- a/app/views/quotes/top.html.erb +++ b/app/views/quotes/top.html.erb @@ -1,5 +1,5 @@

<%= notice %>

<%= paginate(@quotes) %> -<% @quotes.each do |quote| %> -<%= render 'quotes/show' %> -<% end %> +<% @quotes.each do |quote| -%> +<%= render 'quotes/show', :quote => quote %> +<% end -%> \ No newline at end of file diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb index c808667..f97fc45 100644 --- a/config/initializers/kaminari_config.rb +++ b/config/initializers/kaminari_config.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true Kaminari.configure do |config| - # config.default_per_page = 25 + config.default_per_page = 15 # config.max_per_page = nil # config.window = 4 # config.outer_window = 0 From eceb0304d535bc92a3e069893f7db0a071ec3041 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 15 May 2018 11:51:25 -0400 Subject: [PATCH 045/148] pretty bootstrap pagination --- app/views/kaminari/_first_page.html.erb | 3 +++ app/views/kaminari/_gap.html.erb | 3 +++ app/views/kaminari/_last_page.html.erb | 3 +++ app/views/kaminari/_next_page.html.erb | 3 +++ app/views/kaminari/_page.html.erb | 9 +++++++++ app/views/kaminari/_paginator.html.erb | 17 +++++++++++++++++ app/views/kaminari/_prev_page.html.erb | 3 +++ 7 files changed, 41 insertions(+) create mode 100644 app/views/kaminari/_first_page.html.erb create mode 100644 app/views/kaminari/_gap.html.erb create mode 100644 app/views/kaminari/_last_page.html.erb create mode 100644 app/views/kaminari/_next_page.html.erb create mode 100644 app/views/kaminari/_page.html.erb create mode 100644 app/views/kaminari/_paginator.html.erb create mode 100644 app/views/kaminari/_prev_page.html.erb diff --git a/app/views/kaminari/_first_page.html.erb b/app/views/kaminari/_first_page.html.erb new file mode 100644 index 0000000..cc107ec --- /dev/null +++ b/app/views/kaminari/_first_page.html.erb @@ -0,0 +1,3 @@ +
  • + <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_gap.html.erb b/app/views/kaminari/_gap.html.erb new file mode 100644 index 0000000..d241fc4 --- /dev/null +++ b/app/views/kaminari/_gap.html.erb @@ -0,0 +1,3 @@ +
  • + <%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_last_page.html.erb b/app/views/kaminari/_last_page.html.erb new file mode 100644 index 0000000..9a7584e --- /dev/null +++ b/app/views/kaminari/_last_page.html.erb @@ -0,0 +1,3 @@ +
  • + <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_next_page.html.erb b/app/views/kaminari/_next_page.html.erb new file mode 100644 index 0000000..7ca72a8 --- /dev/null +++ b/app/views/kaminari/_next_page.html.erb @@ -0,0 +1,3 @@ +
  • + <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %> +
  • diff --git a/app/views/kaminari/_page.html.erb b/app/views/kaminari/_page.html.erb new file mode 100644 index 0000000..c8f03f2 --- /dev/null +++ b/app/views/kaminari/_page.html.erb @@ -0,0 +1,9 @@ +<% if page.current? %> +
  • + <%= content_tag :a, page, data: { remote: remote }, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), class: 'page-link' %> +
  • +<% else %> +
  • + <%= link_to page, url, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), class: 'page-link' %> +
  • +<% end %> diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb new file mode 100644 index 0000000..bb5ed0f --- /dev/null +++ b/app/views/kaminari/_paginator.html.erb @@ -0,0 +1,17 @@ +<%= paginator.render do %> + +<% end %> diff --git a/app/views/kaminari/_prev_page.html.erb b/app/views/kaminari/_prev_page.html.erb new file mode 100644 index 0000000..c7803fa --- /dev/null +++ b/app/views/kaminari/_prev_page.html.erb @@ -0,0 +1,3 @@ +
  • + <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %> +
  • From d08ef5783da2c65db5a837ce639542e1e708fc1a Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 15 May 2018 12:07:42 -0400 Subject: [PATCH 046/148] links --- app/controllers/quotes_controller.rb | 16 ++++++++++++++++ app/views/quotes/_show.html.erb | 6 +++--- app/views/quotes/show.html.erb | 5 +++-- config/routes.rb | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index 53dee6b..d62dacc 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb @@ -45,6 +45,22 @@ def upvote end end + # GET /quotes/1/flag + # POST /quotes/1/flag + def flag + @quote = Quote.find(params[:id]) + @quote.update(flagged: true) + respond_to do |format| + if @quote.save + format.html { redirect_to @quote, notice: 'Quote was successfully flagged.' } + format.json { render :show, status: :ok, location: @quote } + else + format.html { render :edit } + format.json { render json: @quote.errors, status: :unprocessable_entity } + end + end + end + # GET /quotes/new def new @quote = Quote.new diff --git a/app/views/quotes/_show.html.erb b/app/views/quotes/_show.html.erb index d4385f0..769d48b 100644 --- a/app/views/quotes/_show.html.erb +++ b/app/views/quotes/_show.html.erb @@ -1,6 +1,6 @@ <%= link_to "##{quote.id}", quote %> -+(<%= quote.score %>)- -[X] -<%= link_to 'Delete', quote, method: :delete, data: { confirm: 'Are you sure?' } %> +<%= link_to '+', "/quotes/#{quote.id}/upvote", method: :get, data: { confirm: 'Are you sure you want to upvote?' } %>(<%= quote.score %>)<%= link_to '-', "/quotes/#{quote.id}/downvote", method: :get, data: { confirm: 'Are you sure you want to downvote?' } %> +<%= link_to '[X]', "/quotes/#{quote.id}/flag", method: :get, data: { confirm: 'Are you sure you want to flag this quote for review?' } %> +<%= link_to 'Delete', quote, method: :delete, data: { confirm: 'Are you sure you want to delete this quote?' } %>
    <%= quote.text %>
    diff --git a/app/views/quotes/show.html.erb b/app/views/quotes/show.html.erb index caa8e59..09be518 100644 --- a/app/views/quotes/show.html.erb +++ b/app/views/quotes/show.html.erb @@ -1,3 +1,4 @@ -<% quote = @quote %>

    <%= notice %>

    -<%= render 'quotes/show' %> \ No newline at end of file +<% @quotes.each do |quote| -%> +<%= render 'quotes/show', :quote => quote %> +<% end -%> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0ff2de3..54e7dca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,8 @@ post :downvote get :upvote post :upvote + get :flag + post :flag end end From 72e7827a901190d5e94b3442054b165b1468859b Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 15 May 2018 12:09:28 -0400 Subject: [PATCH 047/148] fix randoms --- app/views/quotes/random.html.erb | 4 +++- app/views/quotes/random1.html.erb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/quotes/random.html.erb b/app/views/quotes/random.html.erb index d2dc89c..09be518 100644 --- a/app/views/quotes/random.html.erb +++ b/app/views/quotes/random.html.erb @@ -1,2 +1,4 @@

    <%= notice %>

    -<%= render 'quotes/show' %> +<% @quotes.each do |quote| -%> +<%= render 'quotes/show', :quote => quote %> +<% end -%> \ No newline at end of file diff --git a/app/views/quotes/random1.html.erb b/app/views/quotes/random1.html.erb index d2dc89c..09be518 100644 --- a/app/views/quotes/random1.html.erb +++ b/app/views/quotes/random1.html.erb @@ -1,2 +1,4 @@

    <%= notice %>

    -<%= render 'quotes/show' %> +<% @quotes.each do |quote| -%> +<%= render 'quotes/show', :quote => quote %> +<% end -%> \ No newline at end of file From 5975a453a9cb77fe0008916897cabc416a747388 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 15 May 2018 12:29:39 -0400 Subject: [PATCH 048/148] layout --- app/assets/stylesheets/application.scss | 3 +- app/views/layouts/application.html.erb | 49 +++++++++--------- app/views/quotes/_navbar.html.erb | 69 ++++++++++++------------- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index e08573c..bb935af 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -43,12 +43,13 @@ pre.quote_output{ padding-bottom: 13pt; } -#navbar { +.navbar, #navbar { background-color: #f0f0f0; text-align: right; font-size: 10pt; font-family: Veranda, sans-serif; color: #000000; + float: right; } h1 { diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 025ca64..0b40c14 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,32 +10,33 @@ -
    -
    -
    -

    RQDB

    +
    +
    +
    +
    +

    RQDB

    +
    +
    -
    -
    -
    - <%= render 'quotes/navbar' %> -
    -
    -
    -
    - <%= yield %> +
    + <%= render 'quotes/navbar' %>
    -
    -
    -
    - <%= render 'quotes/navbar' %> -
    -
    -
    -
    - RQDB Version: pre-alpha +
    +
    +
    + <%= yield %> +
    +
    +
    +
    + <%= render 'quotes/navbar' %> +
    +
    +
    +
    + RQDB Version: pre-alpha +
    +
    -
    -
    diff --git a/app/views/quotes/_navbar.html.erb b/app/views/quotes/_navbar.html.erb index f25dc48..dea1194 100644 --- a/app/views/quotes/_navbar.html.erb +++ b/app/views/quotes/_navbar.html.erb @@ -1,37 +1,34 @@ -
    - \ No newline at end of file diff --git a/test/controllers/announcements_controller_test.rb b/test/controllers/announcements_controller_test.rb index ec0be64..68ff56f 100644 --- a/test/controllers/announcements_controller_test.rb +++ b/test/controllers/announcements_controller_test.rb @@ -9,5 +9,21 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest test 'should get index' do get '/' assert_response :success + assert_select 'div.announcements', {:count=>1} + assert_select 'div.announcement', {:count=>2} + end + + test 'unauthenticated user should not add announcement' do + assert_no_changes('Announcement.count') do + false + end + assert_redirected_to '/users/sign_in' + end + + test 'authenticated user should add announcement' do + sign_in users(:one) + assert_no_changes('Announcement.count') do + false + end end end \ No newline at end of file diff --git a/test/controllers/quotes_controller_test.rb b/test/controllers/quotes_controller_test.rb index e32952e..080f9de 100644 --- a/test/controllers/quotes_controller_test.rb +++ b/test/controllers/quotes_controller_test.rb @@ -19,10 +19,19 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest test 'should create quote' do assert_difference('Quote.count') do - post quotes_url, params: { quote: { score: @quote.score, text: @quote.text } } + post quotes_url, params: { quote: { text: @quote.text } } end end + test 'should fail to create approved quote' do + post quotes_url, params: { quote: { text: 'this quote is not approved', approved: true } } + assert_equal false, Quote.where(text: 'this quote is not approved').first.approved + end + + test 'should fail to set score on created quote' do + + end + test 'should show quote' do get quote_url(@quote) assert_response :success @@ -68,7 +77,7 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest end get '/random' - assert_select "pre", {:class => "quote_output", :count=>0} + assert_select "pre.quote_output", {:count=>0} assert_response :success end diff --git a/test/controllers/searches_controller_test.rb b/test/controllers/searches_controller_test.rb index 5243cbc..e0e5e48 100644 --- a/test/controllers/searches_controller_test.rb +++ b/test/controllers/searches_controller_test.rb @@ -5,21 +5,21 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest @search = searches(:one) end - test "search should return matching quotes" do + test 'search should return matching quotes' do post '/search', params: { pattern: 'MyString1' } assert_response :success - assert_select "pre", {:class => "quote_output", :count=>1} + assert_select 'pre.quote_output', {:count=>1} end - test "search should not return nonmatching quotes" do + test 'search should not return nonmatching quotes' do post '/search', params: { pattern: 'BogusStringWithNoMatchingQuotes' } assert_response :success - assert_select "pre", {:class => "quote_output", :count=>0} + assert_select 'pre.quote_output', {:count=>0} end - test "empty search pattern should not return quotes" do + test 'empty search pattern should not return quotes' do post '/search', params: { pattern: '' } assert_response :success - assert_select "pre", {:class => "quote_output", :count=>0} + assert_select 'pre.quote_output', {:count=>0} end end \ No newline at end of file diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 6d77ca0..0f2057b 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -21,14 +21,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end end - test "unauthenticated user should not create user" do + test 'unauthenticated user should not create user' do assert_no_difference('User.count') do post users_url, params: { user: { email: 'another@email', password: 'password' } } end assert_redirected_to '/users/sign_in' end - test "authenticated user should create user" do + test 'authenticated user should create user' do sign_in users(:one) assert_difference('User.count', +1) do post users_url, params: { user: { email: 'another@email', password: 'password' } } @@ -37,14 +37,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end - test "unauthenticated user should not destroy user" do + test 'unauthenticated user should not destroy user' do assert_no_difference('User.count') do post users_url, params: { user: { email: 'another@email', password: 'password' } } end assert_redirected_to '/users/sign_in' end - test "authenticated user should not destroy self" do + test 'authenticated user should not destroy self' do sign_in users(:one) sign_in users(:one) assert_no_difference('User.count') do @@ -54,7 +54,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end - test "authenticated user should destroy other user" do + test 'authenticated user should destroy other user' do sign_in users(:one) assert_difference('User.count', -1) do delete "/admin/users/#{@other_user.id}" diff --git a/test/system/announcements_test.rb b/test/system/announcements_test.rb index 7f9c329..8825018 100644 --- a/test/system/announcements_test.rb +++ b/test/system/announcements_test.rb @@ -5,8 +5,8 @@ class AnnouncementsTest < ApplicationSystemTestCase @announcement = announcements(:one) end - test 'visiting the index' do - visit '/' - assert_select "pre", {:class => "announcement", :count=>1} + test "visiting the index" do + visit quotes_url + assert_selector "table", class: "announcements" end end \ No newline at end of file From d7046c9223db791e63a79fed7043037cecddc294 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 09:53:31 -0400 Subject: [PATCH 109/148] add test scenarios for announcements controller --- .../announcements_controller_test.rb | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/test/controllers/announcements_controller_test.rb b/test/controllers/announcements_controller_test.rb index 68ff56f..c35c64e 100644 --- a/test/controllers/announcements_controller_test.rb +++ b/test/controllers/announcements_controller_test.rb @@ -13,17 +13,57 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest assert_select 'div.announcement', {:count=>2} end - test 'unauthenticated user should not add announcement' do + + test 'should not create blank announcement' do + sign_in users(:one) assert_no_changes('Announcement.count') do - false + post announcements_url, params: { announcement: { text: '' } } + end + end + + test 'unauthenticated user should not add announcement' do + assert_no_difference('Announcement.count') do + post announcements_url, params: { announcement: { text: 'My new announcement' } } end assert_redirected_to '/users/sign_in' end test 'authenticated user should add announcement' do sign_in users(:one) - assert_no_changes('Announcement.count') do - false + assert_difference('Announcement.count', +1) do + post announcements_url, params: { announcement: { text: 'My new announcement' } } + end + end + + test 'unauthenticated user should not destroy announcement' do + assert_no_difference('Announcement.count') do + delete announcement_url(@announcement) + end + assert_redirected_to '/users/sign_in' + end + + test 'authenticated user should destroy announcement' do + sign_in users(:one) + assert_difference('Announcement.count', +1) do + delete announcement_url(@announcement) + end + end + + test 'unauthenticated user should not update announcement' do + assert_no_changes('@announcement.text') do + @modified_announcement = @announcement + @modified_announcement.text = 'Modified text' + put announcement_url, params: { announcement: @modified_announcement } + end + assert_redirected_to '/users/sign_in' + end + + test 'authenticated user should update announcement' do + sign_in users(:one) + assert_changes('@announcement.text') do + @modified_announcement = @announcement + @modified_announcement.text = 'Modified text' + put announcement_url, params: { announcement: @modified_announcement } end end end \ No newline at end of file From cc9fc1a98885f0575a2e827b69fa98f43fe91d35 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:04:32 -0400 Subject: [PATCH 110/148] remove stale template --- app/views/announcements/_show.html.erb.old | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 app/views/announcements/_show.html.erb.old diff --git a/app/views/announcements/_show.html.erb.old b/app/views/announcements/_show.html.erb.old deleted file mode 100644 index baead3b..0000000 --- a/app/views/announcements/_show.html.erb.old +++ /dev/null @@ -1,13 +0,0 @@ -Announcements
    - - -
    -<% @announcements.each do |announcement| %>
    - 
    - - - -<% end %> - - -
    <%= announcement.text %><%= announcement.created_at %>
    From 4390c3b188b54d2afd130b1e3c935c19da890002 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:04:40 -0400 Subject: [PATCH 111/148] move divs to index in views --- app/views/announcements/_show.html.erb | 10 ++++------ app/views/announcements/index.html.erb | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/announcements/_show.html.erb b/app/views/announcements/_show.html.erb index 542bf1c..67d353d 100644 --- a/app/views/announcements/_show.html.erb +++ b/app/views/announcements/_show.html.erb @@ -1,6 +1,4 @@ -
    - <%= announcement.created_at.strftime("%Y.%m.%d %H:%M:%S %Z") %> -
    -			<%= announcement.text %>
    -		
    -
    \ No newline at end of file +<%= announcement.created_at.strftime("%Y.%m.%d %H:%M:%S %Z") %> +
    +	<%= announcement.text %>
    +
    \ No newline at end of file diff --git a/app/views/announcements/index.html.erb b/app/views/announcements/index.html.erb index c09f971..08a6e08 100644 --- a/app/views/announcements/index.html.erb +++ b/app/views/announcements/index.html.erb @@ -13,7 +13,9 @@
    <%= paginate(@announcements) %> <% @announcements.each do |announcement| -%> - <%= render 'announcements/show', :announcement => announcement %> +
    + <%= render 'announcements/show', :announcement => announcement %> +
    <% end %>
    \ No newline at end of file From 1787b95570d9158f1965544efe178cfd3244e9cd Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:04:49 -0400 Subject: [PATCH 112/148] add announcement routes --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 50be9ea..f78f965 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,8 @@ get 'top', to: 'quotes#top' get 'bottom', to: 'quotes#bottom' + resources :announcements + resources :quotes do member do get :downvote From 438240179a08e4858b85124d7d7988ee0aff5acc Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:05:22 -0400 Subject: [PATCH 113/148] update announcement tests --- .../announcements_controller_test.rb | 21 +++++++++---------- test/controllers/quotes_controller_test.rb | 18 ++++++++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/test/controllers/announcements_controller_test.rb b/test/controllers/announcements_controller_test.rb index c35c64e..07a5a5f 100644 --- a/test/controllers/announcements_controller_test.rb +++ b/test/controllers/announcements_controller_test.rb @@ -13,28 +13,27 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest assert_select 'div.announcement', {:count=>2} end - - test 'should not create blank announcement' do - sign_in users(:one) - assert_no_changes('Announcement.count') do - post announcements_url, params: { announcement: { text: '' } } - end - end - - test 'unauthenticated user should not add announcement' do + test 'unauthenticated user should not create announcement' do assert_no_difference('Announcement.count') do post announcements_url, params: { announcement: { text: 'My new announcement' } } end assert_redirected_to '/users/sign_in' end - test 'authenticated user should add announcement' do + test 'authenticated user should create announcement' do sign_in users(:one) assert_difference('Announcement.count', +1) do post announcements_url, params: { announcement: { text: 'My new announcement' } } end end + test 'authenticated user should not create blank announcement' do + sign_in users(:one) + assert_no_changes('Announcement.count') do + post announcements_url, params: { announcement: { text: '' } } + end + end + test 'unauthenticated user should not destroy announcement' do assert_no_difference('Announcement.count') do delete announcement_url(@announcement) @@ -44,7 +43,7 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest test 'authenticated user should destroy announcement' do sign_in users(:one) - assert_difference('Announcement.count', +1) do + assert_difference('Announcement.count', -1) do delete announcement_url(@announcement) end end diff --git a/test/controllers/quotes_controller_test.rb b/test/controllers/quotes_controller_test.rb index 080f9de..2c8d1ea 100644 --- a/test/controllers/quotes_controller_test.rb +++ b/test/controllers/quotes_controller_test.rb @@ -29,7 +29,7 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest end test 'should fail to set score on created quote' do - + assert false end test 'should show quote' do @@ -77,8 +77,22 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest end get '/random' - assert_select "pre.quote_output", {:count=>0} + assert_select 'pre.quote_output', {:count=>0} assert_response :success end + test 'unauthenticated user should not update quote' do + assert_no_changes('Quote.find(@flagged_quote.id).flagged') do + get "/quotes/#{@flagged_quote.id}/unflag" + end + assert_redirected_to '/users/sign_in' + end + + test 'authenticated user should update quote' do + sign_in users(:one) + assert_changes('Quote.find(@flagged_quote.id).flagged') do + get "/quotes/#{@flagged_quote.id}/unflag" + end + end + end From f51982cad365491407e79f2f32f4f6618bc704be Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:10:52 -0400 Subject: [PATCH 114/148] fix urls in tests --- test/controllers/announcements_controller_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/controllers/announcements_controller_test.rb b/test/controllers/announcements_controller_test.rb index 07a5a5f..fac413a 100644 --- a/test/controllers/announcements_controller_test.rb +++ b/test/controllers/announcements_controller_test.rb @@ -52,7 +52,7 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest assert_no_changes('@announcement.text') do @modified_announcement = @announcement @modified_announcement.text = 'Modified text' - put announcement_url, params: { announcement: @modified_announcement } + put announcement_url(@announcement), params: { announcement: @modified_announcement } end assert_redirected_to '/users/sign_in' end @@ -62,7 +62,7 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest assert_changes('@announcement.text') do @modified_announcement = @announcement @modified_announcement.text = 'Modified text' - put announcement_url, params: { announcement: @modified_announcement } + put announcement_url(@announcement), params: { announcement: @modified_announcement } end end end \ No newline at end of file From aac382c5049b413074e556b2aed9e68b1a7378f2 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:11:00 -0400 Subject: [PATCH 115/148] add methods to announcements controller --- app/controllers/announcements_controller.rb | 64 ++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 09a039f..4440707 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -1,8 +1,68 @@ class AnnouncementsController < ApplicationController - # GET /quotes - # GET /quotes.json + before_action :set_announcement, only: [:show, :edit, :update, :destroy] + + # GET /announcements + # GET /announcements def index @announcements = Announcement.order(created_at: :asc).page(params[:page]) end + # GET /announcement/1 + # GET /announcement/1.json + def show + @announcements = [Announcement.find(params[:id])] + end + + # POST /announcements + # POST /announcements.json + def create + authenticate_user! + @announcement = Announcement.new(announcement_params) + respond_to do |format| + if @announcement.save + format.html { redirect_to announcements_url, notice: 'Announcement was successfully created.' } + format.json { render :show, status: :created, location: announcements_url } + else + format.html { render :new } + format.json { render json: @announcement.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /announcements/1 + # PATCH/PUT /announcements/1.json + def update + authenticate_user! + respond_to do |format| + if @announcement.update(announcement_params) + format.html { redirect_to announcements_url, notice: 'Announcement was successfully updated.' } + format.json { render :show, status: :ok, location: announcements_url } + else + format.html { render :edit } + format.json { render json: @announcement.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /announcements/1 + # DELETE /announcements/1.json + def destroy + authenticate_user! + @announcement.destroy + respond_to do |format| + format.html { redirect_to announcements_url, notice: 'Announcement was successfully deleted.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_announcement + @announcement = Announcement.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def announcement_params + params.require(:announcement).permit(:text) + end end From 498da5b5b0d24be729eac029e12f1cd53d66e2a8 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:21:42 -0400 Subject: [PATCH 116/148] set announcement text column to not null --- db/migrate/20180522142058_set_announcement_text_not_null.rb | 5 +++++ db/schema.rb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180522142058_set_announcement_text_not_null.rb diff --git a/db/migrate/20180522142058_set_announcement_text_not_null.rb b/db/migrate/20180522142058_set_announcement_text_not_null.rb new file mode 100644 index 0000000..8746c73 --- /dev/null +++ b/db/migrate/20180522142058_set_announcement_text_not_null.rb @@ -0,0 +1,5 @@ +class SetAnnouncementTextNotNull < ActiveRecord::Migration[5.2] + def change + change_column_null :announcements, :text, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 77d516d..e335b48 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,10 +10,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_05_22_041222) do +ActiveRecord::Schema.define(version: 2018_05_22_142058) do create_table "announcements", force: :cascade do |t| - t.string "text" + t.string "text", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false end From 19bd1d3ae21dc459b98ba013f9e4b63f4e302630 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:23:28 -0400 Subject: [PATCH 117/148] add presence validator for announcement.text --- app/models/announcement.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/announcement.rb b/app/models/announcement.rb index aa98a0e..b44cd77 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -1,2 +1,3 @@ class Announcement < ApplicationRecord + validates :text, presence: true end From 5e3a07d462c686b884a6675a0f12686ab5812bda Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:29:36 -0400 Subject: [PATCH 118/148] centralize auth methods in announcement controller --- app/controllers/announcements_controller.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 4440707..f113a37 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -1,4 +1,5 @@ class AnnouncementsController < ApplicationController + before_action :authenticate_user!, except: [:index, :show] before_action :set_announcement, only: [:show, :edit, :update, :destroy] # GET /announcements @@ -7,16 +8,9 @@ def index @announcements = Announcement.order(created_at: :asc).page(params[:page]) end - # GET /announcement/1 - # GET /announcement/1.json - def show - @announcements = [Announcement.find(params[:id])] - end - # POST /announcements # POST /announcements.json def create - authenticate_user! @announcement = Announcement.new(announcement_params) respond_to do |format| if @announcement.save @@ -32,7 +26,6 @@ def create # PATCH/PUT /announcements/1 # PATCH/PUT /announcements/1.json def update - authenticate_user! respond_to do |format| if @announcement.update(announcement_params) format.html { redirect_to announcements_url, notice: 'Announcement was successfully updated.' } @@ -47,7 +40,6 @@ def update # DELETE /announcements/1 # DELETE /announcements/1.json def destroy - authenticate_user! @announcement.destroy respond_to do |format| format.html { redirect_to announcements_url, notice: 'Announcement was successfully deleted.' } From 776f91945ec0bae89e3d937259591178e7e9b144 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:29:46 -0400 Subject: [PATCH 119/148] set id for announcement fixtures --- test/fixtures/announcements.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fixtures/announcements.yml b/test/fixtures/announcements.yml index 861ee7d..75ea926 100644 --- a/test/fixtures/announcements.yml +++ b/test/fixtures/announcements.yml @@ -1,7 +1,9 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: + id: 1 text: MyString two: + id: 2 text: MyString From e915da901daa4e313e604ca4d5a6dd574dc6daaf Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:30:30 -0400 Subject: [PATCH 120/148] revert quotes changes --- test/controllers/quotes_controller_test.rb | 27 ++-------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/test/controllers/quotes_controller_test.rb b/test/controllers/quotes_controller_test.rb index 2c8d1ea..e32952e 100644 --- a/test/controllers/quotes_controller_test.rb +++ b/test/controllers/quotes_controller_test.rb @@ -19,19 +19,10 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest test 'should create quote' do assert_difference('Quote.count') do - post quotes_url, params: { quote: { text: @quote.text } } + post quotes_url, params: { quote: { score: @quote.score, text: @quote.text } } end end - test 'should fail to create approved quote' do - post quotes_url, params: { quote: { text: 'this quote is not approved', approved: true } } - assert_equal false, Quote.where(text: 'this quote is not approved').first.approved - end - - test 'should fail to set score on created quote' do - assert false - end - test 'should show quote' do get quote_url(@quote) assert_response :success @@ -77,22 +68,8 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest end get '/random' - assert_select 'pre.quote_output', {:count=>0} + assert_select "pre", {:class => "quote_output", :count=>0} assert_response :success end - test 'unauthenticated user should not update quote' do - assert_no_changes('Quote.find(@flagged_quote.id).flagged') do - get "/quotes/#{@flagged_quote.id}/unflag" - end - assert_redirected_to '/users/sign_in' - end - - test 'authenticated user should update quote' do - sign_in users(:one) - assert_changes('Quote.find(@flagged_quote.id).flagged') do - get "/quotes/#{@flagged_quote.id}/unflag" - end - end - end From c1ba7df18ffdbbb5f90e04ed677d4f654ac1c2f9 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:31:05 -0400 Subject: [PATCH 121/148] add failing test stubs --- test/controllers/quotes_controller_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/controllers/quotes_controller_test.rb b/test/controllers/quotes_controller_test.rb index e32952e..966d37c 100644 --- a/test/controllers/quotes_controller_test.rb +++ b/test/controllers/quotes_controller_test.rb @@ -72,4 +72,14 @@ class QuotesControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test 'unauthenticated user should not update quote' do + assert false + assert_redirected_to '/users/sign_in' + end + + test 'authenticated user should update quote' do + sign_in users(:one) + assert false + end + end From 78a31f9f223bb546425ec2b801efcb3a79ce0e7b Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:42:40 -0400 Subject: [PATCH 122/148] fix tests --- test/controllers/announcements_controller_test.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/controllers/announcements_controller_test.rb b/test/controllers/announcements_controller_test.rb index fac413a..f61d37f 100644 --- a/test/controllers/announcements_controller_test.rb +++ b/test/controllers/announcements_controller_test.rb @@ -29,7 +29,7 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest test 'authenticated user should not create blank announcement' do sign_in users(:one) - assert_no_changes('Announcement.count') do + assert_no_difference('Announcement.count') do post announcements_url, params: { announcement: { text: '' } } end end @@ -49,20 +49,17 @@ class AnnouncementsControllerTest < ActionDispatch::IntegrationTest end test 'unauthenticated user should not update announcement' do - assert_no_changes('@announcement.text') do - @modified_announcement = @announcement - @modified_announcement.text = 'Modified text' - put announcement_url(@announcement), params: { announcement: @modified_announcement } + assert_no_changes('Announcement.find(@announcement.id).text') do + patch announcement_url(@announcement), params: { announcement: {id: 1, text: 'Modified text'} } end assert_redirected_to '/users/sign_in' end test 'authenticated user should update announcement' do sign_in users(:one) - assert_changes('@announcement.text') do - @modified_announcement = @announcement - @modified_announcement.text = 'Modified text' - put announcement_url(@announcement), params: { announcement: @modified_announcement } + assert_changes('Announcement.find(@announcement.id).text') do + patch announcement_url(@announcement), params: { announcement: {id: 1, text: 'Modified text'} } end + assert_redirected_to announcements_url end end \ No newline at end of file From 7826a77830b3e11747ecfd5cd0536ff7989475c5 Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:42:45 -0400 Subject: [PATCH 123/148] update controller to make tests pass --- app/controllers/announcements_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index f113a37..4486c04 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -1,6 +1,6 @@ class AnnouncementsController < ApplicationController before_action :authenticate_user!, except: [:index, :show] - before_action :set_announcement, only: [:show, :edit, :update, :destroy] + before_action :set_announcement, only: [:show, :update, :destroy] # GET /announcements # GET /announcements @@ -17,7 +17,7 @@ def create format.html { redirect_to announcements_url, notice: 'Announcement was successfully created.' } format.json { render :show, status: :created, location: announcements_url } else - format.html { render :new } + format.html { redirect_to announcements_url } format.json { render json: @announcement.errors, status: :unprocessable_entity } end end From d76707c2ded60fe70a28098219cb53cb04ce7b0d Mon Sep 17 00:00:00 2001 From: Ben Plunkert Date: Tue, 22 May 2018 10:53:55 -0400 Subject: [PATCH 124/148] add new announcement form and reorder announcement display --- app/controllers/announcements_controller.rb | 9 +++++++-- app/views/admin/_navbar.html.erb | 9 ++++++--- app/views/announcements/_form.html.erb | 22 +++++++++++++++++++++ app/views/announcements/new.html.erb | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 app/views/announcements/_form.html.erb create mode 100644 app/views/announcements/new.html.erb diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 4486c04..f0ae241 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -3,9 +3,14 @@ class AnnouncementsController < ApplicationController before_action :set_announcement, only: [:show, :update, :destroy] # GET /announcements - # GET /announcements + # GET /announcements.json def index - @announcements = Announcement.order(created_at: :asc).page(params[:page]) + @announcements = Announcement.order(created_at: :desc).page(params[:page]) + end + + # GET /announcements/new + def new + @announcement = Announcement.new end # POST /announcements diff --git a/app/views/admin/_navbar.html.erb b/app/views/admin/_navbar.html.erb index 13d6b29..88e0ab6 100644 --- a/app/views/admin/_navbar.html.erb +++ b/app/views/admin/_navbar.html.erb @@ -1,10 +1,13 @@ -
    +