From 5bbf9b2fa7fec1577a99c125c23db8d42fa6a4c4 Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sat, 7 Nov 2020 01:25:53 -0500 Subject: [PATCH 1/8] installed neccessary dependencies along with will_pagination gem. Completed first challenge of adding pagination to index page, to display 5 dogs per page, working on next challenge --- .generators | 8 + .idea/.generators | 8 + .idea/.gitignore | 8 + .idea/.rakeTasks | 7 + .idea/dataSources.xml | 11 + .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/project-challenge.iml | 50 ++++ .idea/vcs.xml | 6 + .rakeTasks | 7 + Gemfile | 3 + Gemfile.lock | 273 ++++++++++--------- app/controllers/dogs_controller.rb | 2 +- app/views/dogs/_thumbnail.html.erb | 1 + app/views/dogs/index.html.erb | 2 + 16 files changed, 267 insertions(+), 137 deletions(-) create mode 100644 .generators create mode 100644 .idea/.generators create mode 100644 .idea/.gitignore create mode 100644 .idea/.rakeTasks create mode 100644 .idea/dataSources.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project-challenge.iml create mode 100644 .idea/vcs.xml create mode 100644 .rakeTasks diff --git a/.generators b/.generators new file mode 100644 index 00000000..16189766 --- /dev/null +++ b/.generators @@ -0,0 +1,8 @@ + + diff --git a/.idea/.generators b/.idea/.generators new file mode 100644 index 00000000..16189766 --- /dev/null +++ b/.idea/.generators @@ -0,0 +1,8 @@ + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks new file mode 100644 index 00000000..c6865d9a --- /dev/null +++ b/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 00000000..dee134b0 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,11 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/db/development.sqlite3 + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..b0db9b0f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..275dd470 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..5d4cc7ed --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-challenge.iml b/.idea/project-challenge.iml new file mode 100644 index 00000000..0a9cb566 --- /dev/null +++ b/.idea/project-challenge.iml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.rakeTasks b/.rakeTasks new file mode 100644 index 00000000..c6865d9a --- /dev/null +++ b/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/Gemfile b/Gemfile index 3f1e6961..ee88dafb 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,8 @@ group :development, :test do gem 'capybara' gem 'pry' gem 'rails-controller-testing' + gem "will_paginate", "~> 3.3" + end group :development do @@ -61,3 +63,4 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + diff --git a/Gemfile.lock b/Gemfile.lock index 16c3b7bc..a6761ec8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,64 +1,65 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.0) - actionpack (= 5.2.0) + actioncable (5.2.4.4) + actionpack (= 5.2.4.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.0) - actionpack (= 5.2.0) - actionview (= 5.2.0) - activejob (= 5.2.0) + actionmailer (5.2.4.4) + actionpack (= 5.2.4.4) + actionview (= 5.2.4.4) + activejob (= 5.2.4.4) 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) + actionpack (5.2.4.4) + actionview (= 5.2.4.4) + activesupport (= 5.2.4.4) + rack (~> 2.0, >= 2.0.8) 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) + actionview (5.2.4.4) + activesupport (= 5.2.4.4) 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) + activejob (5.2.4.4) + activesupport (= 5.2.4.4) globalid (>= 0.3.6) - activemodel (5.2.0) - activesupport (= 5.2.0) - activerecord (5.2.0) - activemodel (= 5.2.0) - activesupport (= 5.2.0) + activemodel (5.2.4.4) + activesupport (= 5.2.4.4) + activerecord (5.2.4.4) + activemodel (= 5.2.4.4) + activesupport (= 5.2.4.4) arel (>= 9.0) - activestorage (5.2.0) - actionpack (= 5.2.0) - activerecord (= 5.2.0) + activestorage (5.2.4.4) + actionpack (= 5.2.4.4) + activerecord (= 5.2.4.4) marcel (~> 0.3.1) - activesupport (5.2.0) + activesupport (5.2.4.4) 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) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) - bcrypt (3.1.12) - bindex (0.5.0) - bootsnap (1.3.0) + bcrypt (3.1.16) + bindex (0.8.1) + bootsnap (1.5.0) msgpack (~> 1.0) - builder (3.2.3) - byebug (10.0.2) - capybara (2.18.0) + builder (3.2.4) + byebug (11.1.3) + capybara (3.32.2) addressable mini_mime (>= 0.1.3) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (>= 2.0, < 4.0) - coderay (1.1.2) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + coderay (1.1.3) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -66,161 +67,160 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.4) - devise (4.4.3) + concurrent-ruby (1.1.7) + crass (1.0.6) + devise (4.7.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 6.0) + railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.3) - erubi (1.7.1) + diff-lcs (1.4.4) + erubi (1.9.0) execjs (2.7.0) - factory_bot (1.0.0.alpha) - activesupport (>= 3.0.0) - factory_bot_rails (1.0.0.alpha) - factory_bot (~> 1.0.0.alpha) - railties (>= 3.0.0) - ffi (1.9.25) - globalid (0.4.1) + factory_bot (5.2.0) activesupport (>= 4.2.0) - i18n (1.0.1) - concurrent-ruby (~> 1.0) - jbuilder (2.7.0) + factory_bot_rails (5.2.0) + factory_bot (~> 5.2.0) + railties (>= 4.2.0) + ffi (1.13.1) + globalid (0.4.2) activesupport (>= 4.2.0) - multi_json (>= 1.2) + i18n (1.8.5) + concurrent-ruby (~> 1.0) + jbuilder (2.10.1) + activesupport (>= 5.0.0) 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) + loofah (2.7.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.2) + marcel (0.3.3) 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) + method_source (1.0.0) + mimemagic (0.3.5) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.14.2) + msgpack (1.3.3) + nio4r (2.5.4) + nokogiri (1.10.10) + mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - public_suffix (3.0.2) - puma (3.11.4) - rack (2.0.5) - rack-test (1.0.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (4.0.6) + puma (3.12.6) + rack (2.2.3) + rack-test (1.1.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) + rails (5.2.4.4) + actioncable (= 5.2.4.4) + actionmailer (= 5.2.4.4) + actionpack (= 5.2.4.4) + actionview (= 5.2.4.4) + activejob (= 5.2.4.4) + activemodel (= 5.2.4.4) + activerecord (= 5.2.4.4) + activestorage (= 5.2.4.4) + activesupport (= 5.2.4.4) bundler (>= 1.3.0) - railties (= 5.2.0) + railties (= 5.2.4.4) sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.2) - actionpack (~> 5.x, >= 5.0.1) - actionview (~> 5.x, >= 5.0.1) - activesupport (~> 5.x) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) 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) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (5.2.4.4) + actionpack (= 5.2.4.4) + activesupport (= 5.2.4.4) 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) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + thor (>= 0.19.0, < 2.0) + rake (13.0.1) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + regexp_parser (1.8.2) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) + rspec-core (3.9.3) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-rails (3.7.2) + rspec-support (~> 3.9.0) + rspec-rails (3.9.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.1) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.4) ruby_dep (1.5.0) - sass (3.5.6) + sass (3.7.4) 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-rails (5.1.0) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - simple_form (4.0.1) + simple_form (5.0.3) actionpack (>= 5.0) activemodel (>= 5.0) - spring (2.0.2) - activesupport (>= 4.2) + spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.0) + sqlite3 (1.4.2) + thor (1.0.1) 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) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.7) thread_safe (~> 0.1) - uglifier (4.1.11) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - warden (1.2.7) - rack (>= 1.0) - web-console (3.6.2) + warden (1.2.9) + rack (>= 2.0.9) + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.7.0) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - xpath (3.0.0) + websocket-extensions (0.1.5) + will_paginate (3.3.0) + xpath (3.2.0) nokogiri (~> 1.8) PLATFORMS @@ -249,9 +249,10 @@ DEPENDENCIES tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) + will_paginate (~> 3.3) RUBY VERSION ruby 2.4.4p296 BUNDLED WITH - 1.16.2 + 1.17.3 diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index cb9eebc5..aaf48654 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -4,7 +4,7 @@ class DogsController < ApplicationController # GET /dogs # GET /dogs.json def index - @dogs = Dog.all + @dogs = Dog.paginate(:page => params[:page], :per_page => 5) end # GET /dogs/1 diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 4d6bb441..163d66c1 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -3,4 +3,5 @@

