Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darcy_test_task #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
54 changes: 54 additions & 0 deletions source/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

group :development, :test do
gem 'pry'
gem 'pry-nav'
end

group :test do
gem "factory_girl_rails", "~> 4.0"
end
138 changes: 138 additions & 0 deletions source/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.0)
actionpack (= 4.0.0)
mail (~> 2.5.3)
actionpack (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activerecord (4.0.0)
activemodel (= 4.0.0)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.4)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
arel (4.0.2)
builder (3.1.4)
coderay (1.1.1)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
erubis (2.7.0)
execjs (2.7.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
hike (1.2.3)
i18n (0.7.0)
jbuilder (1.5.3)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-rails (3.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.12.1)
polyglot (0.3.5)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-nav (0.2.4)
pry (>= 0.9.10, < 0.11.0)
rack (1.5.5)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.0.0)
actionmailer (= 4.0.0)
actionpack (= 4.0.0)
activerecord (= 4.0.0)
activesupport (= 4.0.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.0)
sprockets-rails (~> 2.0.0)
railties (4.0.0)
actionpack (= 4.0.0)
activesupport (= 4.0.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.3.0)
rdoc (4.2.2)
json (~> 1.4)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2.2)
sprockets (~> 2.8, < 3.0)
sprockets-rails (~> 2.0)
sdoc (0.4.2)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
slop (3.6.0)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.12)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.0)
tzinfo (0.3.51)
uglifier (3.0.2)
execjs (>= 0.3.0, < 3)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (~> 4.0.0)
factory_girl_rails (~> 4.0)
jbuilder (~> 1.2)
jquery-rails
pry
pry-nav
rails (= 4.0.0)
sass-rails (~> 4.0.0)
sdoc
sqlite3
turbolinks
uglifier (>= 1.3.0)

BUNDLED WITH
1.13.1
28 changes: 28 additions & 0 deletions source/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
== 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

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
6 changes: 6 additions & 0 deletions source/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Source::Application.load_tasks
Empty file added source/app/assets/images/.keep
Empty file.
16 changes: 16 additions & 0 deletions source/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
3 changes: 3 additions & 0 deletions source/app/assets/javascripts/charges.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
13 changes: 13 additions & 0 deletions source/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/
15 changes: 15 additions & 0 deletions source/app/assets/stylesheets/charges.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Place all the styles related to the charges controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.failed {
tr {
background-color: #FF0000;
}
}

.disputed {
tr {
background-color: #FF5400;
}
}
5 changes: 5 additions & 0 deletions source/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
7 changes: 7 additions & 0 deletions source/app/controllers/charges_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChargesController < ApplicationController
def index
@paid = Charge.paid
@failed = Charge.failed
@disputed = Charge.disputed
end
end
Empty file.
2 changes: 2 additions & 0 deletions source/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
7 changes: 7 additions & 0 deletions source/app/helpers/charges_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ChargesHelper

# Format amount in US Dollar
def currency_format(amount)
number_to_currency(amount)
end
end
Empty file added source/app/mailers/.keep
Empty file.
Empty file added source/app/models/.keep
Empty file.
17 changes: 17 additions & 0 deletions source/app/models/charge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Charge < ActiveRecord::Base

# Foreign keys
belongs_to :customer

# validation
validates :amount, :customer_id, :presence => true

# Scopes
scope :paid, -> { where(paid: true) }
scope :failed, -> { where(refunded: true) }
scope :disputed, -> { where(disputed: true) }

def amount_in_dollar
amount.to_i / 100.0
end
end
Empty file.
8 changes: 8 additions & 0 deletions source/app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Customer < ActiveRecord::Base

# Foreign keys
has_many :charges, dependent: :destroy

# validation
validates :first_name, :last_name, :presence => true
end
5 changes: 5 additions & 0 deletions source/app/views/charges/_charge.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<tr>
<td><%= "#{charge.customer.first_name} #{charge.customer.last_name}" %></td>
<td><%= currency_format(charge.amount_in_dollar) %></td>
<td><%= charge.created_at %></td>
</tr>
20 changes: 20 additions & 0 deletions source/app/views/charges/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>Failed Charges</h1>
<table class="failed">
<tbody>
<%= render @failed %>
</tbody>
</table>

<h1>Disputed Charges</h1>
<table class="disputed">
<tbody>
<%= render @disputed %>
</tbody>
</table>

<h1>Successful Charges</h1>
<table class="paid">
<tbody>
<%= render @paid %>
</tbody>
</table>
14 changes: 14 additions & 0 deletions source/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Source</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 3 additions & 0 deletions source/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
Loading