Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ Fill in the environment variables
Install this project with:
```sh
bundle install
yarn install --frozen-lockfile
yarn build:css
gem install foreman
rails db:create db:migrate db:seed
```

Expand All @@ -145,6 +148,11 @@ To run the project, execute the following command:
```
Open `http://localhost:3000/` on your browser.

`bin/dev` builds the stylesheet, then runs Rails, the CSS watcher, and Sidekiq
using `Procfile.dev`. Node.js, Yarn, and Foreman must be installed.
If you start Rails directly with `bin/rails server`, run `yarn build:css` first
and use `yarn build:css --watch` in another terminal while editing styles.

### Run tests

To run tests, run the following command:
Expand Down
Binary file added app/assets/images/addisu.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/arturo.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/brenda.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/darik.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/david.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/elson.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/gabriel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/jesus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/santo.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/tinashe.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/worash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def current_user
end

def current_visitor
session[:visitor_id] ? Visitor.find(session[:visitor_id]) : create_current_visitor
Visitor.find_by(id: session[:visitor_id]) || create_current_visitor
end

def posts_per_page
Expand Down
6 changes: 5 additions & 1 deletion bin/dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env ruby
exec "./bin/rails", "server", *ARGV
Dir.chdir(File.expand_path("..", __dir__)) do
# Build once before Rails starts so the first request has a stylesheet.
system("yarn", "build:css", exception: true)
exec "foreman", "start", "-f", "Procfile.dev", *ARGV
end
4 changes: 4 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ FileUtils.chdir APP_ROOT do
puts "== Installing dependencies =="
system("bundle check") || system!("bundle install")

puts "\n== Installing and building stylesheets =="
system! "yarn install --frozen-lockfile"
system! "yarn build:css"

# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
Expand Down
36 changes: 25 additions & 11 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@
# Character.create(name: 'Luke', movie: movies.first)

unless Member.any?
Member.create!(name: 'Elson', bio: 'Student from Brazil', email: 'elson@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Worash', bio: 'Student from Ethiopia', email: 'worash@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Jesus', bio: 'Student from Mexico', email: 'jesus@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Darik', bio: 'Student from Ethiopia', email: 'darik@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Gabriel', bio: 'Student from Brazil', email: 'gabriel@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'David', bio: 'Student from Ecuador', email: 'david@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Brenda', bio: 'Student from Rwanda', email: 'brenda@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Addisu', bio: 'Student from Ethiopia', email: 'addisu@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Tinashe', bio: 'Student from Zimbabwe', email: 'tinashe@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Gabriel', bio: 'Student from Brazil', email: 'santo@blog.com', password: 'foobar', password_confirmation: 'foobar')
Member.create!(name: 'Arturo', bio: 'Student from Ecuador', email: 'arturo@blog.com', password: 'foobar', password_confirmation: 'foobar')
members = [
{ name: 'Elson', bio: 'Student from Brazil', email: 'elson@blog.com' },
{ name: 'Worash', bio: 'Student from Ethiopia', email: 'worash@blog.com' },
{ name: 'Jesus', bio: 'Student from Mexico', email: 'jesus@blog.com' },
{ name: 'Darik', bio: 'Student from Ethiopia', email: 'darik@blog.com' },
{ name: 'Gabriel', bio: 'Student from Brazil', email: 'gabriel@blog.com' },
{ name: 'David', bio: 'Student from Ecuador', email: 'david@blog.com' },
{ name: 'Brenda', bio: 'Student from Rwanda', email: 'brenda@blog.com' },
{ name: 'Addisu', bio: 'Student from Ethiopia', email: 'addisu@blog.com' },
{ name: 'Tinashe', bio: 'Student from Zimbabwe', email: 'tinashe@blog.com' },
{ name: 'Gabriel', bio: 'Student from Brazil', email: 'santo@blog.com' },
{ name: 'Arturo', bio: 'Student from Ecuador', email: 'arturo@blog.com' }
]

members.each do |attributes|
member = Member.new(attributes.merge(password: 'foobar', password_confirmation: 'foobar'))
email_name = member.email.split('@').first
avatar_path = Rails.root.join('app/assets/images').glob("#{email_name}.{jpg,jpeg,png}").first
raise "Avatar image not found for #{member.email}" unless avatar_path

File.open(avatar_path, 'rb') do |file|
member.avatar.attach(io: file, filename: avatar_path.basename.to_s)
member.save!
end
end
end

unless Post.any?
Expand Down
36 changes: 36 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rails_helper'

RSpec.describe ApplicationController, type: :controller do
describe '#current_visitor' do
it 'reuses the visitor stored in the session' do
visitor = Visitor.create!(user_agent: 'Test browser')
session[:visitor_id] = visitor.id

expect { expect(controller.current_visitor).to eq(visitor) }.not_to change(Visitor, :count)
end

it 'creates a visitor when the session has no visitor ID' do
request.env['HTTP_USER_AGENT'] = 'Test browser'

expect { controller.current_visitor }.to change(Visitor, :count).by(1)

visitor = Visitor.find(session[:visitor_id])
expect(visitor.user_agent).to eq('Test browser')
expect(controller.current_visitor).to eq(visitor)
end

it 'replaces a stale visitor ID in the session' do
visitor = Visitor.create!(user_agent: 'Old browser')
session[:visitor_id] = visitor.id
visitor.destroy!
request.env['HTTP_USER_AGENT'] = 'Test browser'

expect { controller.current_visitor }.to change(Visitor, :count).by(1)

replacement = Visitor.find(session[:visitor_id])
expect(replacement.id).not_to eq(visitor.id)
expect(replacement.user_agent).to eq('Test browser')
expect(controller.current_visitor).to eq(replacement)
end
end
end
Loading