<%= dog.name %>

<%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %> + diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index 91ea5603..9cbaffb9 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1 +1,3 @@ + <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> +<%= will_paginate @dogs, :page_links => false %> From a7a41b53a0b1bf348e5fe093c2cb91d335cac1df Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sun, 8 Nov 2020 17:17:14 -0500 Subject: [PATCH 2/8] associated dogs with owners --- Gemfile | 20 +++++---- Gemfile.lock | 45 ++++++++++++++++++- app/controllers/dogs_controller.rb | 30 ++++++------- app/models/dog.rb | 1 + app/models/user.rb | 1 + app/views/dogs/edit.html.erb | 2 + app/views/dogs/index.html.erb | 1 + app/views/dogs/show.html.erb | 2 +- .../20201108205017_add_user_to_create_dogs.rb | 5 +++ db/schema.rb | 4 +- db/seeds.rb | 14 +++--- 11 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 db/migrate/20201108205017_add_user_to_create_dogs.rb diff --git a/Gemfile b/Gemfile index ee88dafb..8f4bf791 100644 --- a/Gemfile +++ b/Gemfile @@ -41,26 +41,28 @@ 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] - gem 'rspec-rails', '~> 3.7' - gem 'factory_bot_rails' + gem 'byebug', platforms: %i[mri mingw x64_mingw] gem 'capybara' + gem 'factory_bot_rails' gem 'pry' gem 'rails-controller-testing' - gem "will_paginate", "~> 3.3" - + gem 'rspec-rails', '~> 3.7' + gem 'rubocop' + gem 'solargraph' + gem 'will_paginate', '~> 3.3' 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' + gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'rubocop' + gem 'solargraph' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'will_paginate', '~> 3.3' end - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] - +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Gemfile.lock b/Gemfile.lock index a6761ec8..56c77900 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,6 +45,7 @@ GEM addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) arel (9.0.0) + ast (2.4.1) bcrypt (3.1.16) bindex (0.8.1) bootsnap (1.5.0) @@ -83,6 +84,8 @@ GEM factory_bot_rails (5.2.0) factory_bot (~> 5.2.0) railties (>= 4.2.0) + faker (2.12.0) + i18n (>= 1.6, < 2) ffi (1.13.1) globalid (0.4.2) activesupport (>= 4.2.0) @@ -107,16 +110,23 @@ GEM mini_portile2 (2.4.0) minitest (5.14.2) msgpack (1.3.3) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) nio4r (2.5.4) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) + parallel (1.19.2) + parser (2.7.2.0) + ast (~> 2.4.1) pry (0.13.1) coderay (~> 1.1) method_source (~> 1.0) public_suffix (4.0.6) puma (3.12.6) rack (2.2.3) + rack-protection (2.1.0) + rack rack-test (1.1.0) rack (>= 1.0, < 3) rails (5.2.4.4) @@ -147,6 +157,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) + rainbow (3.0.0) rake (13.0.1) rb-fsevent (0.10.4) rb-inotify (0.10.1) @@ -155,6 +166,7 @@ GEM responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) + rexml (3.2.4) rspec-core (3.9.3) rspec-support (~> 3.9.3) rspec-expectations (3.9.4) @@ -172,6 +184,19 @@ GEM rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) rspec-support (3.9.4) + rubocop (1.2.0) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8) + rexml + rubocop-ast (>= 1.0.1) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.1.1) + parser (>= 2.7.1.5) + ruby-progressbar (1.10.1) + ruby2_keywords (0.0.2) ruby_dep (1.5.0) sass (3.7.4) sass-listen (~> 4.0.0) @@ -187,6 +212,17 @@ GEM simple_form (5.0.3) actionpack (>= 5.0) activemodel (>= 5.0) + sinatra (2.1.0) + mustermann (~> 1.0) + rack (~> 2.2) + rack-protection (= 2.1.0) + tilt (~> 2.0) + solargraph (0.17.4) + bundler (~> 1.14) + parser (~> 2.4) + sinatra (~> 2) + thor (~> 0.19, >= 0.19.4) + yard (~> 0.9) spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -199,16 +235,17 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.4.2) - thor (1.0.1) + thor (0.20.3) thread_safe (0.3.6) tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.7) + tzinfo (1.2.8) thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) + unicode-display_width (1.7.0) warden (1.2.9) rack (>= 2.0.9) web-console (3.7.0) @@ -222,6 +259,7 @@ GEM will_paginate (3.3.0) xpath (3.2.0) nokogiri (~> 1.8) + yard (0.9.25) PLATFORMS ruby @@ -233,6 +271,7 @@ DEPENDENCIES coffee-rails (~> 4.2) devise factory_bot_rails + faker (~> 2.12) jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) pry @@ -240,8 +279,10 @@ DEPENDENCIES rails (~> 5.2.0) rails-controller-testing rspec-rails (~> 3.7) + rubocop sass-rails (~> 5.0) simple_form + solargraph spring spring-watcher-listen (~> 2.0.0) sqlite3 diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index aaf48654..0330cd27 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -1,16 +1,15 @@ class DogsController < ApplicationController - before_action :set_dog, only: [:show, :edit, :update, :destroy] + before_action :set_dog, only: %i[show edit update destroy] # GET /dogs # GET /dogs.json def index - @dogs = Dog.paginate(:page => params[:page], :per_page => 5) + @dogs = Dog.paginate(page: params[:page], per_page: 5) end # GET /dogs/1 # GET /dogs/1.json - def show - end + def show; end # GET /dogs/new def new @@ -18,15 +17,15 @@ def new end # GET /dogs/1/edit - def edit - end + def edit; end # POST /dogs # POST /dogs.json def create @dog = Dog.new(dog_params) - + @dog.user_id = current_user.id respond_to do |format| + byebug if @dog.save @dog.images.attach(params[:dog][:image]) if params[:dog][:image].present? @@ -66,13 +65,14 @@ def destroy end private - # Use callbacks to share common setup or constraints between actions. - def set_dog - @dog = Dog.find(params[:id]) - end - # Never trust parameters from the scary internet, only allow the white list through. - def dog_params - params.require(:dog).permit(:name, :description, :images) - end + # Use callbacks to share common setup or constraints between actions. + def set_dog + @dog = Dog.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def dog_params + params.require(:dog).permit(:name, :description, :images, :user_id) + end end diff --git a/app/models/dog.rb b/app/models/dog.rb index eb40bf6e..8be9b127 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -1,3 +1,4 @@ class Dog < ApplicationRecord has_many_attached :images + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index b2091f9a..625056f6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,5 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + has_many :dogs end diff --git a/app/views/dogs/edit.html.erb b/app/views/dogs/edit.html.erb index f35e7887..128fefd9 100644 --- a/app/views/dogs/edit.html.erb +++ b/app/views/dogs/edit.html.erb @@ -1,2 +1,4 @@

