-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
811 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ruby-3.1.4 | ||
ruby-3.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.