Skip to content

Commit

Permalink
draw the owl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jörg Seitz authored and fwolfst committed Dec 5, 2024
1 parent e40192d commit b9800c1
Show file tree
Hide file tree
Showing 41 changed files with 811 additions and 63 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:

lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -53,3 +54,19 @@ jobs:
- name: Lint code for consistent style
run: bin/rubocop -f github

test:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Run tests
run: bundle exec rake
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.1.4
ruby-3.2.2
13 changes: 11 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
source "https://rubygems.org"

# Version from .tool-versions (can use asdf); default to 3.2+ (e.g. for dependabot)
ruby file: ".tool-versions" rescue "~> 3.2"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.2.2"
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
Expand Down Expand Up @@ -34,6 +37,9 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# State machine
gem "aasm", "~> 5.5"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
Expand All @@ -43,13 +49,16 @@ group :development, :test do

# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false

# Testing Framework
gem "rspec", "~> 3.13"
gem "rspec-rails"
end

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

# Highlight the fine-grained location where an error occurred [https://github.com/ruby/error_highlight]
gem "error_highlight", ">= 0.4.0", platforms: [ :ruby ]
# gem "error_highlight", ">= 0.4.0", platforms: [ :ruby ]
end

79 changes: 52 additions & 27 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
GEM
remote: https://rubygems.org/
specs:
aasm (5.5.0)
concurrent-ruby (~> 1.0)
actioncable (7.2.2)
actionpack (= 7.2.2)
activesupport (= 7.2.2)
Expand Down Expand Up @@ -89,8 +91,8 @@ GEM
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.1)
drb (2.2.1)
error_highlight (0.6.0)
erubi (1.13.0)
globalid (1.2.1)
activesupport (>= 6.1)
Expand All @@ -100,14 +102,14 @@ GEM
actionpack (>= 6.0.0)
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
io-console (0.8.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.8.2)
json (2.9.0)
language_server-protocol (3.17.0.3)
logger (1.6.2)
loofah (2.23.1)
Expand All @@ -120,7 +122,7 @@ GEM
net-smtp
marcel (1.0.4)
mini_mime (1.1.5)
minitest (5.25.2)
minitest (5.25.4)
msgpack (1.7.5)
net-imap (0.5.1)
date
Expand All @@ -132,17 +134,17 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.4)
nokogiri (1.16.7-aarch64-linux)
nokogiri (1.16.8-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
nokogiri (1.16.8-arm-linux)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.16.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86-linux)
nokogiri (1.16.8-x86-linux)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
nokogiri (1.16.8-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.16.8-x86_64-linux)
racc (~> 1.4)
parallel (1.26.3)
parser (3.3.6.0)
Expand Down Expand Up @@ -179,9 +181,9 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.1)
loofah (~> 2.21)
nokogiri (~> 1.14)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (7.2.2)
actionpack (= 7.2.2)
activesupport (= 7.2.2)
Expand All @@ -197,14 +199,35 @@ GEM
regexp_parser (2.9.3)
reline (0.5.12)
io-console (~> 0.5)
rubocop (1.69.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (7.1.0)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.2)
rubocop (1.69.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.36.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
Expand Down Expand Up @@ -234,16 +257,16 @@ GEM
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
sqlite3 (2.3.1-aarch64-linux-gnu)
sqlite3 (2.3.1-aarch64-linux-musl)
sqlite3 (2.3.1-arm-linux-gnu)
sqlite3 (2.3.1-arm-linux-musl)
sqlite3 (2.3.1-arm64-darwin)
sqlite3 (2.3.1-x86-linux-gnu)
sqlite3 (2.3.1-x86-linux-musl)
sqlite3 (2.3.1-x86_64-darwin)
sqlite3 (2.3.1-x86_64-linux-gnu)
sqlite3 (2.3.1-x86_64-linux-musl)
sqlite3 (2.4.0-aarch64-linux-gnu)
sqlite3 (2.4.0-aarch64-linux-musl)
sqlite3 (2.4.0-arm-linux-gnu)
sqlite3 (2.4.0-arm-linux-musl)
sqlite3 (2.4.0-arm64-darwin)
sqlite3 (2.4.0-x86-linux-gnu)
sqlite3 (2.4.0-x86-linux-musl)
sqlite3 (2.4.0-x86_64-darwin)
sqlite3 (2.4.0-x86_64-linux-gnu)
sqlite3 (2.4.0-x86_64-linux-musl)
stimulus-rails (1.3.4)
railties (>= 6.0.0)
stringio (3.1.2)
Expand All @@ -257,7 +280,7 @@ GEM
unicode-display_width (3.1.2)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
useragent (0.16.10)
useragent (0.16.11)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -285,14 +308,16 @@ PLATFORMS
x86_64-linux-musl

DEPENDENCIES
aasm (~> 5.5)
bootsnap
brakeman
debug
error_highlight (>= 0.4.0)
importmap-rails
jbuilder
puma (>= 5.0)
rails (~> 7.2.2)
rspec (~> 3.13)
rspec-rails
rubocop-rails-omakase
sprockets-rails
sqlite3 (>= 1.4)
Expand Down
77 changes: 53 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
# README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...
# Voting feature coding challenge for betterplace.org

This is a small skeleton rails application that serves as the foundation for our coding challenge.

## Preparation
Please follow the steps below before starting:
1. create a private repository called `betterplace_coding_challenge`
2. Run the following in its parent directory
```
git clone [email protected]:betterplace/voting_challenge.git
cd voting_challenge
git remote set-url origin [email protected]:YOUR-GITHUB-USERNAME/betterplace_coding_challenge.git
git push -u origin main
```
3. Solve the challenge
4. Provide access to betterplace devs so they can have a look. You will receive the email addresses for this during the application process. **Please do not make your solutions public!**
## Setup
There is nothing out of the ordinary in the application all the commands from a basic rails app should work. You only need to run the bundle.
```
bundle install
rails db:setup
```
You can simulate a successful donation request with:
```
curl -X POST http://127.0.0.1:3000/donations \
-d "donation[receiver_id]=1&donation[amount_in_cents]=5000" \
-w "Status Code: %{http_code}\n"
```
## The challenge
Your task is to implement a voting feature based on the feature description and requirements below.
You can take as much time as needed but we planned with a time frame of 1-2h.
It is okay to submit the challenge without fully solving it. We're all human and have limited time, especially if it is unpaid ;).
Instead of a 100% solution we are more interested in your approach, considerations and code.
Dealing with the backend side of things is more important to us than having a full user journey and working forms. You can use the cURL request above to simulate a successful donation form submission without implementing the views and use a rails console to set up data. Please include the code snippets for setting up data if you pursue this approach so we can play with your solution.
If you have any questions feel free to reach out at any time.
### Feature description
In the donation form, receivers can ask a question. Donors participate in the voting by donating and selecting one of multiple preconfigured answers to the question. The answer which was selected most frequently wins.
* Only the votes of confirmed donations should be counted.
* Donating without voting should still be possible.
* Only one question per receiver can be 'active' at a time but multiple can exist which are already answered, or waiting to be answered.
* If a request arrives that would answer a question that is currently not active the vote should be ignored.
## Closing remarks
Thank you for being interested in working with us and improving the world!
We are looking forward to discussing your solution together with you.
Cheers,
the betterplace devs.
73 changes: 73 additions & 0 deletions app/controllers/donations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class DonationsController < ApplicationController
before_action :set_donation, only: %i[ show edit update destroy ]
# following line makes the cURL request from the README work
skip_before_action :verify_authenticity_token, only: [ :create ] if Rails.env.development?

# GET /donations or /donations.json
def index
@donations = Donation.all
end

# GET /donations/1 or /donations/1.json
def show
end

# GET /donations/new
def new
@donation = Donation.new
end

# GET /donations/1/edit
def edit
end

# POST /donations or /donations.json
def create
result = Donate.new.call(donation_params["receiver_id"], donation_params["amount_in_cents"])
@donation = result.donation

respond_to do |format|
if result.success
format.html { redirect_to @donation, notice: "Donation was successfully created." }
format.json { render :show, status: :created, location: @donation }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @donation.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /donations/1 or /donations/1.json
def update
respond_to do |format|
if @donation.update(donation_params)
format.html { redirect_to @donation, notice: "Donation was successfully updated." }
format.json { render :show, status: :ok, location: @donation }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @donation.errors, status: :unprocessable_entity }
end
end
end

# DELETE /donations/1 or /donations/1.json
def destroy
@donation.destroy!

respond_to do |format|
format.html { redirect_to donations_path, status: :see_other, notice: "Donation was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_donation
@donation = Donation.find(params[:id])
end

# Only allow a list of trusted parameters through.
def donation_params
params.require(:donation).permit(:amount_in_cents, :receiver_id)
end
end
Loading

0 comments on commit b9800c1

Please sign in to comment.