fix food ndbn selection caching; upgrade gems and ruby

This commit is contained in:
Dan Elbert 2021-05-09 17:38:08 -05:00
parent 6dcbb80794
commit 66f6b5346d
13 changed files with 2162 additions and 2719 deletions

View File

@ -1 +1 @@
2.7.1
3.0.1

View File

@ -1,6 +1,6 @@
FROM ruby:2.7.1-buster
FROM ruby:3.0.1-buster
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get dist-upgrade -y && \
@ -37,7 +37,7 @@ RUN yarn install --production=true --frozen-lockfile
COPY . .
# Compile assets
RUN bundle exec rails webpacker:clobber webpacker:compile
RUN env RAILS_ENV=production bundle exec rails webpacker:clobber webpacker:compile
ENV PORT=80
EXPOSE 80

24
Gemfile
View File

@ -1,20 +1,20 @@
source 'https://rubygems.org'
gem 'rails', '6.0.3.2'
gem 'pg', '~> 1.2.2'
gem 'rails', '6.1.3.2'
gem 'pg', '~> 1.2.3'
gem 'webpacker', '5.1.1'
gem 'webpacker', '5.3.0'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'oj', '~> 3.10.6'
gem 'oj', '~> 3.11.5'
gem 'kaminari', '~> 1.2.0'
gem 'kaminari', '~> 1.2.1'
gem 'unitwise', '~> 2.2.0'
gem 'redcarpet', '~> 3.5.0'
gem 'redcarpet', '~> 3.5.1'
gem 'dalli', '~> 2.7.10'
gem 'puma', '~> 4.3.3'
gem 'bcrypt', '~> 3.1.13'
gem 'dalli', '~> 2.7.11'
gem 'puma', '~> 5.3'
gem 'bcrypt', '~> 3.1.16'
gem 'tzinfo-data'
group :development, :test do
@ -22,9 +22,9 @@ group :development, :test do
gem 'guard', '~> 2.16.2'
gem 'guard-rspec', require: false
gem 'rspec-rails', '~> 3.9.1'
gem 'rspec-rails', '~> 5.0.1'
gem 'rails-controller-testing'
gem 'factory_bot_rails', '~> 5.2.0'
gem 'database_cleaner', '~> 1.8.4'
gem 'factory_bot_rails', '~> 6.2.0'
gem 'database_cleaner', '~> 2.0.1'
end

View File