Edit Your Dog

<%= render partial: 'form' %> + + diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index 9cbaffb9..d51fb418 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,3 +1,4 @@ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> <%= will_paginate @dogs, :page_links => false %> + diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index 562324d2..e748b206 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -1,6 +1,5 @@

<%= @dog.name %>

- <% @dog.images.each do |image| %> <%= image_tag url_for(image), alt: "Photo of #{@dog.name}" %> <% end %> @@ -11,3 +10,4 @@
<%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %>
+ diff --git a/db/migrate/20201108205017_add_user_to_create_dogs.rb b/db/migrate/20201108205017_add_user_to_create_dogs.rb new file mode 100644 index 00000000..c080aecb --- /dev/null +++ b/db/migrate/20201108205017_add_user_to_create_dogs.rb @@ -0,0 +1,5 @@ +class AddUserToCreateDogs < ActiveRecord::Migration[5.2] + def change + add_reference :dogs, :user, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 462bd430..3bd8e569 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_06_07_114248) do +ActiveRecord::Schema.define(version: 2020_11_08_205017) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -40,6 +40,8 @@ t.text "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "user_id" + t.index ["user_id"], name: "index_dogs_on_user_id" end create_table "users", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index d3e6fde3..6ae9fb92 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,7 +17,7 @@ }, { name: 'Jax', - description: '', + description: '' }, { name: 'Jiro', @@ -31,7 +31,7 @@ name: 'Bijou', description: 'Bijou is the fluffiest of them all' }, - { + { name: 'Britta', description: 'Britta has two different colored eyes' }, @@ -46,16 +46,16 @@ { name: 'Tonks', description: 'Tonks loves to run' - }, + } ] dogs.each do |dog| - dog = Dog.find_or_create_by(name: dog[:name], description: dog[:description]) - directory_name = File.join(Rails.root, 'db', 'seed', "#{dog[:name].downcase}", "*") + dog = Dog.find_or_create_by(name: dog[:name], description: dog[:description], user: User.all.sample) + directory_name = File.join(Rails.root, 'db', 'seed', dog[:name].downcase.to_s, '*') Dir.glob(directory_name).each do |filename| - if !dog.images.any?{|i| i.filename == filename} - dog.images.attach(io: File.open(filename), filename: filename.split("/").pop) + unless dog.images.any? { |i| i.filename == filename } + dog.images.attach(io: File.open(filename), filename: filename.split('/').pop) sleep 1 end end From 4cc5ae1f4923607c4c5bc45563854a9841b7d3b9 Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sun, 8 Nov 2020 17:53:17 -0500 Subject: [PATCH 3/8] only signed-in users can view dogs --- app/controllers/dogs_controller.rb | 2 +- app/views/dogs/_thumbnail.html.erb | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index 0330cd27..40598d7c 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -1,5 +1,5 @@ class DogsController < ApplicationController - before_action :set_dog, only: %i[show edit update destroy] + before_action :authenticate_user!, :set_dog, only: %i[show edit update destroy] # GET /dogs # GET /dogs.json diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 163d66c1..d84e6c91 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -1,7 +1,10 @@ + +

