Skip to content

Commit

Permalink
Fixing prod host for travis, private class usage and rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
alaxalves committed Jul 3, 2019
1 parent 5db0ac9 commit 6cf32f7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ install:
- ./lib/exporter-deps.sh > /dev/null 2>&1
- bundle check --path vendor/.bundle/ || bundle install --path vendor/.bundle/
- yarn check || yarn install
- mysql -e "CREATE DATABASE mapknitter_test; CREATE DATABASE mapknitter;"
- if [ $RAILS_ENV == 'production' ]; then
mysql -e "CREATE DATABASE mapknitter;";
mysql -e "CREATE USER 'mapknitter'@'%' IDENTIFIED BY 'mapknitter';";
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'mapknitter'@'%';";
bundle exec rails db:schema:load;
else
bundle exec rails db:setup || bundle exec rails db:migrate;
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/front_ui_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ def index
@maps = Map.new_maps.first(4)
@unpaginated = true
# TODO: these could use optimization but are better than prev:
tag = Tag.where(name: 'featured').first # note that this is not a join table but the .maps method still works
@mappers = User.where(login: tag.maps.collect(&:author)) if tag
@mappers ||= []
@mappers = if Tag.where(name: 'featured').first
User.where(login: tag.maps.collect(&:author))
else
[]
end
end

def all_maps
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/front_ui_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module FrontUiHelper
def profile_image(author)
img = author&.warpables&.last&.image&.url
img ||= "/images/yarn.png"
author&.warpables&.last&.image&.url || "/images/yarn.png"
end

def anonymous(maps)
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ production:
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: db
host: <%= ENV.fetch("MYSQL_HOST") { '127.0.0.1' } %>
username: mapknitter
password: mapknitter
database: mapknitter
Expand Down
1 change: 1 addition & 0 deletions mapknitter.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ MYSQL_DATABASE=mapknitter
MYSQL_USER=mapknitter
MYSQL_PASSWORD=mapknitter
MYSQL_RANDOM_ROOT_PASSWORD=true
MYSQL_HOST=db
RAILS_ENV=production
7 changes: 6 additions & 1 deletion test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ class UserTest < ActiveSupport::TestCase
user = users(:quentin)
map_images = user.maps.map(&:warpables)

assert_equal Warpable::ActiveRecord_Associations_CollectionProxy, user.warpables.class
map_images.flatten.each do |image|
user.warpables.each do |warpable|
assert_equal image.class, warpable.class
end
end

assert_equal map_images.flatten, user.warpables
end

Expand Down

0 comments on commit 6cf32f7

Please sign in to comment.