@ -1,78 +1,87 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.3.2)
actionpack (= 6.0.3.2)
actioncable (6.1.3.2)
actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.3.2)
actionpack (= 6.0.3.2)
activejob (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
actionmailbox (6.1.3.2)
actionpack (= 6.1.3.2)
activejob (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (>= 2.7.1)
actionmailer (6.0.3.2)
actionpack (= 6.0.3.2)
actionview (= 6.0.3.2)
activejob (= 6.0.3.2)
actionmailer (6.1.3.2)
actionpack (= 6.1.3.2)
actionview (= 6.1.3.2)
activejob (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.3.2)
actionview (= 6.0.3.2)
activesupport (= 6.0.3.2)
rack (~> 2.0, >= 2.0.8)
actionpack (6.1.3.2)
actionview (= 6.1.3.2)
activesupport (= 6.1.3.2)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.3.2)
actionpack (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
actiontext (6.1.3.2)
actionpack (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
nokogiri (>= 1.8.5)
actionview (6.0.3.2)
activesupport (= 6.0.3.2)
actionview (6.1.3.2)
activesupport (= 6.1.3.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.3.2)
activesupport (= 6.0.3.2)
activejob (6.1.3.2)
activesupport (= 6.1.3.2)
globalid (>= 0.3.6)
activemodel (6.0.3.2)
activesupport (= 6.0.3.2)
activerecord (6.0.3.2)
activemodel (= 6.0.3.2)
activesupport (= 6.0.3.2)
activestorage (6.0.3.2)
actionpack (= 6.0.3.2)
activejob (= 6.0.3.2)
activerecord (= 6.0.3.2)
marcel (~> 0.3.1)
activesupport (6.0.3.2)
activemodel (6.1.3.2)
activesupport (= 6.1.3.2)
activerecord (6.1.3.2)
activemodel (= 6.1.3.2)
activesupport (= 6.1.3.2)
activestorage (6.1.3.2)
actionpack (= 6.1.3.2)
activejob (= 6.1.3.2)
activerecord (= 6.1.3.2)
activesupport (= 6.1.3.2)
marcel (~> 1.0.0)
mini_mime (~> 1.0.2)
activesupport (6.1.3.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
bcrypt (3.1.15)
bootsnap (1.4.7)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
bcrypt (3.1.16)
bootsnap (1.7.5)
msgpack (~> 1.0)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.1.7)
concurrent-ruby (1.1.8)
crass (1.0.6)
dalli (2.7.10)
database_cleaner (1.8.5)
dalli (2.7.11)
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.1)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
diff-lcs (1.4.4)
erubi (1.9.0)
factory_bot (5.2.0)
activesupport (>= 4.2.0)
factory_bot_rails (5.2.0)
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
ffi (1.13.1)
erubi (1.10.0)
factory_bot (6.2.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
ffi (1.15.0)
formatador (0.2.5)
globalid (0.4.2)
activesupport (>= 4.2.0)
@ -90,7 +99,7 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
i18n (1.8.5)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
kaminari (1.2.1)
activesupport (>= 4.1.0)
@ -105,59 +114,59 @@ GEM
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
liner (0.2.4)
listen (3.2.1)
listen (3.5.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.6.0)
loofah (2.9.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.7)
lumberjack (1.2.8)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
marcel (1.0.1)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (1.0.0)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.1)
msgpack (1.3.3)
mini_mime (1.0.3)
mini_portile2 (2.5.1)
minitest (5.14.4)
msgpack (1.4.2)
nenv (0.3.0)
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
nio4r (2.5.7)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
oj (3.10.8)
oj (3.11.5)
parslet (1.8.2)
pg (1.2.3)
pry (0.13.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
puma (4.3.5)
puma (5.3.0)
nio4r (~> 2.0)
racc (1.5.2)
rack (2.2.3)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.3.2)
actioncable (= 6.0.3.2)
actionmailbox (= 6.0.3.2)
actionmailer (= 6.0.3.2)
actionpack (= 6.0.3.2)
actiontext (= 6.0.3.2)
actionview (= 6.0.3.2)
activejob (= 6.0.3.2)
activemodel (= 6.0.3.2)
activerecord (= 6.0.3.2)
activestorage (= 6.0.3.2)
activesupport (= 6.0.3.2)
bundler (>= 1.3.0)
railties (= 6.0.3.2)
rails (6.1.3.2)
actioncable (= 6.1.3.2)
actionmailbox (= 6.1.3.2)
actionmailer (= 6.1.3.2)
actionpack (= 6.1.3.2)
actiontext (= 6.1.3.2)
actionview (= 6.1.3.2)
activejob (= 6.1.3.2)
activemodel (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
bundler (>= 1.15.0)
railties (= 6.1.3.2)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
@ -168,61 +177,61 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.0.3.2)
actionpack (= 6.0.3.2)
activesupport (= 6.0.3.2)
railties (6.1.3.2)
actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rake (13.0.1)
rb-fsevent (0.10.4)
thor (~> 1.0)
rake (13.0.3)
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
redcarpet (3.5.0)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
redcarpet (3.5.1)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (3.9.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
semantic_range (2.3.0)
rspec-support (~> 3.10.0)
rspec-rails (5.0.1)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
semantic_range (3.0.0)
shellany (0.0.1)
signed_multiset (0.2.1)
sprockets (4.0.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.4.2)
thor (1.0.1)
thor (1.1.0)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
tzinfo-data (1.2020.1)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2021.1)
tzinfo (>= 1.0.0)
unitwise (2.2.0)
liner (~> 0.2)
memoizable (~> 0.4)
parslet (~> 1.5)
signed_multiset (~> 0.2)
webpacker (5.1.1)
webpacker (5.3.0)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
@ -230,31 +239,31 @@ GEM
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.4.0)
zeitwerk (2.4.2)
PLATFORMS
ruby
DEPENDENCIES
bcrypt (~> 3.1.13)
bcrypt (~> 3.1.16)
bootsnap (>= 1.1.0)
dalli (~> 2.7.10)
database_cleaner (~> 1.8.4)
factory_bot_rails (~> 5.2.0)
dalli (~> 2.7.11)
database_cleaner (~> 2.0.1)
factory_bot_rails (~> 6.2.0)
guard (~> 2.16.2)
guard-rspec
kaminari (~> 1.2.0)
oj (~> 3.10.6)
pg (~> 1.2.2)
puma (~> 4.3.3)
rails (= 6.0.3.2)
kaminari (~> 1.2.1)
oj (~> 3.11.5)
pg (~> 1.2.3)
puma (~> 5.3)
rails (= 6.1.3.2)
rails-controller-testing
redcarpet (~> 3.5.0)
rspec-rails (~> 3.9.1)
redcarpet (~> 3.5.1)
rspec-rails (~> 5.0.1)
sqlite3 (~> 1.4.2)
tzinfo-data
unitwise (~> 2.2.0)
webpacker (= 5.1.1)
webpacker (= 5.3.0)
BUNDLED WITH
2.1.4
2.2.17

View File

@ -25,7 +25,7 @@ class NotesController < ApplicationController
respond_to do |format|
if @note.save
format.html { redirect_to notes_path, notice: 'Note was successfully created.' }
format.json { render :show, status: :created, location: @note }
format.json { render json: NoteSerializer.for(@note), status: :created, location: @note }
else
format.html { render :new }
format.json { render json: @note.errors, status: :unprocessable_entity }
@ -40,7 +40,7 @@ class NotesController < ApplicationController
respond_to do |format|
if @note.update(note_params)
format.html { redirect_to notes_path, notice: 'Note was successfully updated.' }
format.json { render :show, status: :ok, location: @note }
format.json { render json: NoteSerializer.for(@note), status: :ok, location: @note }
else
format.html { render :edit }
format.json { render json: @note.errors, status: :unprocessable_entity }

View File

@ -12,7 +12,7 @@ class DensityValidator < ActiveModel::EachValidator
end
unless valid
record.errors[attribute] << (options[:message] || msg)
record.errors.add(attribute, message: (options[:message] || msg))
end
end
end

View File

@ -21,6 +21,14 @@ class Food < Ingredient
end
end
def cache_key
if !self.persisted? && self.ndbn.present?
"#{super}/#{self.ndbn}"
else
super
end
end
def custom_units
units = {}
food_units.each do |fu|

View File

@ -47,6 +47,12 @@ module.exports = function(api) {
loose: true
}
],
[
'@babel/plugin-proposal-private-methods',
{
"loose": true
}
],
[
'@babel/plugin-proposal-object-rest-spread',
{

View File

@ -374,7 +374,7 @@ class UsdaImporter
sorted_files.each do |name, filename|
data = FILES[name]
opened_files[name] = CSV.open(filename, 'r:iso-8859-1:utf-8', csv_options(data))
opened_files[name] = CSV.open(filename, 'r:iso-8859-1:utf-8', **csv_options(data))
end
build_enumerator(opened_files).each_slice(500) do |slice|

View File

@ -1,26 +1,26 @@
{
"dependencies": {
"@rails/webpacker": "5.1.1",
"@tweenjs/tween.js": "^18.5.0",
"@rails/webpacker": "5.3.0",
"@tweenjs/tween.js": "^18.6.4",
"autosize": "^4.0.2",
"bulma": "^0.8.0",
"cheerio": "^1.0.0-rc.3",
"css-loader": "^3.4.2",
"lodash": "^4.17.15",
"bulma": "^0.8.2",
"cheerio": "^1.0.0-rc.9",
"css-loader": "^5.2.4",
"lodash": "^4.17.21",
"svg-loader": "^0.0.2",
"url-loader": "3.0.0",
"vue": "^2.6.11",
"vue-loader": "^15.8.3",
"url-loader": "4.1.1",
"vue": "^2.6.12",
"vue-loader": "^15.9.6",
"vue-progressbar": "^0.7.5",
"vue-resize": "^0.4.5",
"vue-router": "^3.1.5",
"vue-template-compiler": "^2.6.11",
"vuex": "^3.1.2",
"vue-resize": "^1.0.1",
"vue-router": "^3.5.1",
"vue-template-compiler": "^2.6.12",
"vuex": "^3.6.2",
"vuex-router-sync": "^5.0.0",
"webpack": "^4.41.5"
"webpack": "^4.46.0"
},
"devDependencies": {
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1"
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.2"
}
}

View File

@ -39,32 +39,11 @@ RSpec.describe NotesController, type: :controller do
end
end
describe "GET #new" do
it "assigns a new note as @note" do
get :new, params: {}, session: valid_session
expect(assigns(:note)).to be_a_new(Note)
end
end
describe "GET #edit" do
it "assigns the requested note as @note" do
note = create(:note, user: user)
get :edit, params: {id: note.to_param}, session: valid_session
expect(assigns(:note)).to eq(note)
end
it 'redirects if note is not owned' do
note = create(:note)
get :edit, params: {id: note.to_param}, session: valid_session
expect(response).to redirect_to(root_path)
end
end
describe "POST #create" do
context "with valid params" do
it "creates a new Note" do
expect {
post :create, params: {note: valid_attributes}, session: valid_session
post :create, params: {note: valid_attributes}, session: valid_session, as: :json
}.to change(Note, :count).by(1)
end

View File

@ -47,4 +47,30 @@ RSpec.describe Food, type: :model do
end
end
describe '#cache_key' do
it 'has a key for new foods' do
f = Food.new
expect(f.cache_key).to eq "foods/new"
expect(f.cache_version).to be_nil
end
it 'has a different key for new foods with an ndbn' do
f = Food.new(ndbn: '123456')
expect(f.cache_key).to eq "foods/new/123456"
expect(f.cache_version).to be_nil
end
it 'has a key for persisted foods' do
f = create(:food)
expect(f.cache_key).to eq "foods/#{f.id}"
expect(f.cache_version).not_to be_nil
end
it 'has the same key for persisted foods with an ndbn' do
f = create(:food, ndbn: '123456')
expect(f.cache_key).to eq "foods/#{f.id}"
expect(f.cache_version).not_to be_nil
end
end
end

4477
yarn.lock

File diff suppressed because it is too large Load Diff