<%= dog.name %>

<%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %>
-
+ + From a7bec0b9ea0f99b3a95b9bf54c48c7fc565425b8 Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sun, 8 Nov 2020 19:40:46 -0500 Subject: [PATCH 4/8] Allow editing only by owner --- app/controllers/dogs_controller.rb | 10 ++++++++-- app/views/dogs/index.html.erb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index 40598d7c..be706f25 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -9,7 +9,10 @@ def index # GET /dogs/1 # GET /dogs/1.json - def show; end + def show + @user = User.find(params[:id]) + redirect_to new_user_session_path unless @user == current_user + end # GET /dogs/new def new @@ -25,7 +28,6 @@ def create @dog = Dog.new(dog_params) @dog.user_id = current_user.id respond_to do |format| - byebug if @dog.save @dog.images.attach(params[:dog][:image]) if params[:dog][:image].present? @@ -75,4 +77,8 @@ def set_dog def dog_params params.require(:dog).permit(:name, :description, :images, :user_id) end + + # def redirect_user + # redirect_to new_user_session_path unless @user == current_user + # end end diff --git a/app/views/dogs/index.html.erb b/app/views/dogs/index.html.erb index d51fb418..dd0bdeb2 100644 --- a/app/views/dogs/index.html.erb +++ b/app/views/dogs/index.html.erb @@ -1,4 +1,4 @@ <%= render partial: 'thumbnail', collection: @dogs, as: :dog %> -<%= will_paginate @dogs, :page_links => false %> +<%= will_paginate @dogs, page_links: false %> From 46da8ed180172b604d8190878e39990f06cd69dc Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sun, 8 Nov 2020 20:59:21 -0500 Subject: [PATCH 5/8] Add the ability to for a user to input multiple dog images on new dog form --- app/controllers/dogs_controller.rb | 5 +++-- app/views/dogs/_form.html.erb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index be706f25..3d723c4c 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -11,7 +11,7 @@ def index # GET /dogs/1.json def show @user = User.find(params[:id]) - redirect_to new_user_session_path unless @user == current_user + redirect_to root_path unless @user == current_user end # GET /dogs/new @@ -27,6 +27,7 @@ def edit; end def create @dog = Dog.new(dog_params) @dog.user_id = current_user.id + byebug respond_to do |format| if @dog.save @dog.images.attach(params[:dog][:image]) if params[:dog][:image].present? @@ -75,7 +76,7 @@ def set_dog # Never trust parameters from the scary internet, only allow the white list through. def dog_params - params.require(:dog).permit(:name, :description, :images, :user_id) + params.require(:dog).permit(:name, :description, :user_id, images: []) end # def redirect_user diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index 6dfc7dc9..be19e565 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -1,7 +1,7 @@ <%= simple_form_for @dog do |f| %> <%= f.input :name %> <%= f.input :description, as: :text %> - <%= f.input :image, as: :file %> + <%= f.file_field :image, as: :file, accept: "image/*", multiple: true%> <% if @dog.images.any? %> <%= image_tag @dog.images.first %> From 73bb940e7ad2dfdd29ab66bb8e9dfa18325ea454 Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sun, 8 Nov 2020 22:13:14 -0500 Subject: [PATCH 6/8] Add the ability to for a user to input multiple dog images on edit form --- app/views/dogs/_form.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index be19e565..b355549e 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -4,7 +4,10 @@ <%= f.file_field :image, as: :file, accept: "image/*", multiple: true%> <% if @dog.images.any? %> - <%= image_tag @dog.images.first %> + <% for dog_image in @dog.images %> + <%= image_tag dog_image %> + <% end %> + <% end %> <%= f.button :submit %> From 2a20d190c65416881cdf62a75d16c9c3ccfb31d9 Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Sun, 8 Nov 2020 23:45:26 -0500 Subject: [PATCH 7/8] Display the ad.jpg image (saved at app/assets/images/ad.jpg) after every 2 dogs in the index page, to simulate advertisements in a feed --- app/assets/stylesheets/application.css | 11 ++++++++--- app/controllers/dogs_controller.rb | 5 ++--- app/views/dogs/_thumbnail.html.erb | 27 +++++++++++++++++++------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index edb771d6..5efb175f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,7 +15,12 @@ */ header { - align-items: center; - display: flex; - justify-content: space-between; + align-items: center; + display: flex; + justify-content: space-between; +} + +.dog-ad { + padding: 10px; + width: 30%; } diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index 3d723c4c..e8baa926 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -10,8 +10,8 @@ def index # GET /dogs/1 # GET /dogs/1.json def show - @user = User.find(params[:id]) - redirect_to root_path unless @user == current_user + # @user = User.find(params[:id]) + # redirect_to root_path unless @user == current_user end # GET /dogs/new @@ -27,7 +27,6 @@ def edit; end def create @dog = Dog.new(dog_params) @dog.user_id = current_user.id - byebug respond_to do |format| if @dog.save @dog.images.attach(params[:dog][:image]) if params[:dog][:image].present? diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index d84e6c91..074f02d4 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -1,10 +1,23 @@ - - -
-

