From 844f68ef4c2fa1e197bbdb2883af8d2e66236a19 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 24 Nov 2016 18:48:01 +0000 Subject: [PATCH 01/25] Auto-deploy to production on successful merge I *think* this is all that's necessary, though it's a bit hard to test :-) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0fc8e1e54..f01bdbeae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,7 @@ deploy: repo: Growstuff/growstuff app: dev: growstuff-staging + master: growstuff-prod travis_deploy: tranquil-basin-3130 travis_containers: tranquil-basin-3130 run: From 20c72e1205930357bf0df81542d423137dc00320 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 26 Nov 2016 13:43:04 +1300 Subject: [PATCH 02/25] Upgrading poltergeist --- Gemfile | 7 +++++-- Gemfile.lock | 16 ++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 0a445dc62..e752f553a 100644 --- a/Gemfile +++ b/Gemfile @@ -110,14 +110,17 @@ group :development, :test do gem 'capybara' # integration tests gem 'capybara-email' # integration tests for email gem 'capybara-screenshot' # for test debugging - gem 'poltergeist', '~> 1.6' # for headless JS testing + gem 'poltergeist' # for headless JS testing gem 'i18n-tasks' # adds tests for finding missing and unused translations gem 'selenium-webdriver' - gem "codeclimate-test-reporter", group: :test, require: nil gem "active_merchant-paypal-bogus-gateway" gem 'rubocop', require: false end +group :test do + gem 'codeclimate-test-reporter', require: false +end + group :travis do gem 'heroku-api' end diff --git a/Gemfile.lock b/Gemfile.lock index 8f6230ac2..9455fd3c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,7 +48,8 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.4.0) + addressable (2.5.0) + public_suffix (~> 2.0, >= 2.0.2) arel (6.0.3) ast (2.3.0) autoprefixer-rails (6.4.0.2) @@ -74,7 +75,7 @@ GEM builder (3.2.2) byebug (9.0.5) cancancan (1.15.0) - capybara (2.8.0) + capybara (2.10.1) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -277,9 +278,8 @@ GEM multipart-post (2.0.0) nenv (0.3.0) newrelic_rpm (3.16.1.320) - nokogiri (1.6.8) + nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) @@ -317,10 +317,9 @@ GEM parser (2.3.1.2) ast (~> 2.2) pg (0.18.4) - pkg-config (1.1.7) plupload-rails (1.2.1) rails (>= 3.1) - poltergeist (1.10.0) + poltergeist (1.11.0) capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) @@ -329,9 +328,10 @@ GEM coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) + public_suffix (2.0.4) quiet_assets (1.1.0) railties (>= 3.1, < 5.0) - rack (1.6.4) + rack (1.6.5) rack-protection (1.5.3) rack rack-test (0.6.3) @@ -540,7 +540,7 @@ DEPENDENCIES omniauth-flickr (>= 0.0.15) omniauth-twitter pg - poltergeist (~> 1.6) + poltergeist pry quiet_assets rails (~> 4.2.1) From 38fbc52a6f03f9c0b6b1b40ee83bd096758943d1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 10:17:01 +1300 Subject: [PATCH 03/25] String interp doesn't need .to_s --- .rubocop_todo.yml | 6 ------ spec/views/seeds/index.rss.haml_spec.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7f137a1b9..737bc1082 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -73,12 +73,6 @@ Lint/ParenthesesAsGroupedExpression: - 'spec/models/member_spec.rb' - 'spec/views/plantings/show.html.haml_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Lint/StringConversionInInterpolation: - Exclude: - - 'spec/views/seeds/index.rss.haml_spec.rb' - # Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. diff --git a/spec/views/seeds/index.rss.haml_spec.rb b/spec/views/seeds/index.rss.haml_spec.rb index 5e1ceb62f..72f56fa0a 100644 --- a/spec/views/seeds/index.rss.haml_spec.rb +++ b/spec/views/seeds/index.rss.haml_spec.rb @@ -42,7 +42,7 @@ describe 'seeds/index.rss.haml' do end it 'shows the plant_before date' do - rendered.should have_content "Plant before: #{@seed.plant_before.to_s}" + rendered.should have_content "Plant before: #{@seed.plant_before}" end it 'mentions that one seed is tradable' do From 702bbeb7243e5f0012d18ab6957a4c6b50cb5eee Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 10:21:11 +1300 Subject: [PATCH 04/25] "[Member]'s garden" link to garden, not member --- app/views/gardens/_thumbnail.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/gardens/_thumbnail.html.haml b/app/views/gardens/_thumbnail.html.haml index 8c00d25ec..bc08be246 100644 --- a/app/views/gardens/_thumbnail.html.haml +++ b/app/views/gardens/_thumbnail.html.haml @@ -1,7 +1,7 @@ .panel.panel-success .panel-heading %h3.panel-title - = link_to "#{garden.owner.login_name}'s garden", garden.owner + = link_to "#{garden.owner.login_name}'s garden", garden - if can? :edit, garden %a.pull-right{:href => edit_garden_path(garden), :role => "button", :id => "edit_garden_glyphicon"} %span.glyphicon.glyphicon-pencil{:title => "Edit"} From 9cb58ab0c98ded57b7de6bdebb0ad6b24015b3a3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 13:08:53 +1300 Subject: [PATCH 05/25] Wrapped the phantomjs downloading in travis.yml --- .travis.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0fc8e1e54..5d24c9f89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,14 @@ rvm: - 2.3.1 before_install: - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH - - if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi - - if [ $(phantomjs --version) != '2.1.1' ]; then wget https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi - - if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi + - > + if [ $(phantomjs --version) != '2.1.1' ]; then + PHANTOM_URL=https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2; + rm -rf $PWD/travis_phantomjs; + mkdir -p $PWD/travis_phantomjs; + wget $PHANTOM_URL -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; + tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; + fi - phantomjs --version before_script: - psql -c 'create database growstuff_test;' -U postgres From 7fcd3cba8d1471b4c3a7a50ad35eac63590764ae Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 13:22:10 +1300 Subject: [PATCH 06/25] Changed phantomjs url to project official --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5d24c9f89..a13ca40d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_install: - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH - > if [ $(phantomjs --version) != '2.1.1' ]; then - PHANTOM_URL=https://assets.membergetmember.co/software/phantomjs-2.1.1-linux-x86_64.tar.bz2; + PHANTOM_URL=https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2; rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; wget $PHANTOM_URL -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; From 167417a7119ecae2de75161a4ed184c0bcf991c3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 13:24:02 +1300 Subject: [PATCH 07/25] Indent travis.yml correctly --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index a13ca40d9..f3397e9c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ env: global: secure: "Z5TpM2jEX4UCvNePnk/LwltQX48U2u9BRc+Iypr1x9QW2o228QJhPIOH39a8RMUrepGnkQIq9q3ZRUn98RfrJz1yThtlNFL3NmzdQ57gKgjGwfpa0e4Dwj/ZJqV2D84tDGjvdVYLP7zzaYZxQcwk/cgNpzKf/jq97HLNP7CYuf4=" rvm: -- 2.3.1 + - 2.3.1 before_install: - export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH - > @@ -24,13 +24,13 @@ before_install: fi - phantomjs --version before_script: -- psql -c 'create database growstuff_test;' -U postgres + - psql -c 'create database growstuff_test;' -U postgres script: -- bundle exec rubocop --display-cop-names --rails -- script/gemfile_check -- bundle exec script/check_contributors_md -- bundle exec rake db:migrate --trace -- bundle exec rspec spec/ + - bundle exec rubocop --display-cop-names --rails + - script/gemfile_check + - bundle exec script/check_contributors_md + - bundle exec rake db:migrate --trace + - bundle exec rspec spec/ services: - elasticsearch before_deploy: From c76fb15cfd2a8a205117b6bbe723faa9cf03330d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 13:24:21 +1300 Subject: [PATCH 08/25] Add yamllint settings --- .yamllint | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .yamllint diff --git a/.yamllint b/.yamllint new file mode 100644 index 000000000..06876caa2 --- /dev/null +++ b/.yamllint @@ -0,0 +1,7 @@ +extends: relaxed + +rules: + # 80 chars should be enough, but don't fail if a line is longer + line-length: + max: 150 + level: warning From f52b828abe6c897fb8a94e9bd370b63d39756ca3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 13:27:45 +1300 Subject: [PATCH 09/25] Use rake to create database --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f3397e9c7..5bc80442c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: fi - phantomjs --version before_script: - - psql -c 'create database growstuff_test;' -U postgres + - bundle exec rake db:create db:migrate db:test:prepare script: - bundle exec rubocop --display-cop-names --rails - script/gemfile_check From 10c20c7f91bdab3ca43c7cf25be86f28c6e357ff Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 14:32:07 +1300 Subject: [PATCH 10/25] Narrow-ed regex on wikipedia url and more tests --- app/models/crop.rb | 2 +- spec/models/crop_spec.rb | 42 +++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 7de010b1e..865965b40 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -42,7 +42,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength ## Wikipedia urls are only necessary when approving a crop validates :en_wikipedia_url, format: { - with: /\Ahttps?:\/\/en\.wikipedia\.org\/wiki/, + with: /\Ahttps?:\/\/en\.wikipedia\.org\/wiki\/[[:alnum:]%_]+\z/, message: 'is not a valid English Wikipedia URL' }, if: :approved? diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 6ff1bd47b..375abc500 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -85,11 +85,43 @@ describe Crop do @crop.plantings.size.should eq 1 end - it 'validates en_wikipedia_url' do - @crop = FactoryGirl.build(:tomato, en_wikipedia_url: 'this is not valid') - @crop.should_not be_valid - @crop = FactoryGirl.build(:tomato, en_wikipedia_url: 'http://en.wikipedia.org/wiki/SomePage') - @crop.should be_valid + context "wikipedia url" do + subject { FactoryGirl.build(:tomato, en_wikipedia_url: wikipedia_url) } + + context 'not a url' do + let(:wikipedia_url) { 'this is not valid' } + it { expect(subject).not_to be_valid } + end + + context 'http url' do + let(:wikipedia_url) { 'http://en.wikipedia.org/wiki/SomePage' } + it { expect(subject).to be_valid } + end + + context 'with ssl' do + let(:wikipedia_url) { 'https://en.wikipedia.org/wiki/SomePage' } + it { expect(subject).to be_valid } + end + + context 'with utf8 macrons' do + let(:wikipedia_url) { 'https://en.wikipedia.org/wiki/Māori' } + it { expect(subject).to be_valid } + end + + context 'urlencoded' do + let(:wikipedia_url) { 'https://en.wikipedia.org/wiki/M%C4%81ori' } + it { expect(subject).to be_valid } + end + + context 'with new lines in url' do + let(:wikipedia_url) { 'http://en.wikipedia.org/wiki/SomePage\n\nBrendaRocks' } + it { expect(subject).not_to be_valid } + end + + context "with script tags in url" do + let(:wikipedia_url) { 'http://en.wikipedia.org/wiki/SomePage' } + it { expect(subject).not_to be_valid } + end end context 'varieties' do From 9cce0e39f6e66446a078b3790a7135529cf6e57b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 27 Nov 2016 14:52:07 +1300 Subject: [PATCH 11/25] Limit garden names to one line --- app/models/garden.rb | 2 +- spec/models/garden_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index 448d7d60e..332200f04 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -33,7 +33,7 @@ class Garden < ActiveRecord::Base validates :name, format: { - with: /\S/ + with: /\A\w+[\w ]+\z/ }, length: { maximum: 255 } diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 866e9bd7e..bfb53f1eb 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -23,11 +23,26 @@ describe Garden do garden.should_not be_valid end + it "allows numbers" do + garden = FactoryGirl.build(:garden, name: "100 vines of 2 kamo-kamo") + garden.should_not be_valid + end + + it "allows macrons" do + garden = FactoryGirl.build(:garden, name: "Kūmara and pūha patch") + garden.should_not be_valid + end + it "doesn't allow a name with only spaces" do garden = FactoryGirl.build(:garden, name: " ") garden.should_not be_valid end + it "doesn't allow a new lines in garden names" do + garden = FactoryGirl.build(:garden, name: "My garden\nI am a 1337 hacker") + garden.should_not be_valid + end + it "should have an owner" do garden.owner.should be_an_instance_of Member end From 7a90c020fc196b5e3e09f8499c77de86379490c0 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:28:07 +1000 Subject: [PATCH 12/25] bundle update thor tins term-ansicolor --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9455fd3c3..1903be636 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -451,14 +451,14 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - term-ansicolor (1.3.2) + term-ansicolor (1.4.0) tins (~> 1.0) terminal-table (1.6.0) - thor (0.19.1) + thor (0.19.3) thread (0.2.2) thread_safe (0.3.5) tilt (2.0.5) - tins (1.12.0) + tins (1.13.0) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.2) From 9bd1484a95c6ff574c9397842c6c0008cc2632cf Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:29:09 +1000 Subject: [PATCH 13/25] bundle update ruby_parser rb-fsevent redis --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1903be636..d59a10ad2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -371,10 +371,10 @@ GEM rainbow (2.1.0) raindrops (0.17.0) rake (11.2.2) - rb-fsevent (0.9.7) + rb-fsevent (0.9.8) rb-inotify (0.9.7) ffi (>= 0.5.0) - redis (3.3.1) + redis (3.3.2) responders (2.3.0) railties (>= 4.2.0, < 5.1) rspec (3.5.0) @@ -411,7 +411,7 @@ GEM ruby-progressbar (1.8.1) ruby-units (2.0.1) ruby_dep (1.4.0) - ruby_parser (3.8.2) + ruby_parser (3.8.3) sexp_processor (~> 4.1) rubyzip (1.2.0) sass (3.4.22) From eb1013f925865da503df27a1d322e113e1e78084 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:30:02 +1000 Subject: [PATCH 14/25] bundle update jwt kramdown excon --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d59a10ad2..a4568c537 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -161,7 +161,7 @@ GEM faraday multi_json erubis (2.7.0) - excon (0.51.0) + excon (0.54.0) execjs (2.7.0) factory_girl (4.7.0) activesupport (>= 3.0.0) @@ -243,12 +243,12 @@ GEM railties (>= 3.2) sprockets-rails json (1.8.3) - jwt (1.5.4) + jwt (1.5.6) kaminari (0.17.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) kgio (2.10.0) - kramdown (1.12.0) + kramdown (1.13.1) launchy (2.4.3) addressable (~> 2.3) leaflet-markercluster-rails (0.7.0) From 9c116f5887333b764916afcfb0ff1f2999dfc713 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:31:24 +1000 Subject: [PATCH 15/25] bundle update rspec-rails coveralls capybara-screenshot --- Gemfile.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a4568c537..00b802487 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,7 +85,7 @@ GEM capybara-email (2.5.0) capybara (~> 2.4) mail - capybara-screenshot (1.0.13) + capybara-screenshot (1.0.14) capybara (>= 1.0, < 3) launchy childprocess (0.5.9) @@ -124,10 +124,10 @@ GEM sass-rails (>= 4.0.3) concurrent-ruby (1.0.2) connection_pool (2.2.0) - coveralls (0.8.15) + coveralls (0.8.16) json (>= 1.8, < 3) simplecov (~> 0.12.0) - term-ansicolor (~> 1.3) + term-ansicolor (~> 1.3.0) thor (~> 0.19.1) tins (>= 1.6.0, < 2) csv_shaper (1.3.0) @@ -272,7 +272,7 @@ GEM mime-types-data (3.2016.0521) mimemagic (0.3.2) mini_portile2 (2.1.0) - minitest (5.9.0) + minitest (5.9.1) multi_json (1.11.3) multi_xml (0.5.5) multipart-post (2.0.0) @@ -370,7 +370,7 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (2.1.0) raindrops (0.17.0) - rake (11.2.2) + rake (11.3.0) rb-fsevent (0.9.8) rb-inotify (0.9.7) ffi (>= 0.5.0) @@ -385,7 +385,7 @@ GEM activemodel (>= 3.0) activesupport (>= 3.0) rspec-mocks (>= 2.99, < 4.0) - rspec-core (3.5.2) + rspec-core (3.5.4) rspec-support (~> 3.5.0) rspec-expectations (3.5.0) diff-lcs (>= 1.2.0, < 2.0) @@ -393,7 +393,7 @@ GEM rspec-mocks (3.5.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.5.0) - rspec-rails (3.5.1) + rspec-rails (3.5.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -451,7 +451,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - term-ansicolor (1.4.0) + term-ansicolor (1.3.2) tins (~> 1.0) terminal-table (1.6.0) thor (0.19.3) From 89c29ea73c289b23182f47498ccfa3e3e52ca054 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:32:43 +1000 Subject: [PATCH 16/25] bundle update pg --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 00b802487..559a61146 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -316,7 +316,7 @@ GEM mimemagic (~> 0.3.0) parser (2.3.1.2) ast (~> 2.2) - pg (0.18.4) + pg (0.19.0) plupload-rails (1.2.1) rails (>= 3.1) poltergeist (1.11.0) From 0fb9ea7a1136c5ae32a74ee67b7052ae383bb271 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:37:36 +1000 Subject: [PATCH 17/25] bundle update newrelic_rpm byebug --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 559a61146..49bffe861 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,7 +73,7 @@ GEM sass (>= 3.3.4) bootstrap_form (2.5.0) builder (3.2.2) - byebug (9.0.5) + byebug (9.0.6) cancancan (1.15.0) capybara (2.10.1) addressable @@ -277,7 +277,7 @@ GEM multi_xml (0.5.5) multipart-post (2.0.0) nenv (0.3.0) - newrelic_rpm (3.16.1.320) + newrelic_rpm (3.17.1.326) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) notiffany (0.1.1) From c08c038df148332f086af7d0926796627bed63a8 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:40:32 +1000 Subject: [PATCH 18/25] bundle update active_utils --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 49bffe861..ac9fde044 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,7 +24,7 @@ GEM actionpack active_merchant-paypal-bogus-gateway (0.1.0) activemerchant - active_utils (3.2.2) + active_utils (3.2.3) activesupport (>= 3.2, < 5.1.0) i18n activejob (4.2.7.1) From bd46c37f07feaeac337414f3f2c0614f8c18d113 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:42:03 +1000 Subject: [PATCH 19/25] bundle update activemerchant --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index ac9fde044..cc66b8c32 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,7 +30,7 @@ GEM activejob (4.2.7.1) activesupport (= 4.2.7.1) globalid (>= 0.3.0) - activemerchant (1.60.0) + activemerchant (1.61.0) activesupport (>= 3.2.14, < 5.1) builder (>= 2.1.2, < 4.0.0) i18n (>= 0.6.9) From 330bc912c1ef9941d73cc5c8a9c07eb6f1c38137 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:43:05 +1000 Subject: [PATCH 20/25] bundle update bootstrap_form --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index cc66b8c32..4e207d409 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,7 +71,7 @@ GEM bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) - bootstrap_form (2.5.0) + bootstrap_form (2.5.2) builder (3.2.2) byebug (9.0.6) cancancan (1.15.0) From 5c2b14376e4bc57857752c0e820408194213bc86 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 10:43:46 +1000 Subject: [PATCH 21/25] bundle update terminal-table --- Gemfile.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4e207d409..292cfb4dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -453,7 +453,8 @@ GEM sprockets (>= 3.0.0) term-ansicolor (1.3.2) tins (~> 1.0) - terminal-table (1.6.0) + terminal-table (1.7.3) + unicode-display_width (~> 1.1.1) thor (0.19.3) thread (0.2.2) thread_safe (0.3.5) From 9963502026cc483ce582d530074c4a088645a4b0 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Nov 2016 13:55:01 +1000 Subject: [PATCH 22/25] bundle update i18n-tasks --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 292cfb4dd..618de9759 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -223,7 +223,7 @@ GEM httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.7.0) - i18n-tasks (0.9.5) + i18n-tasks (0.9.6) activesupport (>= 4.0.2) ast (>= 2.1.0) easy_translate (>= 0.5.0) @@ -314,7 +314,7 @@ GEM cocaine (~> 0.5.5) mime-types mimemagic (~> 0.3.0) - parser (2.3.1.2) + parser (2.3.2.0) ast (~> 2.2) pg (0.19.0) plupload-rails (1.2.1) From 96b1e78962a6af0c6d5f99b20af083b163609fff Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Mon, 28 Nov 2016 11:02:32 -0500 Subject: [PATCH 23/25] dedup the add from csv code (Fixes: #1082) --- app/models/crop.rb | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index ceec55c36..86dbd52f7 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -263,43 +263,24 @@ class Crop < ActiveRecord::Base logger.warn("Warning: no scientific name (not even on parent crop) for #{self}") end + cropbot = Member.find_by_login_name('cropbot') + if names_to_add.size > 0 - cropbot = Member.find_by_login_name('cropbot') raise "cropbot account not found: run rake db:seed" unless cropbot - names_to_add.each do |n| - if self.scientific_names.exists?(scientific_name: n) - logger.warn("Warning: skipping duplicate scientific name #{n} for #{self}") - else - - self.scientific_names.create( - scientific_name: n, - creator_id: cropbot.id - ) - end - end + add_names_to_list(names_to_add, 'scientific', 'scientific_name') end end def add_alternate_names_from_csv(alternate_names) + cropbot = Member.find_by_login_name('cropbot') + names_to_add = [] if ! alternate_names.blank? # i.e. we actually passed something in, which isn't a given - cropbot = Member.find_by_login_name('cropbot') raise "cropbot account not found: run rake db:seed" unless cropbot names_to_add = alternate_names.split(%r{,\s*}) - - names_to_add.each do |n| - if self.alternate_names.exists?(name: n) - logger.warn("Warning: skipping duplicate alternate name #{n} for #{self}") - else - self.alternate_names.create( - name: n, - creator_id: cropbot.id - ) - end - end - + add_names_to_list(names_to_add, 'alternate', 'name') end end @@ -352,6 +333,23 @@ class Crop < ActiveRecord::Base end end + private + + def add_names_to_list(names_to_add, list_name, col_name) + cropbot = Member.find_by_login_name('cropbot') + names_to_add.each do |n| + if self.send("#{list_name}_names").exists?(["#{col_name} LIKE ?", n]) + logger.warn("Warning: skipping duplicate #{list_name} name #{n} for #{self}") + else + create_hash = { + creator_id: "#{cropbot.id}" + } + create_hash["#{col_name}"] = n + self.send("#{list_name}_names").create(create_hash) + end + end + end + # Custom validations def approval_status_cannot_be_changed_again From 502862128fabff1b9fac592f0be4e8069a050107 Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Mon, 28 Nov 2016 19:20:35 -0500 Subject: [PATCH 24/25] break out if/else into discrete blocks --- app/models/crop.rb | 99 +++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 86dbd52f7..4ca02bcdf 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -50,44 +50,46 @@ class Crop < ActiveRecord::Base #################################### # Elastic search configuration - include Elasticsearch::Model - include Elasticsearch::Model::Callbacks - # In order to avoid clashing between different environments, - # use Rails.env as a part of index name (eg. development_growstuff) - index_name [Rails.env, "growstuff"].join('_') - settings index: { number_of_shards: 1 }, - analysis: { - tokenizer: { - gs_edgeNGram_tokenizer: { - type: "edgeNGram", # edgeNGram: NGram match from the start of a token - min_gram: 3, - max_gram: 10, - # token_chars: Elasticsearch will split on characters - # that don’t belong to any of these classes - token_chars: [ "letter", "digit" ] - } - }, - analyzer: { - gs_edgeNGram_analyzer: { - tokenizer: "gs_edgeNGram_tokenizer", - filter: ["lowercase"] - } - }, - } do - mappings dynamic: 'false' do - indexes :id, type: 'long' - indexes :name, type: 'string', analyzer: 'gs_edgeNGram_analyzer' - indexes :approval_status, type: 'string' - indexes :scientific_names do - indexes :scientific_name, - type: 'string', - analyzer: 'gs_edgeNGram_analyzer', - # Disabling field-length norm (norm). If the norm option is turned on(by default), - # higher weigh would be given for shorter fields, which in our case is irrelevant. - norms: { enabled: false } - end - indexes :alternate_names do + if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + include Elasticsearch::Model + include Elasticsearch::Model::Callbacks + # In order to avoid clashing between different environments, + # use Rails.env as a part of index name (eg. development_growstuff) + index_name [Rails.env, "growstuff"].join('_') + settings index: { number_of_shards: 1 }, + analysis: { + tokenizer: { + gs_edgeNGram_tokenizer: { + type: "edgeNGram", # edgeNGram: NGram match from the start of a token + min_gram: 3, + max_gram: 10, + # token_chars: Elasticsearch will split on characters + # that don’t belong to any of these classes + token_chars: [ "letter", "digit" ] + } + }, + analyzer: { + gs_edgeNGram_analyzer: { + tokenizer: "gs_edgeNGram_tokenizer", + filter: ["lowercase"] + } + }, + } do + mappings dynamic: 'false' do + indexes :id, type: 'long' indexes :name, type: 'string', analyzer: 'gs_edgeNGram_analyzer' + indexes :approval_status, type: 'string' + indexes :scientific_names do + indexes :scientific_name, + type: 'string', + analyzer: 'gs_edgeNGram_analyzer', + # Disabling field-length norm (norm). If the norm option is turned on(by default), + # higher weigh would be given for shorter fields, which in our case is irrelevant. + norms: { enabled: false } + end + indexes :alternate_names do + indexes :name, type: 'string', analyzer: 'gs_edgeNGram_analyzer' + end end end end @@ -297,7 +299,7 @@ class Crop < ActiveRecord::Base if ENV['GROWSTUFF_ELASTICSEARCH'] == "true" search_str = query.nil? ? "" : query.downcase response = __elasticsearch__.search( { - # Finds documents which match any field, but uses the _score from + # Finds documents which match any field, but uses the _score from # the best field insead of adding up _score from each field. query: { multi_match: { @@ -336,20 +338,27 @@ class Crop < ActiveRecord::Base private def add_names_to_list(names_to_add, list_name, col_name) - cropbot = Member.find_by_login_name('cropbot') names_to_add.each do |n| - if self.send("#{list_name}_names").exists?(["#{col_name} LIKE ?", n]) + if name_already_exists(list_name, col_name, n) logger.warn("Warning: skipping duplicate #{list_name} name #{n} for #{self}") else - create_hash = { - creator_id: "#{cropbot.id}" - } - create_hash["#{col_name}"] = n - self.send("#{list_name}_names").create(create_hash) + create_crop_in_list(list_name, col_name, n) end end end + def create_crop_in_list(list_name, col_name, name) + cropbot = Member.find_by_login_name('cropbot') + create_hash = {} + create_hash['creator_id'] = "#{cropbot.id}" + create_hash["#{col_name}"] = name + self.send("#{list_name}_names").create(create_hash) + end + + def name_already_exists(list_name, col_name, name) + self.send("#{list_name}_names").exists?(["#{col_name} LIKE ?", name]) + end + # Custom validations def approval_status_cannot_be_changed_again From b94cb2abd68217c88b927b5fffa2c0132b382ad9 Mon Sep 17 00:00:00 2001 From: Mackenzie Morgan Date: Mon, 28 Nov 2016 19:57:34 -0500 Subject: [PATCH 25/25] deduplicate sunniness and planted_from functions (Fixes: #1085) --- app/models/crop.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 30d7530d4..89863eb2c 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -152,13 +152,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength # key: sunniness (eg. 'sun') # value: count of how many times it's been used by plantings def sunniness - sunniness = Hash.new(0) - plantings.each do |p| - if !p.sunniness.blank? - sunniness[p.sunniness] += 1 - end - end - return sunniness + count_uses_of_property 'sunniness' end # crop.planted_from @@ -166,13 +160,7 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength # key: propagation method (eg. 'seed') # value: count of how many times it's been used by plantings def planted_from - planted_from = Hash.new(0) - plantings.each do |p| - if !p.planted_from.blank? - planted_from[p.planted_from] += 1 - end - end - return planted_from + count_uses_of_property 'planted_from' end # crop.popular_plant_parts @@ -368,6 +356,16 @@ class Crop < ActiveRecord::Base # rubocop:disable Metrics/ClassLength self.send("#{list_name}_names").exists?(["#{col_name} LIKE ?", name]) end + def count_uses_of_property(col_name) + data = Hash.new(0) + plantings.each do |p| + if !p.send("#{col_name}").blank? + data[p.send("#{col_name}")] += 1 + end + end + data + end + # Custom validations def approval_status_cannot_be_changed_again