<%= dog.name %>

- <%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %> -
-
+
+ +
+

<%= dog.name %>

+ <%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %> + +
+
+ + <% if dog.id % 2 == 0%> +
+
+

Collar for Sale!

+ <%= image_tag "ad.jpg", class: "collar-photo", alt: "new advert" %> +
+
+ <% end %> +
+ + From abc394f033cfcc8e7365b7455ea15ee95590407e Mon Sep 17 00:00:00 2001 From: Hamidou Diallo Date: Tue, 10 Nov 2020 15:37:12 -0500 Subject: [PATCH 8/8] Allow users to like other dogs (not their own) --- Gemfile.lock | 3 -- app/assets/javascripts/likes.coffee | 3 ++ app/assets/stylesheets/likes.scss | 3 ++ app/controllers/dogs_controller.rb | 10 +++--- app/controllers/likes_controller.rb | 39 +++++++++++++++++++++++ app/helpers/likes_helper.rb | 2 ++ app/models/dog.rb | 1 + app/models/like.rb | 4 +++ app/models/user.rb | 3 +- app/views/dogs/_form.html.erb | 1 - app/views/dogs/_thumbnail.html.erb | 1 - app/views/dogs/show.html.erb | 19 +++++++++-- config/routes.rb | 6 ++-- db/migrate/20201109223410_create_likes.rb | 10 ++++++ db/schema.rb | 11 ++++++- spec/controllers/likes_controller_spec.rb | 5 +++ spec/factories/likes.rb | 7 ++++ spec/helpers/likes_helper_spec.rb | 15 +++++++++ spec/models/like_spec.rb | 5 +++ spec/rails_helper.rb | 5 ++- 20 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 app/assets/javascripts/likes.coffee create mode 100644 app/assets/stylesheets/likes.scss create mode 100644 app/controllers/likes_controller.rb create mode 100644 app/helpers/likes_helper.rb create mode 100644 app/models/like.rb create mode 100644 db/migrate/20201109223410_create_likes.rb create mode 100644 spec/controllers/likes_controller_spec.rb create mode 100644 spec/factories/likes.rb create mode 100644 spec/helpers/likes_helper_spec.rb create mode 100644 spec/models/like_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 56c77900..4f540688 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,8 +84,6 @@ GEM factory_bot_rails (5.2.0) factory_bot (~> 5.2.0) railties (>= 4.2.0) - faker (2.12.0) - i18n (>= 1.6, < 2) ffi (1.13.1) globalid (0.4.2) activesupport (>= 4.2.0) @@ -271,7 +269,6 @@ DEPENDENCIES coffee-rails (~> 4.2) devise factory_bot_rails - faker (~> 2.12) jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) pry diff --git a/app/assets/javascripts/likes.coffee b/app/assets/javascripts/likes.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/likes.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/likes.scss b/app/assets/stylesheets/likes.scss new file mode 100644 index 00000000..dacd946d --- /dev/null +++ b/app/assets/stylesheets/likes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Likes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/dogs_controller.rb b/app/controllers/dogs_controller.rb index e8baa926..ceba6ce8 100644 --- a/app/controllers/dogs_controller.rb +++ b/app/controllers/dogs_controller.rb @@ -12,6 +12,8 @@ def index def show # @user = User.find(params[:id]) # redirect_to root_path unless @user == current_user + # Fetches current user's likes for show view template + @like = Like.where(user_id: current_user.id).where(dog_id: @dog.id).first if current_user end # GET /dogs/new @@ -27,6 +29,7 @@ def edit; end def create @dog = Dog.new(dog_params) @dog.user_id = current_user.id + respond_to do |format| if @dog.save @dog.images.attach(params[:dog][:image]) if params[:dog][:image].present? @@ -74,11 +77,8 @@ def set_dog end # Never trust parameters from the scary internet, only allow the white list through. + # updated dog_params to handle multiple images def dog_params - params.require(:dog).permit(:name, :description, :user_id, images: []) + params.require(:dog).permit(:name, :description, images: []) end - - # def redirect_user - # redirect_to new_user_session_path unless @user == current_user - # end end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb new file mode 100644 index 00000000..e306eaf9 --- /dev/null +++ b/app/controllers/likes_controller.rb @@ -0,0 +1,39 @@ +class LikesController < ApplicationController + before_action :authenticate_user!, :set_likes, only: %i[destroy] + + def new + @like = Like.new + end + + def create + @like = Like.new(like_params) + @like.user_id = current_user.id + @dog = Dog.find(params[:dog_id]) + + respond_to do |format| + if @like.save + format.html { redirect_to @dog, notice: 'Like was successfully created.' } + format.json { render :show, status: :created, location: @dog } + else + format.json { render json: @like.errors, status: :unprocessable_entity } + end + end + end + + def edit; end + + def update; end + + def destroy; end + + private + + def set_likes + @like = Like.find(params[:id]) + @dog = Dog.find(@like.dog.id) + end + + def like_params + params.permit(:user_id, :dog_id) + end +end diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb new file mode 100644 index 00000000..a78a7596 --- /dev/null +++ b/app/helpers/likes_helper.rb @@ -0,0 +1,2 @@ +module LikesHelper +end diff --git a/app/models/dog.rb b/app/models/dog.rb index 8be9b127..22df904a 100644 --- a/app/models/dog.rb +++ b/app/models/dog.rb @@ -1,4 +1,5 @@ class Dog < ApplicationRecord has_many_attached :images belongs_to :user + has_many :likes, dependent: :destroy end diff --git a/app/models/like.rb b/app/models/like.rb new file mode 100644 index 00000000..dc452b29 --- /dev/null +++ b/app/models/like.rb @@ -0,0 +1,4 @@ +class Like < ApplicationRecord + belongs_to :user + belongs_to :dog +end diff --git a/app/models/user.rb b/app/models/user.rb index 625056f6..f61fd7f5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,5 +3,6 @@ class User < ApplicationRecord # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - has_many :dogs + has_many :dogs, dependent: :destroy + has_many :likes, dependent: :destroy end diff --git a/app/views/dogs/_form.html.erb b/app/views/dogs/_form.html.erb index b355549e..4bf89600 100644 --- a/app/views/dogs/_form.html.erb +++ b/app/views/dogs/_form.html.erb @@ -7,7 +7,6 @@ <% for dog_image in @dog.images %> <%= image_tag dog_image %> <% end %> - <% end %> <%= f.button :submit %> diff --git a/app/views/dogs/_thumbnail.html.erb b/app/views/dogs/_thumbnail.html.erb index 074f02d4..ea04bf57 100644 --- a/app/views/dogs/_thumbnail.html.erb +++ b/app/views/dogs/_thumbnail.html.erb @@ -4,7 +4,6 @@

<%= dog.name %>

<%= image_tag url_for(dog.images.first), class: "dog-photo", alt: "Photo of #{dog.name}" %> -
diff --git a/app/views/dogs/show.html.erb b/app/views/dogs/show.html.erb index e748b206..42252c67 100644 --- a/app/views/dogs/show.html.erb +++ b/app/views/dogs/show.html.erb @@ -6,8 +6,21 @@

<%= @dog.description %>

- <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> -
- <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> +
+ <%= "#{@dog.likes.count} likes" %> +
+ <% if current_user && current_user.id != @dog.user_id %> + <% if !@like %> + + <% end %> + <% end %> +
+ +
+
+ <%= link_to "Edit #{@dog.name}'s Profile", edit_dog_path %> +
+ <%= link_to "Delete #{@dog.name}'s Profile", dog_path, method: :delete, data: { confirm: 'Are you sure?' } %> +
diff --git a/config/routes.rb b/config/routes.rb index 06b01adc..36ba9abc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :users - resources :dogs - root to: "dogs#index" + resources :dogs do + resources :likes, only: %i[create] + end + root to: 'dogs#index' end diff --git a/db/migrate/20201109223410_create_likes.rb b/db/migrate/20201109223410_create_likes.rb new file mode 100644 index 00000000..60f6dcea --- /dev/null +++ b/db/migrate/20201109223410_create_likes.rb @@ -0,0 +1,10 @@ +class CreateLikes < ActiveRecord::Migration[5.2] + def change + create_table :likes do |t| + t.references :user, foreign_key: true + t.references :dog, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3bd8e569..f3ba44a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_11_08_205017) do +ActiveRecord::Schema.define(version: 2020_11_09_223410) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -44,6 +44,15 @@ t.index ["user_id"], name: "index_dogs_on_user_id" end + create_table "likes", force: :cascade do |t| + t.integer "user_id" + t.integer "dog_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["dog_id"], name: "index_likes_on_dog_id" + t.index ["user_id"], name: "index_likes_on_user_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.string "email" diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb new file mode 100644 index 00000000..6c4e73de --- /dev/null +++ b/spec/controllers/likes_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe LikesController, type: :controller do + +end diff --git a/spec/factories/likes.rb b/spec/factories/likes.rb new file mode 100644 index 00000000..2f6fd75c --- /dev/null +++ b/spec/factories/likes.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :like do + like_count { "MyString" } + user { nil } + dog { nil } + end +end diff --git a/spec/helpers/likes_helper_spec.rb b/spec/helpers/likes_helper_spec.rb new file mode 100644 index 00000000..bc196878 --- /dev/null +++ b/spec/helpers/likes_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the LikesHelper. For example: +# +# describe LikesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe LikesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb new file mode 100644 index 00000000..76ea93df --- /dev/null +++ b/spec/models/like_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Like, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4e322aeb..22901f46 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,14 +1,13 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production -abort("The Rails environment is running in production mode!") if Rails.env.production? +abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! require 'support/factory_bot' - # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end