From e35076ac0eb14de0a6865043060f49f0f8cb1256 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 17:51:14 -0700 Subject: sketch out a rough design. --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index a10a0e0..6b67063 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,48 @@ A typical well license has the following structure (all fields are required): 2. Your submission can be developed using any technology/language you like. 3. This private Github repo has been created just for you. Please push your code to it for review. + +## Design (Rough) + +### Assumptions + +* Name of applicant is the name of the employee at the company that submitted the application. +* Date of license is the date the license was issued. +* Assume perf isn't the focus, so no need to over-engineer with a denorm read model. + +### Model + +WellLicense (aggregate root) +* belongs_to applicant +* has_one well_type +* has_one location +* issued_at +* expired_at +* status + +WellType (flyweight value object) +* id +* name + +Applicant +* company + +Location (value object) +* latitude +* longitude +* township_name + +LicenseStatus (flyweight, state) +* id + +### Endpoints + +* GET /licenses - list of all well licenses +* GET /company/:id/licenses - list of all active licences for company +* GET /licenses/:id - details of a single license +* GET /company/:id/licenses?township=:township - list of active licenses for township, for company. + +Start with a versioned api using urls cuz it's easy peasy. Won't worry +about token auth at this point. + +What should i call this thing? hrmm.... -- cgit v1.2.3 From 734c8c53aa1821a199a76350fd7cbe3449c1193d Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 17:59:46 -0700 Subject: specifiy ruby. --- .ruby-gemset | 1 + .ruby-version | 1 + 2 files changed, 2 insertions(+) create mode 100644 .ruby-gemset create mode 100644 .ruby-version diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..d86cdc7 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +code-challenge diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..9304515 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.1.0 -- cgit v1.2.3 From 1bff8ede68b131f183c96eafacb99df6c9ee514a Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:06:41 -0700 Subject: rails new . --- .gitignore | 16 ++++++ Gemfile | 40 +++++++++++++++ README.rdoc | 28 +++++++++++ Rakefile | 6 +++ app/assets/images/.keep | 0 app/assets/javascripts/application.js | 16 ++++++ app/assets/stylesheets/application.css | 13 +++++ app/controllers/application_controller.rb | 5 ++ app/controllers/concerns/.keep | 0 app/helpers/application_helper.rb | 2 + app/mailers/.keep | 0 app/models/.keep | 0 app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 14 ++++++ bin/bundle | 3 ++ bin/rails | 4 ++ bin/rake | 4 ++ config.ru | 4 ++ config/application.rb | 31 ++++++++++++ config/boot.rb | 4 ++ config/database.yml | 25 ++++++++++ config/environment.rb | 5 ++ config/environments/development.rb | 25 ++++++++++ config/environments/production.rb | 65 +++++++++++++++++++++++++ config/environments/test.rb | 36 ++++++++++++++ config/initializers/backtrace_silencers.rb | 7 +++ config/initializers/filter_parameter_logging.rb | 4 ++ config/initializers/inflections.rb | 16 ++++++ config/initializers/mime_types.rb | 5 ++ config/initializers/secret_token.rb | 12 +++++ config/initializers/session_store.rb | 3 ++ config/initializers/wrap_parameters.rb | 14 ++++++ config/locales/en.yml | 23 +++++++++ config/routes.rb | 56 +++++++++++++++++++++ db/seeds.rb | 7 +++ lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 public/404.html | 58 ++++++++++++++++++++++ public/422.html | 58 ++++++++++++++++++++++ public/500.html | 57 ++++++++++++++++++++++ public/favicon.ico | 0 public/robots.txt | 5 ++ vendor/assets/javascripts/.keep | 0 vendor/assets/stylesheets/.keep | 0 45 files changed, 671 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/helpers/application_helper.rb create mode 100644 app/mailers/.keep create mode 100644 app/models/.keep create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/application.html.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/secret_token.rb create mode 100644 config/initializers/session_store.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/routes.rb create mode 100644 db/seeds.rb create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 vendor/assets/javascripts/.keep create mode 100644 vendor/assets/stylesheets/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a502e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# See https://help.github.com/articles/ignoring-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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e3d983b --- /dev/null +++ b/Gemfile @@ -0,0 +1,40 @@ +source 'https://rubygems.org' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.0.3' + +# Use sqlite3 as the database for Active Record +gem 'sqlite3' + + +# 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.1.2' + +# Use unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano', group: :development + +# Use debugger +# gem 'debugger', group: [:development, :test] diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/README.rdoc @@ -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 +rake doc:app. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2ef3c94 --- /dev/null +++ b/Rakefile @@ -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__) + +CodeChallengeMo::Application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..d6925fa --- /dev/null +++ b/app/assets/javascripts/application.js @@ -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 . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..3192ec8 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -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 . + */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..e6fe263 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + CodeChallengeMo + <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> + <%= javascript_include_tag "application", "data-turbolinks-track" => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..728cd85 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..1724048 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..267e747 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,31 @@ +require File.expand_path('../boot', __FILE__) + +# Pick the frameworks you want: +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +# require "sprockets/railtie" +# require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) + +module CodeChallengeMo + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # Disable the asset pipeline. + config.assets.enabled = false + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..3596736 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..51a4dd4 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..b13bc26 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +CodeChallengeMo::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..b6a245b --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,25 @@ +CodeChallengeMo::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load + +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..d162aa3 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,65 @@ +CodeChallengeMo::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..89c41db --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,36 @@ +CodeChallengeMo::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr +end diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb new file mode 100644 index 0000000..7c81149 --- /dev/null +++ b/config/initializers/secret_token.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure your secret_key_base is kept private +# if you're sharing your code publicly. +CodeChallengeMo::Application.config.secret_key_base = '38d3dbb199f442080b87ee04aacdf61ac0cc2640d67647c73f9c26b8d3a57341cac0330d9f0167a8b0d4e89c401597fe58b289e4d9c46da489c6f3c60c1dd552' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..6259340 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +CodeChallengeMo::Application.config.session_store :cookie_store, key: '_code-challenge-mo_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..f9a308b --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,56 @@ +CodeChallengeMo::Application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..4edb1e8 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..a0daa0c --- /dev/null +++ b/public/404.html @@ -0,0 +1,58 @@ + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..fbb4b84 --- /dev/null +++ b/public/422.html @@ -0,0 +1,58 @@ + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..e9052d3 --- /dev/null +++ b/public/500.html @@ -0,0 +1,57 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..1a3a5e4 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From f87c6088405df0d0f0fe563fac4865dfbdb206b1 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:08:39 -0700 Subject: install rspec and cleanup default gem file. --- .rspec | 1 + Gemfile | 31 ++----------- Gemfile.lock | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 42 ++++++++++++++++++ 4 files changed, 170 insertions(+), 27 deletions(-) create mode 100644 .rspec create mode 100644 Gemfile.lock create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e1e0d2 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color diff --git a/Gemfile b/Gemfile index e3d983b..07b72cf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,25 +1,9 @@ source 'https://rubygems.org' -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.0.3' - -# Use sqlite3 as the database for Active Record -gem 'sqlite3' - - -# 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 @@ -27,14 +11,7 @@ group :doc do gem 'sdoc', require: false end -# Use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.1.2' - -# 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 'sqlite3' + gem 'rspec-rails' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d9888de --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,123 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.0.3) + actionpack (= 4.0.3) + mail (~> 2.5.4) + actionpack (4.0.3) + activesupport (= 4.0.3) + builder (~> 3.1.0) + erubis (~> 2.7.0) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.3) + activesupport (= 4.0.3) + builder (~> 3.1.0) + activerecord (4.0.3) + activemodel (= 4.0.3) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.3) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.3) + activesupport (4.0.3) + 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) + atomic (1.1.14) + builder (3.1.4) + coffee-rails (4.0.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.7.0) + diff-lcs (1.2.5) + erubis (2.7.0) + execjs (2.0.2) + hike (1.2.3) + i18n (0.6.9) + jbuilder (1.5.3) + activesupport (>= 3.0.0) + multi_json (>= 1.2.0) + jquery-rails (3.1.0) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) + json (1.8.1) + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.25.1) + minitest (4.7.5) + multi_json (1.8.4) + polyglot (0.3.4) + rack (1.5.2) + rack-test (0.6.2) + rack (>= 1.0) + rails (4.0.3) + actionmailer (= 4.0.3) + actionpack (= 4.0.3) + activerecord (= 4.0.3) + activesupport (= 4.0.3) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.3) + sprockets-rails (~> 2.0.0) + railties (4.0.3) + actionpack (= 4.0.3) + activesupport (= 4.0.3) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.1.1) + rdoc (4.1.1) + json (~> 1.4) + rspec-core (2.14.7) + rspec-expectations (2.14.5) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.6) + rspec-rails (2.14.1) + actionpack (>= 3.0) + activemodel (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + sdoc (0.4.0) + json (~> 1.8) + rdoc (~> 4.0, < 5.0) + sprockets (2.11.0) + 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.8) + thor (0.18.1) + thread_safe (0.1.3) + atomic + tilt (1.4.1) + treetop (1.4.15) + polyglot + polyglot (>= 0.3.1) + turbolinks (2.2.1) + coffee-rails + tzinfo (0.3.38) + +PLATFORMS + ruby + +DEPENDENCIES + coffee-rails (~> 4.0.0) + jbuilder (~> 1.2) + jquery-rails + rails (= 4.0.3) + rspec-rails + sdoc + sqlite3 + turbolinks diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..943bc19 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,42 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'rspec/autorun' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) + +RSpec.configure do |config| + # ## Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # If true, the base class of anonymous controllers will be inferred + # automatically. This will be the default behavior in future versions of + # rspec-rails. + config.infer_base_class_for_anonymous_controllers = false + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = "random" +end -- cgit v1.2.3 From a95bc6ecd044ca3ec7590a3189e9c54e06a9f72c Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:29:20 -0700 Subject: create route to licenses#index. --- README.rdoc | 28 --------------- app/controllers/v1/licenses_controller.rb | 2 ++ config/routes.rb | 57 ++----------------------------- spec/routing/licenses_routing_spec.rb | 7 ++++ 4 files changed, 12 insertions(+), 82 deletions(-) delete mode 100644 README.rdoc create mode 100644 app/controllers/v1/licenses_controller.rb create mode 100644 spec/routing/licenses_routing_spec.rb diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index dd4e97e..0000000 --- a/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== 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 -rake doc:app. diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb new file mode 100644 index 0000000..697daa9 --- /dev/null +++ b/app/controllers/v1/licenses_controller.rb @@ -0,0 +1,2 @@ +class V1::LicensesController +end diff --git a/config/routes.rb b/config/routes.rb index f9a308b..87a889f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,5 @@ CodeChallengeMo::Application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end + namespace :v1, path: 'v1' do + get 'licenses', to: 'licenses#index' + end end diff --git a/spec/routing/licenses_routing_spec.rb b/spec/routing/licenses_routing_spec.rb new file mode 100644 index 0000000..bc2d45d --- /dev/null +++ b/spec/routing/licenses_routing_spec.rb @@ -0,0 +1,7 @@ +require "spec_helper" + +describe 'v1/licenses' do + it "can route to the index action" do + expect({ get: 'v1/licenses' }).to route_to(controller: 'v1/licenses', action: 'index') + end +end -- cgit v1.2.3 From e602075ef3bc53075129b1427ea880eaea2def5a Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:38:44 -0700 Subject: start to define the index action. --- app/controllers/v1/licenses_controller.rb | 8 +++++++- app/models/license.rb | 2 ++ spec/controllers/v1/liceneses_controller_spec.rb | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/models/license.rb create mode 100644 spec/controllers/v1/liceneses_controller_spec.rb diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index 697daa9..86eb85e 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -1,2 +1,8 @@ -class V1::LicensesController +class V1::LicensesController < ApplicationController + def index + per_page = 10 + page = 1 + @licenses = License.most_recent(page, per_page) + render nothing: true + end end diff --git a/app/models/license.rb b/app/models/license.rb new file mode 100644 index 0000000..4f7e5eb --- /dev/null +++ b/app/models/license.rb @@ -0,0 +1,2 @@ +class License +end diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb new file mode 100644 index 0000000..fc4d7b3 --- /dev/null +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -0,0 +1,16 @@ +require "spec_helper" + +describe V1::LicensesController do + describe :index do + let(:licenses) { [] } + + it "returns the first page of licenses" do + License.stub(:most_recent).with(1, 10).and_return(licenses) + + xhr :get, :index + + response.should be_success + assigns(:licenses).should == licenses + end + end +end -- cgit v1.2.3 From ab6a0801874f7bd6590f6e57ee76cd2b74c30618 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:42:01 -0700 Subject: return a specific page of results. --- app/controllers/v1/licenses_controller.rb | 8 +++++--- spec/controllers/v1/liceneses_controller_spec.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index 86eb85e..e919663 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -1,8 +1,10 @@ class V1::LicensesController < ApplicationController + PER_PAGE = 10 + DEFAULT_PAGE = 1 + def index - per_page = 10 - page = 1 - @licenses = License.most_recent(page, per_page) + page = params[:page].to_i || DEFAULT_PAGE + @licenses = License.most_recent(page, PER_PAGE) render nothing: true end end diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index fc4d7b3..7f1080c 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -12,5 +12,14 @@ describe V1::LicensesController do response.should be_success assigns(:licenses).should == licenses end + + it "returns the second page of licenses" do + License.stub(:most_recent).with(2, 10).and_return(licenses) + + xhr :get, :index, page: 2 + + response.should be_success + assigns(:licenses).should == licenses + end end end -- cgit v1.2.3 From 5beba5ac1bac65d99eac14d55ee89d70254b58d3 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:45:09 -0700 Subject: allow clients to specify the number of items per page. --- app/controllers/v1/licenses_controller.rb | 5 +++-- spec/controllers/v1/liceneses_controller_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index e919663..45a6489 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -3,8 +3,9 @@ class V1::LicensesController < ApplicationController DEFAULT_PAGE = 1 def index - page = params[:page].to_i || DEFAULT_PAGE - @licenses = License.most_recent(page, PER_PAGE) + page = params[:page].present? ? params[:page].to_i : DEFAULT_PAGE + per_page = params[:per_page].present? ? params[:per_page].to_i : PER_PAGE + @licenses = License.most_recent(page, per_page) render nothing: true end end diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index 7f1080c..5964556 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -21,5 +21,13 @@ describe V1::LicensesController do response.should be_success assigns(:licenses).should == licenses end + + it "returns the specified number of results" do + License.stub(:most_recent).with(1, 100).and_return(licenses) + + xhr :get, :index, per_page: 100 + response.should be_success + assigns(:licenses).should == licenses + end end end -- cgit v1.2.3 From 4f506a2366115e61c6f0cbb5ae154e2555b9d1ca Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:46:48 -0700 Subject: extract filter to prepare pagination fields. --- app/controllers/v1/licenses_controller.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index 45a6489..d8c16b6 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -1,11 +1,17 @@ class V1::LicensesController < ApplicationController PER_PAGE = 10 DEFAULT_PAGE = 1 + before_filter :prepare_pagination def index - page = params[:page].present? ? params[:page].to_i : DEFAULT_PAGE - per_page = params[:per_page].present? ? params[:per_page].to_i : PER_PAGE - @licenses = License.most_recent(page, per_page) + @licenses = License.most_recent(@page, @per_page) render nothing: true end + + private + + def prepare_pagination + @page = params[:page].present? ? params[:page].to_i : DEFAULT_PAGE + @per_page = params[:per_page].present? ? params[:per_page].to_i : PER_PAGE + end end -- cgit v1.2.3 From b6635fb14d7935992aa004a477ac877804675794 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 18:52:21 -0700 Subject: use named parameters for better readability and ensure a json response is returned. --- app/controllers/v1/licenses_controller.rb | 4 ++-- spec/controllers/v1/liceneses_controller_spec.rb | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index d8c16b6..36ae54c 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -4,8 +4,8 @@ class V1::LicensesController < ApplicationController before_filter :prepare_pagination def index - @licenses = License.most_recent(@page, @per_page) - render nothing: true + @licenses = License.most_recent(page: @page, per_page: @per_page) + render json: @licenses end private diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index 5964556..b2eb705 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -5,7 +5,7 @@ describe V1::LicensesController do let(:licenses) { [] } it "returns the first page of licenses" do - License.stub(:most_recent).with(1, 10).and_return(licenses) + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) xhr :get, :index @@ -14,7 +14,7 @@ describe V1::LicensesController do end it "returns the second page of licenses" do - License.stub(:most_recent).with(2, 10).and_return(licenses) + License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) xhr :get, :index, page: 2 @@ -23,11 +23,18 @@ describe V1::LicensesController do end it "returns the specified number of results" do - License.stub(:most_recent).with(1, 100).and_return(licenses) + License.stub(:most_recent).with(page: 1, per_page: 100).and_return(licenses) xhr :get, :index, per_page: 100 response.should be_success assigns(:licenses).should == licenses end + + it "returns a json response" do + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) + + xhr :get, :index + -> { JSON.parse(response.body) }.should_not raise_error + end end end -- cgit v1.2.3 From f0f7b7ccb7cf67d33a75e97dcdc2e8de5d151544 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:01:06 -0700 Subject: create licenses table and return most recently created. --- app/models/license.rb | 5 ++++- db/migrate/20140221015819_create_licenses.rb | 7 +++++++ db/schema.rb | 21 +++++++++++++++++++++ spec/models/license_spec.rb | 15 +++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140221015819_create_licenses.rb create mode 100644 db/schema.rb create mode 100644 spec/models/license_spec.rb diff --git a/app/models/license.rb b/app/models/license.rb index 4f7e5eb..c8d2fdb 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,2 +1,5 @@ -class License +class License < ActiveRecord::Base + def self.most_recent(page, per_page) + License.order(:created_at => :desc) + end end diff --git a/db/migrate/20140221015819_create_licenses.rb b/db/migrate/20140221015819_create_licenses.rb new file mode 100644 index 0000000..cc571e1 --- /dev/null +++ b/db/migrate/20140221015819_create_licenses.rb @@ -0,0 +1,7 @@ +class CreateLicenses < ActiveRecord::Migration + def change + create_table :licenses do |t| + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..4da550d --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,21 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20140221015819) do + + create_table "licenses", force: true do |t| + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb new file mode 100644 index 0000000..9998ad9 --- /dev/null +++ b/spec/models/license_spec.rb @@ -0,0 +1,15 @@ +require "spec_helper" + +describe License do + describe ".most_recent" do + let!(:oldest_license) { License.create } + let!(:newest_license) { License.create } + + let(:results) { License.most_recent(1, 2) } + + it "returns the most recently created well licenses" do + results.first.should == newest_license + results.last.should == oldest_license + end + end +end -- cgit v1.2.3 From 3efbc2b2540783d5d1c9e2a65d423b771f049d6d Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:16:17 -0700 Subject: return the paginated set of results. --- app/models/license.rb | 5 +++-- spec/models/license_spec.rb | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index c8d2fdb..abcd728 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,5 +1,6 @@ class License < ActiveRecord::Base - def self.most_recent(page, per_page) - License.order(:created_at => :desc) + def self.most_recent(page: 1, per_page: 10) + offset = (page - 1) * per_page + License.order(created_at: :desc).offset(offset).limit(per_page) end end diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index 9998ad9..a939372 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -5,11 +5,28 @@ describe License do let!(:oldest_license) { License.create } let!(:newest_license) { License.create } - let(:results) { License.most_recent(1, 2) } - it "returns the most recently created well licenses" do + results = License.most_recent(page: 1, per_page: 2) results.first.should == newest_license results.last.should == oldest_license end + + it "returns the first page of results" do + results = License.most_recent(page: 1, per_page: 1) + results.count.should == 1 + results.first.should == newest_license + end + + it "returns the next page of results" do + results = License.most_recent(page: 2, per_page: 1) + results.count.should == 1 + results.first.should == oldest_license + end + + it "returns the first page of results when the page is below 1" do + results = License.most_recent(page: -1, per_page: 1) + results.count.should == 1 + results.first.should == newest_license + end end end -- cgit v1.2.3 From eed61ce1f9ea921b9bc9dabd468ea7683e5b4622 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:18:08 -0700 Subject: review readme. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6b67063..2bb9994 100644 --- a/README.md +++ b/README.md @@ -93,9 +93,9 @@ LicenseStatus (flyweight, state) ### Endpoints * GET /licenses - list of all well licenses -* GET /company/:id/licenses - list of all active licences for company -* GET /licenses/:id - details of a single license -* GET /company/:id/licenses?township=:township - list of active licenses for township, for company. +* GET /licenses/:guid - details of a single license +* GET /company/:guid/licenses - list of all active licences for company +* GET /company/:guid/licenses?township=:township - list of active licenses for township, for company. Start with a versioned api using urls cuz it's easy peasy. Won't worry about token auth at this point. -- cgit v1.2.3 From 12e544beb49702b876ce0cbd104d881d86b53383 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:27:53 -0700 Subject: add route to licenses#show. --- config/routes.rb | 2 +- spec/routing/licenses_routing_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 87a889f..a9b6923 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ CodeChallengeMo::Application.routes.draw do namespace :v1, path: 'v1' do - get 'licenses', to: 'licenses#index' + resources :licenses, only: [:index, :show] end end diff --git a/spec/routing/licenses_routing_spec.rb b/spec/routing/licenses_routing_spec.rb index bc2d45d..4491c5b 100644 --- a/spec/routing/licenses_routing_spec.rb +++ b/spec/routing/licenses_routing_spec.rb @@ -4,4 +4,9 @@ describe 'v1/licenses' do it "can route to the index action" do expect({ get: 'v1/licenses' }).to route_to(controller: 'v1/licenses', action: 'index') end + + it "can route to the show action" do + uuid = 'aa80f0ee-c6da-4b1d-bd80-3c50c93d083e' + expect(get: "v1/licenses/#{uuid}").to route_to(controller: 'v1/licenses', action: 'show', id: uuid) + end end -- cgit v1.2.3 From b1bac85f2c8b55e92f0472cbe4e548beb74743d0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:35:45 -0700 Subject: remove sqlite and use pg. --- .gitignore | 1 + Gemfile | 2 +- Gemfile.lock | 4 ++-- config/database.yml | 32 +++++++++++--------------------- config/database.yml.example | 13 +++++++++++++ db/schema.rb | 3 +++ 6 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 config/database.yml.example diff --git a/.gitignore b/.gitignore index 6a502e9..318627d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp +database.yml diff --git a/Gemfile b/Gemfile index 07b72cf..6636799 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 1.2' +gem 'pg' group :doc do # bundle exec rake doc:rails generates the API under doc/api. @@ -12,6 +13,5 @@ group :doc do end group :development, :test do - gem 'sqlite3' gem 'rspec-rails' end diff --git a/Gemfile.lock b/Gemfile.lock index d9888de..797bc91 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,6 +53,7 @@ GEM mime-types (1.25.1) minitest (4.7.5) multi_json (1.8.4) + pg (0.17.1) polyglot (0.3.4) rack (1.5.2) rack-test (0.6.2) @@ -97,7 +98,6 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) - sqlite3 (1.3.8) thor (0.18.1) thread_safe (0.1.3) atomic @@ -116,8 +116,8 @@ DEPENDENCIES coffee-rails (~> 4.0.0) jbuilder (~> 1.2) jquery-rails + pg rails (= 4.0.3) rspec-rails sdoc - sqlite3 turbolinks diff --git a/config/database.yml b/config/database.yml index 51a4dd4..95db128 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,25 +1,15 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' development: - adapter: sqlite3 - database: db/development.sqlite3 + adapter: postgresql + encoding: unicode + database: licenses_dev pool: 5 - timeout: 5000 + username: mo + password: password + host: localhost -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: - adapter: sqlite3 - database: db/test.sqlite3 - pool: 5 - timeout: 5000 - -production: - adapter: sqlite3 - database: db/production.sqlite3 - pool: 5 - timeout: 5000 + adapter: postgresql + database: licenses_test + username: mo + password: password + host: localhost diff --git a/config/database.yml.example b/config/database.yml.example new file mode 100644 index 0000000..e598daf --- /dev/null +++ b/config/database.yml.example @@ -0,0 +1,13 @@ +development: + adapter: postgresql + database: licenses_dev + username: + password: + host: + +test: + adapter: postgresql + database: licenses_test + username: + password: + host: diff --git a/db/schema.rb b/db/schema.rb index 4da550d..37479de 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,6 +13,9 @@ ActiveRecord::Schema.define(version: 20140221015819) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + create_table "licenses", force: true do |t| t.datetime "created_at" t.datetime "updated_at" -- cgit v1.2.3 From ba8ebf09cd54dbf58bfb8ba032075ac895fea9bb Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:39:36 -0700 Subject: remove jquery, coffeescript and turbolinks gems. --- .gitignore | 1 + Gemfile | 3 --- Gemfile.lock | 16 ---------------- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 318627d..fe31e01 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /log/*.log /tmp database.yml +vendor/bundle diff --git a/Gemfile b/Gemfile index 6636799..ee76893 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,6 @@ source 'https://rubygems.org' gem 'rails', '4.0.3' -gem 'coffee-rails', '~> 4.0.0' -gem 'jquery-rails' -gem 'turbolinks' gem 'jbuilder', '~> 1.2' gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 797bc91..3f653bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,24 +28,13 @@ GEM arel (4.0.2) atomic (1.1.14) builder (3.1.4) - coffee-rails (4.0.1) - coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) - coffee-script (2.2.0) - coffee-script-source - execjs - coffee-script-source (1.7.0) diff-lcs (1.2.5) erubis (2.7.0) - execjs (2.0.2) hike (1.2.3) i18n (0.6.9) jbuilder (1.5.3) activesupport (>= 3.0.0) multi_json (>= 1.2.0) - jquery-rails (3.1.0) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) json (1.8.1) mail (2.5.4) mime-types (~> 1.16) @@ -105,19 +94,14 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - turbolinks (2.2.1) - coffee-rails tzinfo (0.3.38) PLATFORMS ruby DEPENDENCIES - coffee-rails (~> 4.0.0) jbuilder (~> 1.2) - jquery-rails pg rails (= 4.0.3) rspec-rails sdoc - turbolinks -- cgit v1.2.3 From 60f1cea60b2ba69c21620eb244a0d7c102859830 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:48:03 -0700 Subject: enabled uuid extension. --- db/migrate/20140221024327_enable_uuid_extension.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140221024327_enable_uuid_extension.rb diff --git a/db/migrate/20140221024327_enable_uuid_extension.rb b/db/migrate/20140221024327_enable_uuid_extension.rb new file mode 100644 index 0000000..876b6aa --- /dev/null +++ b/db/migrate/20140221024327_enable_uuid_extension.rb @@ -0,0 +1,5 @@ +class EnableUuidExtension < ActiveRecord::Migration + def change + enable_extension 'uuid-ossp' + end +end diff --git a/db/schema.rb b/db/schema.rb index 37479de..86fbee4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,11 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140221015819) do +ActiveRecord::Schema.define(version: 20140221024327) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + enable_extension "uuid-ossp" create_table "licenses", force: true do |t| t.datetime "created_at" -- cgit v1.2.3 From cdfc77e265a9720d5a6207447b84629940e3efa0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:52:51 -0700 Subject: create show action. --- app/controllers/v1/licenses_controller.rb | 5 +++++ spec/controllers/v1/liceneses_controller_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index 36ae54c..0a076c8 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -8,6 +8,11 @@ class V1::LicensesController < ApplicationController render json: @licenses end + def show + @license = License.find(params[:id]) + render nothing: true + end + private def prepare_pagination diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index b2eb705..bfc3618 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -37,4 +37,12 @@ describe V1::LicensesController do -> { JSON.parse(response.body) }.should_not raise_error end end + + describe :show do + it "returns the correct license" do + license = License.create + xhr :get, :show, id: license.id + assigns(:license).should == license + end + end end -- cgit v1.2.3 From 64f61d074312782050da3a06185f99fe59249b8f Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:54:58 -0700 Subject: switch to using a uuid. --- db/migrate/20140221025310_recreate_licenses.rb | 8 ++++++++ db/schema.rb | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140221025310_recreate_licenses.rb diff --git a/db/migrate/20140221025310_recreate_licenses.rb b/db/migrate/20140221025310_recreate_licenses.rb new file mode 100644 index 0000000..a1229b5 --- /dev/null +++ b/db/migrate/20140221025310_recreate_licenses.rb @@ -0,0 +1,8 @@ +class RecreateLicenses < ActiveRecord::Migration + def change + drop_table :licenses + create_table :licenses, id: :uuid do |t| + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 86fbee4..ace9922 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,13 +11,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140221024327) do +ActiveRecord::Schema.define(version: 20140221025310) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp" - create_table "licenses", force: true do |t| + create_table "licenses", id: :uuid, default: "uuid_generate_v4()", force: true do |t| t.datetime "created_at" t.datetime "updated_at" end -- cgit v1.2.3 From 2fcaf253098ddd61bb5af6e96ddb93d331552d25 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:57:29 -0700 Subject: fix broken spec after switch from sqlite to pg. --- app/models/license.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/license.rb b/app/models/license.rb index abcd728..8eb7612 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,6 +1,7 @@ class License < ActiveRecord::Base def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page + offset = offset >= 0 ? offset : 0 License.order(created_at: :desc).offset(offset).limit(per_page) end end -- cgit v1.2.3 From 148724f3b057a0790be5386de23103db24a812eb Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 19:59:23 -0700 Subject: return a json response. --- app/controllers/v1/licenses_controller.rb | 2 +- spec/controllers/v1/liceneses_controller_spec.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index 0a076c8..c62c78b 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -10,7 +10,7 @@ class V1::LicensesController < ApplicationController def show @license = License.find(params[:id]) - render nothing: true + render json: @license end private diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index bfc3618..0f08c05 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -39,10 +39,18 @@ describe V1::LicensesController do end describe :show do - it "returns the correct license" do - license = License.create + let(:license) { License.create } + + before :each do xhr :get, :show, id: license.id + end + + it "returns the correct license" do assigns(:license).should == license end + + it "returns a json response" do + expect(-> { JSON.parse(response.body) }).not_to raise_error + end end end -- cgit v1.2.3 From 1a8040859f0df76efd9bf70eccbfd0a34d53d7d5 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:01:28 -0700 Subject: stub out the finder. --- spec/controllers/v1/liceneses_controller_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb index 0f08c05..e8538d0 100644 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ b/spec/controllers/v1/liceneses_controller_spec.rb @@ -39,9 +39,10 @@ describe V1::LicensesController do end describe :show do - let(:license) { License.create } + let(:license) { License.new(id: SecureRandom.uuid) } before :each do + License.stub(:find).with(license.id).and_return(license) xhr :get, :show, id: license.id end -- cgit v1.2.3 From 8005a209624eec93ead4b372733cd8816d54a7c2 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:02:20 -0700 Subject: remove the assets directory. --- app/assets/images/.keep | 0 app/assets/javascripts/application.js | 16 ---------------- app/assets/stylesheets/application.css | 13 ------------- app/mailers/.keep | 0 4 files changed, 29 deletions(-) delete mode 100644 app/assets/images/.keep delete mode 100644 app/assets/javascripts/application.js delete mode 100644 app/assets/stylesheets/application.css delete mode 100644 app/mailers/.keep diff --git a/app/assets/images/.keep b/app/assets/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js deleted file mode 100644 index d6925fa..0000000 --- a/app/assets/javascripts/application.js +++ /dev/null @@ -1,16 +0,0 @@ -// 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 . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css deleted file mode 100644 index 3192ec8..0000000 --- a/app/assets/stylesheets/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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 . - */ diff --git a/app/mailers/.keep b/app/mailers/.keep deleted file mode 100644 index e69de29..0000000 -- cgit v1.2.3 From 8fa71f5e5200c91ab3916154a9b00e75c4064a2f Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:11:50 -0700 Subject: add routes to companies/:company_id/licenses --- app/controllers/v1/company_licenses_controller.rb | 2 ++ config/routes.rb | 3 +++ spec/routing/company_licenses_routing_spec.rb | 8 ++++++++ 3 files changed, 13 insertions(+) create mode 100644 app/controllers/v1/company_licenses_controller.rb create mode 100644 spec/routing/company_licenses_routing_spec.rb diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb new file mode 100644 index 0000000..aa52b26 --- /dev/null +++ b/app/controllers/v1/company_licenses_controller.rb @@ -0,0 +1,2 @@ +class V1::CompanyLicensesController +end diff --git a/config/routes.rb b/config/routes.rb index a9b6923..b61e488 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ CodeChallengeMo::Application.routes.draw do namespace :v1, path: 'v1' do resources :licenses, only: [:index, :show] + resources :companies, only: [] do + resources :licenses, controller: 'company_licenses', only: [:index] + end end end diff --git a/spec/routing/company_licenses_routing_spec.rb b/spec/routing/company_licenses_routing_spec.rb new file mode 100644 index 0000000..d6e5aa4 --- /dev/null +++ b/spec/routing/company_licenses_routing_spec.rb @@ -0,0 +1,8 @@ +require "spec_helper" + +describe 'v1/companies/:id/licenses' do + it "routes to the index action" do + company_id = SecureRandom.uuid + expect(get: "v1/companies/#{company_id}/licenses").to route_to(controller: 'v1/company_licenses', action: 'index', company_id: company_id) + end +end -- cgit v1.2.3 From 9a094059fcb67a9f54ee73efbdecc2835a5fe0c6 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:22:06 -0700 Subject: implement index action on company licenses controller. --- app/controllers/v1/company_licenses_controller.rb | 14 +++++- app/models/company.rb | 2 + .../v1/company_licenses_controller_spec.rb | 23 +++++++++ spec/controllers/v1/liceneses_controller_spec.rb | 57 ---------------------- spec/controllers/v1/licenses_controller_spec.rb | 57 ++++++++++++++++++++++ 5 files changed, 95 insertions(+), 58 deletions(-) create mode 100644 app/models/company.rb create mode 100644 spec/controllers/v1/company_licenses_controller_spec.rb delete mode 100644 spec/controllers/v1/liceneses_controller_spec.rb create mode 100644 spec/controllers/v1/licenses_controller_spec.rb diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index aa52b26..06d2145 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -1,2 +1,14 @@ -class V1::CompanyLicensesController +class V1::CompanyLicensesController < ApplicationController + before_filter :load_company + + def index + @active_licenses = @company.active_licenses + render json: @active_licenses + end + + private + + def load_company + @company = Company.find(params[:company_id]) + end end diff --git a/app/models/company.rb b/app/models/company.rb new file mode 100644 index 0000000..bff819b --- /dev/null +++ b/app/models/company.rb @@ -0,0 +1,2 @@ +class Company +end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb new file mode 100644 index 0000000..fb0972a --- /dev/null +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -0,0 +1,23 @@ +require "spec_helper" + +describe V1::CompanyLicensesController do + describe :index do + let(:company) { Object.new } + let(:company_id) { SecureRandom.uuid } + let(:active_licenses) { [] } + + before :each do + Company.stub(:find).with(company_id).and_return(company) + company.stub(:active_licenses).and_return(active_licenses) + xhr :get, :index, company_id: company_id + end + + it "returns the active licenses" do + assigns(:active_licenses).should == active_licenses + end + + it "returns a json response" do + expect(-> { JSON.parse(response.body) }).not_to raise_error + end + end +end diff --git a/spec/controllers/v1/liceneses_controller_spec.rb b/spec/controllers/v1/liceneses_controller_spec.rb deleted file mode 100644 index e8538d0..0000000 --- a/spec/controllers/v1/liceneses_controller_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require "spec_helper" - -describe V1::LicensesController do - describe :index do - let(:licenses) { [] } - - it "returns the first page of licenses" do - License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) - - xhr :get, :index - - response.should be_success - assigns(:licenses).should == licenses - end - - it "returns the second page of licenses" do - License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) - - xhr :get, :index, page: 2 - - response.should be_success - assigns(:licenses).should == licenses - end - - it "returns the specified number of results" do - License.stub(:most_recent).with(page: 1, per_page: 100).and_return(licenses) - - xhr :get, :index, per_page: 100 - response.should be_success - assigns(:licenses).should == licenses - end - - it "returns a json response" do - License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) - - xhr :get, :index - -> { JSON.parse(response.body) }.should_not raise_error - end - end - - describe :show do - let(:license) { License.new(id: SecureRandom.uuid) } - - before :each do - License.stub(:find).with(license.id).and_return(license) - xhr :get, :show, id: license.id - end - - it "returns the correct license" do - assigns(:license).should == license - end - - it "returns a json response" do - expect(-> { JSON.parse(response.body) }).not_to raise_error - end - end -end diff --git a/spec/controllers/v1/licenses_controller_spec.rb b/spec/controllers/v1/licenses_controller_spec.rb new file mode 100644 index 0000000..e8538d0 --- /dev/null +++ b/spec/controllers/v1/licenses_controller_spec.rb @@ -0,0 +1,57 @@ +require "spec_helper" + +describe V1::LicensesController do + describe :index do + let(:licenses) { [] } + + it "returns the first page of licenses" do + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) + + xhr :get, :index + + response.should be_success + assigns(:licenses).should == licenses + end + + it "returns the second page of licenses" do + License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) + + xhr :get, :index, page: 2 + + response.should be_success + assigns(:licenses).should == licenses + end + + it "returns the specified number of results" do + License.stub(:most_recent).with(page: 1, per_page: 100).and_return(licenses) + + xhr :get, :index, per_page: 100 + response.should be_success + assigns(:licenses).should == licenses + end + + it "returns a json response" do + License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) + + xhr :get, :index + -> { JSON.parse(response.body) }.should_not raise_error + end + end + + describe :show do + let(:license) { License.new(id: SecureRandom.uuid) } + + before :each do + License.stub(:find).with(license.id).and_return(license) + xhr :get, :show, id: license.id + end + + it "returns the correct license" do + assigns(:license).should == license + end + + it "returns a json response" do + expect(-> { JSON.parse(response.body) }).not_to raise_error + end + end +end -- cgit v1.2.3 From bd442141974a110a1647b01be919bf03de407ab9 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:39:45 -0700 Subject: filter by license status and township --- app/controllers/v1/company_licenses_controller.rb | 3 ++- app/models/license_status.rb | 3 +++ spec/controllers/v1/company_licenses_controller_spec.rb | 14 +++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 app/models/license_status.rb diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 06d2145..963423a 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -2,7 +2,8 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company def index - @active_licenses = @company.active_licenses + @active_licenses = @company.status(LicenseStatus::ACTIVE) + @active_licenses = @active_licenses.township(params[:township]) if params[:township].present? render json: @active_licenses end diff --git a/app/models/license_status.rb b/app/models/license_status.rb new file mode 100644 index 0000000..abe54b1 --- /dev/null +++ b/app/models/license_status.rb @@ -0,0 +1,3 @@ +module LicenseStatus + ACTIVE="active" +end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index fb0972a..2784a1d 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -4,20 +4,28 @@ describe V1::CompanyLicensesController do describe :index do let(:company) { Object.new } let(:company_id) { SecureRandom.uuid } - let(:active_licenses) { [] } + let(:active_licenses) { ["active"] } + let(:active_licenses_in_township) { ["active township"] } before :each do Company.stub(:find).with(company_id).and_return(company) - company.stub(:active_licenses).and_return(active_licenses) - xhr :get, :index, company_id: company_id + company.stub(:status).with(LicenseStatus::ACTIVE).and_return(active_licenses) + active_licenses.stub(:township).with("123").and_return(active_licenses_in_township) end it "returns the active licenses" do + xhr :get, :index, company_id: company_id assigns(:active_licenses).should == active_licenses end it "returns a json response" do + xhr :get, :index, company_id: company_id expect(-> { JSON.parse(response.body) }).not_to raise_error end + + it "returns the active licenses for a given township" do + xhr :get, :index, company_id: company_id, township: "123" + assigns(:active_licenses).should == active_licenses_in_township + end end end -- cgit v1.2.3 From 676c9df5c6da3f60fd8f1a6184810acff5d74df9 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 20 Feb 2014 20:48:56 -0700 Subject: extract search filter method. --- app/controllers/v1/company_licenses_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 963423a..32e3bc1 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -2,13 +2,22 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company def index - @active_licenses = @company.status(LicenseStatus::ACTIVE) - @active_licenses = @active_licenses.township(params[:township]) if params[:township].present? + @active_licenses = filter_using(@company, search_filters) render json: @active_licenses end private + def search_filters + { status: LicenseStatus::ACTIVE, township: params[:township] } + end + + def filter_using(scope, filters) + result = scope + filters.each { |key, value| result = result.public_send(key, value) if value.present? } + result + end + def load_company @company = Company.find(params[:company_id]) end -- cgit v1.2.3 From caaba52706c1aaba8c0831256d597ec85c473dfc Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 06:40:45 -0700 Subject: extract query method to look up the matching status. --- app/controllers/v1/company_licenses_controller.rb | 2 +- app/models/license_status.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 32e3bc1..234345c 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -9,7 +9,7 @@ class V1::CompanyLicensesController < ApplicationController private def search_filters - { status: LicenseStatus::ACTIVE, township: params[:township] } + { status: LicenseStatus.find_match(params[:status]), township: params[:township] } end def filter_using(scope, filters) diff --git a/app/models/license_status.rb b/app/models/license_status.rb index abe54b1..e22a71c 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -1,3 +1,8 @@ module LicenseStatus ACTIVE="active" + ALL=[ACTIVE] + + def self.find_match(status) + ACTIVE + end end -- cgit v1.2.3 From bd1b2145347c25ee6fba54e306d5e11749e511d0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 06:57:11 -0700 Subject: define relationship between company and licenses and return active licenses. --- app/models/company.rb | 8 +++++++- app/models/license.rb | 2 ++ db/migrate/20140221134937_create_companies.rb | 8 ++++++++ .../20140221135224_add_active_range_to_licenses.rb | 7 +++++++ db/schema.rb | 11 ++++++++++- spec/models/company_spec.rb | 17 +++++++++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20140221134937_create_companies.rb create mode 100644 db/migrate/20140221135224_add_active_range_to_licenses.rb create mode 100644 spec/models/company_spec.rb diff --git a/app/models/company.rb b/app/models/company.rb index bff819b..0959d4d 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,2 +1,8 @@ -class Company +class Company < ActiveRecord::Base + has_many :licenses + + def status(status) + today = DateTime.now + licenses.where('issued_at < ? AND expired_at > ?', today, today) + end end diff --git a/app/models/license.rb b/app/models/license.rb index 8eb7612..d1ce61d 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,4 +1,6 @@ class License < ActiveRecord::Base + belongs_to :company + def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page offset = offset >= 0 ? offset : 0 diff --git a/db/migrate/20140221134937_create_companies.rb b/db/migrate/20140221134937_create_companies.rb new file mode 100644 index 0000000..b2fc820 --- /dev/null +++ b/db/migrate/20140221134937_create_companies.rb @@ -0,0 +1,8 @@ +class CreateCompanies < ActiveRecord::Migration + def change + create_table :companies, id: :uuid do |t| + t.string :name + t.timestamps + end + end +end diff --git a/db/migrate/20140221135224_add_active_range_to_licenses.rb b/db/migrate/20140221135224_add_active_range_to_licenses.rb new file mode 100644 index 0000000..6342f61 --- /dev/null +++ b/db/migrate/20140221135224_add_active_range_to_licenses.rb @@ -0,0 +1,7 @@ +class AddActiveRangeToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :issued_at, :datetime, default: nil + add_column :licenses, :expired_at, :datetime, default: nil + add_column :licenses, :company_id, :uuid + end +end diff --git a/db/schema.rb b/db/schema.rb index ace9922..b359b4b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,15 +11,24 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140221025310) do +ActiveRecord::Schema.define(version: 20140221135224) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp" + create_table "companies", id: :uuid, default: "uuid_generate_v4()", force: true do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "licenses", id: :uuid, default: "uuid_generate_v4()", force: true do |t| t.datetime "created_at" t.datetime "updated_at" + t.datetime "issued_at" + t.datetime "expired_at" + t.uuid "company_id" end end diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb new file mode 100644 index 0000000..f9e0a61 --- /dev/null +++ b/spec/models/company_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe Company do + describe ".status" do + let(:company) { Company.create } + let(:today) { DateTime.now } + let(:active_license) { company.licenses.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } + let(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) } + let(:pending_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now ) } + + it "returns all the licenses that are active" do + licenses = company.status(LicenseStatus::ACTIVE) + licenses.count.should == 0 + licenses.should include(active_license) + end + end +end -- cgit v1.2.3 From 5d937942170c81bcb2304cab1c71eefda48e4e35 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 07:04:37 -0700 Subject: move status filtering behaviour to separate status classes. --- app/models/active_status.rb | 11 +++++++++++ app/models/company.rb | 6 ++++-- app/models/expired_status.rb | 10 ++++++++++ app/models/license_status.rb | 7 ++++--- spec/models/company_spec.rb | 17 +++++++++++++---- 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 app/models/active_status.rb create mode 100644 app/models/expired_status.rb diff --git a/app/models/active_status.rb b/app/models/active_status.rb new file mode 100644 index 0000000..efb2db4 --- /dev/null +++ b/app/models/active_status.rb @@ -0,0 +1,11 @@ +class ActiveStatus + def initialize(name) + @name = name + end + + def filter(licenses) + today = DateTime.now + licenses.where('issued_at < ? AND expired_at > ?', today, today) + end +end + diff --git a/app/models/company.rb b/app/models/company.rb index 0959d4d..7233020 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -2,7 +2,9 @@ class Company < ActiveRecord::Base has_many :licenses def status(status) - today = DateTime.now - licenses.where('issued_at < ? AND expired_at > ?', today, today) + #today = DateTime.now + #licenses.where('issued_at < ? AND expired_at > ?', today, today) + + status.filter(licenses) end end diff --git a/app/models/expired_status.rb b/app/models/expired_status.rb new file mode 100644 index 0000000..11ee7f7 --- /dev/null +++ b/app/models/expired_status.rb @@ -0,0 +1,10 @@ +class ExpiredStatus + def initialize(name) + @name = name + end + + def filter(licenses) + today = DateTime.now + licenses.where('expired_at < ?', today) + end +end diff --git a/app/models/license_status.rb b/app/models/license_status.rb index e22a71c..1c5833f 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -1,6 +1,7 @@ -module LicenseStatus - ACTIVE="active" - ALL=[ACTIVE] +class LicenseStatus + ACTIVE=ActiveStatus.new("active") + EXPIRED=ExpiredStatus.new("expired") + ALL=[ACTIVE, EXPIRED] def self.find_match(status) ACTIVE diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb index f9e0a61..4b5f7ce 100644 --- a/spec/models/company_spec.rb +++ b/spec/models/company_spec.rb @@ -4,14 +4,23 @@ describe Company do describe ".status" do let(:company) { Company.create } let(:today) { DateTime.now } - let(:active_license) { company.licenses.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } - let(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) } - let(:pending_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now ) } + let!(:active_license) { company.licenses.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } + let!(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) } + let!(:pending_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now ) } it "returns all the licenses that are active" do licenses = company.status(LicenseStatus::ACTIVE) - licenses.count.should == 0 + licenses.count.should == 1 licenses.should include(active_license) end + + it "returns all expired licenses" do + licenses = company.status(LicenseStatus::EXPIRED) + licenses.count.should == 1 + licenses.should include(expired_license) + end + + pending "returns all confidential licenses" do + end end end -- cgit v1.2.3 From fbb41be394f841ce0878eb0512fbacff1a588ab7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 20:27:36 -0700 Subject: add confidential well license status. --- app/models/company.rb | 3 --- app/models/license_status.rb | 4 +++- app/models/license_status/confidential.rb | 5 +++++ db/migrate/20140222032401_add_confidential_to_licenses.rb | 5 +++++ db/schema.rb | 3 ++- spec/models/company_spec.rb | 7 +++++-- 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 app/models/license_status/confidential.rb create mode 100644 db/migrate/20140222032401_add_confidential_to_licenses.rb diff --git a/app/models/company.rb b/app/models/company.rb index 7233020..4b6e798 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -2,9 +2,6 @@ class Company < ActiveRecord::Base has_many :licenses def status(status) - #today = DateTime.now - #licenses.where('issued_at < ? AND expired_at > ?', today, today) - status.filter(licenses) end end diff --git a/app/models/license_status.rb b/app/models/license_status.rb index 1c5833f..82af2fd 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -1,7 +1,9 @@ class LicenseStatus ACTIVE=ActiveStatus.new("active") EXPIRED=ExpiredStatus.new("expired") - ALL=[ACTIVE, EXPIRED] + CONFIDENTIAL=Confidential.new + + ALL=[ACTIVE, EXPIRED, CONFIDENTIAL] def self.find_match(status) ACTIVE diff --git a/app/models/license_status/confidential.rb b/app/models/license_status/confidential.rb new file mode 100644 index 0000000..f3e980a --- /dev/null +++ b/app/models/license_status/confidential.rb @@ -0,0 +1,5 @@ +class LicenseStatus::Confidential + def filter(licenses) + licenses.where(confidential: true) + end +end diff --git a/db/migrate/20140222032401_add_confidential_to_licenses.rb b/db/migrate/20140222032401_add_confidential_to_licenses.rb new file mode 100644 index 0000000..7d752c8 --- /dev/null +++ b/db/migrate/20140222032401_add_confidential_to_licenses.rb @@ -0,0 +1,5 @@ +class AddConfidentialToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :confidential, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index b359b4b..453bf07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140221135224) do +ActiveRecord::Schema.define(version: 20140222032401) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20140221135224) do t.datetime "issued_at" t.datetime "expired_at" t.uuid "company_id" + t.boolean "confidential", default: false end end diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb index 4b5f7ce..1acef1c 100644 --- a/spec/models/company_spec.rb +++ b/spec/models/company_spec.rb @@ -6,7 +6,7 @@ describe Company do let(:today) { DateTime.now } let!(:active_license) { company.licenses.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } let!(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) } - let!(:pending_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now ) } + let!(:confidential_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) } it "returns all the licenses that are active" do licenses = company.status(LicenseStatus::ACTIVE) @@ -20,7 +20,10 @@ describe Company do licenses.should include(expired_license) end - pending "returns all confidential licenses" do + it "returns all confidential licenses" do + licenses = company.status(LicenseStatus::CONFIDENTIAL) + licenses.count.should == 1 + licenses.should include(confidential_license) end end end -- cgit v1.2.3 From 57170cae301215b992f398853732d00e7efe3119 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 20:30:42 -0700 Subject: move active and expired to license status namespace. --- app/models/active_status.rb | 11 ----------- app/models/expired_status.rb | 10 ---------- app/models/license_status.rb | 4 ++-- app/models/license_status/active.rb | 7 +++++++ app/models/license_status/expired.rb | 6 ++++++ 5 files changed, 15 insertions(+), 23 deletions(-) delete mode 100644 app/models/active_status.rb delete mode 100644 app/models/expired_status.rb create mode 100644 app/models/license_status/active.rb create mode 100644 app/models/license_status/expired.rb diff --git a/app/models/active_status.rb b/app/models/active_status.rb deleted file mode 100644 index efb2db4..0000000 --- a/app/models/active_status.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ActiveStatus - def initialize(name) - @name = name - end - - def filter(licenses) - today = DateTime.now - licenses.where('issued_at < ? AND expired_at > ?', today, today) - end -end - diff --git a/app/models/expired_status.rb b/app/models/expired_status.rb deleted file mode 100644 index 11ee7f7..0000000 --- a/app/models/expired_status.rb +++ /dev/null @@ -1,10 +0,0 @@ -class ExpiredStatus - def initialize(name) - @name = name - end - - def filter(licenses) - today = DateTime.now - licenses.where('expired_at < ?', today) - end -end diff --git a/app/models/license_status.rb b/app/models/license_status.rb index 82af2fd..998792f 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -1,6 +1,6 @@ class LicenseStatus - ACTIVE=ActiveStatus.new("active") - EXPIRED=ExpiredStatus.new("expired") + ACTIVE=Active.new + EXPIRED=Expired.new CONFIDENTIAL=Confidential.new ALL=[ACTIVE, EXPIRED, CONFIDENTIAL] diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb new file mode 100644 index 0000000..80d950d --- /dev/null +++ b/app/models/license_status/active.rb @@ -0,0 +1,7 @@ +class LicenseStatus::Active + def filter(licenses) + today = DateTime.now + licenses.where('issued_at < ? AND expired_at > ?', today, today) + end +end + diff --git a/app/models/license_status/expired.rb b/app/models/license_status/expired.rb new file mode 100644 index 0000000..1b339c6 --- /dev/null +++ b/app/models/license_status/expired.rb @@ -0,0 +1,6 @@ +class LicenseStatus::Expired + def filter(licenses) + today = DateTime.now + licenses.where('expired_at < ?', today) + end +end -- cgit v1.2.3 From ea2de48ec543fb341be31e9ed312b72ede860aee Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 20:51:30 -0700 Subject: inplement query method to find matching status strategy. --- app/models/license_status.rb | 4 ++-- app/models/license_status/active.rb | 4 ++++ app/models/license_status/confidential.rb | 4 ++++ app/models/license_status/expired.rb | 4 ++++ spec/models/license_status_spec.rb | 29 +++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 spec/models/license_status_spec.rb diff --git a/app/models/license_status.rb b/app/models/license_status.rb index 998792f..41b54c5 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -5,7 +5,7 @@ class LicenseStatus ALL=[ACTIVE, EXPIRED, CONFIDENTIAL] - def self.find_match(status) - ACTIVE + def self.find_match(status = "") + ALL.find { |x| x.matches?("#{status}".downcase) } || ACTIVE end end diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb index 80d950d..76fb4c0 100644 --- a/app/models/license_status/active.rb +++ b/app/models/license_status/active.rb @@ -3,5 +3,9 @@ class LicenseStatus::Active today = DateTime.now licenses.where('issued_at < ? AND expired_at > ?', today, today) end + + def matches?(name) + "active" == name + end end diff --git a/app/models/license_status/confidential.rb b/app/models/license_status/confidential.rb index f3e980a..81178f6 100644 --- a/app/models/license_status/confidential.rb +++ b/app/models/license_status/confidential.rb @@ -2,4 +2,8 @@ class LicenseStatus::Confidential def filter(licenses) licenses.where(confidential: true) end + + def matches?(name) + "confidential" == name + end end diff --git a/app/models/license_status/expired.rb b/app/models/license_status/expired.rb index 1b339c6..393e34f 100644 --- a/app/models/license_status/expired.rb +++ b/app/models/license_status/expired.rb @@ -3,4 +3,8 @@ class LicenseStatus::Expired today = DateTime.now licenses.where('expired_at < ?', today) end + + def matches?(name) + "expired" == name + end end diff --git a/spec/models/license_status_spec.rb b/spec/models/license_status_spec.rb new file mode 100644 index 0000000..09e2319 --- /dev/null +++ b/spec/models/license_status_spec.rb @@ -0,0 +1,29 @@ +require "spec_helper" + +describe LicenseStatus do + describe ".find_match" do + it "returns the active status" do + LicenseStatus.find_match("active").should == LicenseStatus::ACTIVE + LicenseStatus.find_match("ACTIVE").should == LicenseStatus::ACTIVE + LicenseStatus.find_match("Active").should == LicenseStatus::ACTIVE + end + + it "returns the expired status" do + LicenseStatus.find_match("expired").should == LicenseStatus::EXPIRED + LicenseStatus.find_match("EXPIRED").should == LicenseStatus::EXPIRED + LicenseStatus.find_match("Expired").should == LicenseStatus::EXPIRED + end + + it "returns the confidential status" do + LicenseStatus.find_match("confidential").should == LicenseStatus::CONFIDENTIAL + LicenseStatus.find_match("CONFIDENTIAL").should == LicenseStatus::CONFIDENTIAL + LicenseStatus.find_match("Confidential").should == LicenseStatus::CONFIDENTIAL + end + + it "returns the active status as the default" do + [nil, "", "oh hai"].each do |key| + LicenseStatus.find_match(key).should == LicenseStatus::ACTIVE + end + end + end +end -- cgit v1.2.3 From f6eebdeb6aa56c4734102caf1817479d9e7b2765 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 20:57:18 -0700 Subject: load well statuses and well types with each request to the company licenses controller. --- app/controllers/v1/company_licenses_controller.rb | 6 ++++++ app/models/well_type.rb | 3 +++ spec/controllers/v1/company_licenses_controller_spec.rb | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 app/models/well_type.rb diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 234345c..df0c4ec 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -1,5 +1,6 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company + before_filter :load_additional_payload_data def index @active_licenses = filter_using(@company, search_filters) @@ -21,4 +22,9 @@ class V1::CompanyLicensesController < ApplicationController def load_company @company = Company.find(params[:company_id]) end + + def load_additional_payload_data + @license_statuses = LicenseStatus::ALL + @well_types = WellType::ALL + end end diff --git a/app/models/well_type.rb b/app/models/well_type.rb new file mode 100644 index 0000000..5367ce2 --- /dev/null +++ b/app/models/well_type.rb @@ -0,0 +1,3 @@ +class WellType + ALL=[] +end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index 2784a1d..c139f8b 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -27,5 +27,15 @@ describe V1::CompanyLicensesController do xhr :get, :index, company_id: company_id, township: "123" assigns(:active_licenses).should == active_licenses_in_township end + + it "includes each well status" do + xhr :get, :index, company_id: company_id + assigns(:license_statuses).should =~ LicenseStatus::ALL + end + + it "includes each well type" do + xhr :get, :index, company_id: company_id + assigns(:well_types).should =~ WellType::ALL + end end end -- cgit v1.2.3 From 4f6de445141fc5542f61a1830c29ad61ecbeb49b Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:03:56 -0700 Subject: load well statuses and well types in application controller. --- app/controllers/application_controller.rb | 8 +++++++- app/controllers/v1/company_licenses_controller.rb | 6 ------ spec/controllers/application_controller_spec.rb | 19 +++++++++++++++++++ .../v1/company_licenses_controller_spec.rb | 10 ---------- 4 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 spec/controllers/application_controller_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..658a065 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,11 @@ 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 + protect_from_forgery with: :null_session + before_filter :load_additional_payload_data + + def load_additional_payload_data + @license_statuses = LicenseStatus::ALL + @well_types = WellType::ALL + end end diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index df0c4ec..234345c 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -1,6 +1,5 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company - before_filter :load_additional_payload_data def index @active_licenses = filter_using(@company, search_filters) @@ -22,9 +21,4 @@ class V1::CompanyLicensesController < ApplicationController def load_company @company = Company.find(params[:company_id]) end - - def load_additional_payload_data - @license_statuses = LicenseStatus::ALL - @well_types = WellType::ALL - end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb new file mode 100644 index 0000000..a26c465 --- /dev/null +++ b/spec/controllers/application_controller_spec.rb @@ -0,0 +1,19 @@ +require "spec_helper" + +describe ApplicationController do + controller do + def index + render nothing: true + end + end + + it "includes all well statuses with every response" do + get :index + assigns(:license_statuses).should =~ LicenseStatus::ALL + end + + it "includes all well types with every response" do + get :index + assigns(:well_types).should =~ WellType::ALL + end +end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index c139f8b..2784a1d 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -27,15 +27,5 @@ describe V1::CompanyLicensesController do xhr :get, :index, company_id: company_id, township: "123" assigns(:active_licenses).should == active_licenses_in_township end - - it "includes each well status" do - xhr :get, :index, company_id: company_id - assigns(:license_statuses).should =~ LicenseStatus::ALL - end - - it "includes each well type" do - xhr :get, :index, company_id: company_id - assigns(:well_types).should =~ WellType::ALL - end end end -- cgit v1.2.3 From 5f5269f7a58180a77686677f76baa6d1566cd494 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:09:19 -0700 Subject: add root route to licenses. --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index b61e488..39fc8ea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,4 +5,5 @@ CodeChallengeMo::Application.routes.draw do resources :licenses, controller: 'company_licenses', only: [:index] end end + root to: 'v1/licenses#index' end -- cgit v1.2.3 From f3b3b2fc4b52694def53309ea2955ef28a44a8a0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:12:24 -0700 Subject: specify ruby in gemfile. --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index ee76893..5b538f8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ source 'https://rubygems.org' +ruby '2.1.0' gem 'rails', '4.0.3' gem 'jbuilder', '~> 1.2' -- cgit v1.2.3 From 43e38c3dc960a11e90bd2a028efab4ba77f1cd47 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:17:05 -0700 Subject: use unicorn. --- Gemfile | 4 ++++ Gemfile.lock | 7 +++++++ Procfile | 1 + config/unicorn.rb | 20 ++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 Procfile create mode 100644 config/unicorn.rb diff --git a/Gemfile b/Gemfile index 5b538f8..15bdfc8 100644 --- a/Gemfile +++ b/Gemfile @@ -13,3 +13,7 @@ end group :development, :test do gem 'rspec-rails' end + +group :production do + gem 'unicorn' +end diff --git a/Gemfile.lock b/Gemfile.lock index 3f653bd..860c002 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM activesupport (>= 3.0.0) multi_json (>= 1.2.0) json (1.8.1) + kgio (2.9.2) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -60,6 +61,7 @@ GEM activesupport (= 4.0.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.13.0) rake (10.1.1) rdoc (4.1.1) json (~> 1.4) @@ -95,6 +97,10 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.38) + unicorn (4.8.2) + kgio (~> 2.6) + rack + raindrops (~> 0.7) PLATFORMS ruby @@ -105,3 +111,4 @@ DEPENDENCIES rails (= 4.0.3) rspec-rails sdoc + unicorn diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9c82374 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..729ff4d --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,20 @@ +worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) +timeout 15 +preload_app true + +before_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn master intercepting TERM and sending myself QUIT instead' + Process.kill 'QUIT', Process.pid + end + + defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! +end + +after_fork do |server, worker| + Signal.trap 'TERM' do + puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' + end + + defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection +end -- cgit v1.2.3 From b84a691bc4de6dfd61b608e01afecf7570d768f1 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:26:28 -0700 Subject: add deploy script. --- bin/deploy | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 bin/deploy diff --git a/bin/deploy b/bin/deploy new file mode 100755 index 0000000..c7cac2c --- /dev/null +++ b/bin/deploy @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +git push heroku master +heroku run rake db:migrate -- cgit v1.2.3 From fe13da4831bade3b7292d5143ab7267edd4a63df Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:32:10 -0700 Subject: add script to tail heroku logs. --- bin/deploy | 5 ----- bin/deploy.sh | 5 +++++ bin/logs.sh | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) delete mode 100755 bin/deploy create mode 100755 bin/deploy.sh create mode 100755 bin/logs.sh diff --git a/bin/deploy b/bin/deploy deleted file mode 100755 index c7cac2c..0000000 --- a/bin/deploy +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -git push heroku master -heroku run rake db:migrate diff --git a/bin/deploy.sh b/bin/deploy.sh new file mode 100755 index 0000000..c7cac2c --- /dev/null +++ b/bin/deploy.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +git push heroku master +heroku run rake db:migrate diff --git a/bin/logs.sh b/bin/logs.sh new file mode 100755 index 0000000..3662a74 --- /dev/null +++ b/bin/logs.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +heroku logs --tail --app infinite-atoll-2481 -- cgit v1.2.3 From 476bee1ff1e1c0d4fe553898f5f029530a41919c Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 21:54:15 -0700 Subject: start to build the json specs. --- app/views/v1/company_licenses/index.jbuilder | 9 +++++++++ .../v1/company_licenses/index.json.jbuilder_spec.rb | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/views/v1/company_licenses/index.jbuilder create mode 100644 spec/views/v1/company_licenses/index.json.jbuilder_spec.rb diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder new file mode 100644 index 0000000..ff31792 --- /dev/null +++ b/app/views/v1/company_licenses/index.jbuilder @@ -0,0 +1,9 @@ +json.array! @licenses do |license| + json.issued_at license.issued_at.to_s + json.expired_at license.expired_at.to_s + json.well_type do + json.id 1 + json.pneumonic "NFW" + json.name "New Field Wildcat" + end +end diff --git a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb new file mode 100644 index 0000000..52b5fe5 --- /dev/null +++ b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb @@ -0,0 +1,18 @@ +require "spec_helper" + +describe 'v1/company_licenses/index' do + let!(:company) { Company.create(name: 'acme') } + let!(:license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + + before :each do + assign(:licenses, company.licenses) + render + end + + let(:result) { JSON.parse(rendered) } + + it "includes the license date range" do + result.first["issued_at"].should == license.issued_at.to_s + result.first["expired_at"].should == license.expired_at.to_s + end +end -- cgit v1.2.3 From 60aa8fa77deaf9d4c90c1ede37caeeff13ee283d Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:27:13 -0700 Subject: define well types table. --- app/models/location.rb | 4 ++++ app/models/user.rb | 16 ++++++++++++++++ app/models/well_type.rb | 10 ++++++++-- db/migrate/20140222051253_create_well_types.rb | 8 ++++++++ db/schema.rb | 7 ++++++- db/seeds.rb | 10 +++++----- spec/models/license_spec.rb | 14 ++++++++++++++ spec/spec_helper.rb | 3 +++ 8 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 app/models/location.rb create mode 100644 app/models/user.rb create mode 100644 db/migrate/20140222051253_create_well_types.rb diff --git a/app/models/location.rb b/app/models/location.rb new file mode 100644 index 0000000..611ae87 --- /dev/null +++ b/app/models/location.rb @@ -0,0 +1,4 @@ +class Location + def initialize(latitude: 0, longitude: 0, township: 'unknown') + end +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..7085ac2 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,16 @@ +class User + attr_reader :company + + def initialize(company: nil) + @company = company + end + + def apply_for(well_type, location) + license = License.new + license.company = company + license.well_type = well_type + license.location = location + license.applicant = self + license + end +end diff --git a/app/models/well_type.rb b/app/models/well_type.rb index 5367ce2..361dd99 100644 --- a/app/models/well_type.rb +++ b/app/models/well_type.rb @@ -1,3 +1,9 @@ -class WellType - ALL=[] +class WellType < ActiveRecord::Base + NFW=WellType.find_by_id(1) + NPW=WellType.find_by_id(2) + DPT=WellType.find_by_id(3) + SPT=WellType.find_by_id(4) + DEV=WellType.find_by_id(5) + + ALL=[NFW, NPW, DPT, SPT, DEV] end diff --git a/db/migrate/20140222051253_create_well_types.rb b/db/migrate/20140222051253_create_well_types.rb new file mode 100644 index 0000000..aa22bca --- /dev/null +++ b/db/migrate/20140222051253_create_well_types.rb @@ -0,0 +1,8 @@ +class CreateWellTypes < ActiveRecord::Migration + def change + create_table :well_types do |t| + t.string :name + t.string :acronym + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 453bf07..aa1c471 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222032401) do +ActiveRecord::Schema.define(version: 20140222051253) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,4 +32,9 @@ ActiveRecord::Schema.define(version: 20140222032401) do t.boolean "confidential", default: false end + create_table "well_types", force: true do |t| + t.string "name" + t.string "acronym" + end + end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..b9d9ff1 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,7 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). -# -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) +WellType.create(id: 1, acronym: "NFW", name: "New Field Wildcat") unless WellType.exists?(1) +WellType.create(id: 2, acronym: "NPW", name: "New Pool Wildcat") unless WellType.exists?(2) +WellType.create(id: 3, acronym: "DPT", name: "Deeper Pool Test") unless WellType.exists?(3) +WellType.create(id: 4, acronym: "SPT", name: "Shallower Pool Test") unless WellType.exists?(4) +WellType.create(id: 5, acronym: "DEV", name: "Development Well") unless WellType.exists?(5) diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index a939372..d35c51f 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -29,4 +29,18 @@ describe License do results.first.should == newest_license end end + + describe "model" do + it "looks like this" do + company = Company.create(name: 'ABC Resources Ltd.') + user = User.new(company: company) + location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') + license = user.apply_for(WellType::NFW, location) + + license.company.should == user.company + license.well_type.should == WellType::NFW + license.location.should == location + license.applicant.should == user + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 943bc19..09b0309 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,4 +39,7 @@ RSpec.configure do |config| # the seed, which is printed after each run. # --seed 1234 config.order = "random" + config.before(:suite) do + require "#{Rails.root}/db/seeds" + end end -- cgit v1.2.3 From b50a9b42f1cddc78f75f75913f39bd19fbf4d8d5 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:31:38 -0700 Subject: add well type to licenses table. --- app/models/license.rb | 1 + .../20140222052902_add_well_type_to_licenses.rb | 5 +++++ db/schema.rb | 3 ++- spec/models/license_spec.rb | 22 ++++++++++++---------- 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20140222052902_add_well_type_to_licenses.rb diff --git a/app/models/license.rb b/app/models/license.rb index d1ce61d..3da7b24 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,5 +1,6 @@ class License < ActiveRecord::Base belongs_to :company + belongs_to :well_type def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page diff --git a/db/migrate/20140222052902_add_well_type_to_licenses.rb b/db/migrate/20140222052902_add_well_type_to_licenses.rb new file mode 100644 index 0000000..bc1dded --- /dev/null +++ b/db/migrate/20140222052902_add_well_type_to_licenses.rb @@ -0,0 +1,5 @@ +class AddWellTypeToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :well_type_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index aa1c471..d6e0d44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222051253) do +ActiveRecord::Schema.define(version: 20140222052902) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -30,6 +30,7 @@ ActiveRecord::Schema.define(version: 20140222051253) do t.datetime "expired_at" t.uuid "company_id" t.boolean "confidential", default: false + t.integer "well_type_id" end create_table "well_types", force: true do |t| diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index d35c51f..ac4c37c 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -30,17 +30,19 @@ describe License do end end - describe "model" do - it "looks like this" do - company = Company.create(name: 'ABC Resources Ltd.') - user = User.new(company: company) - location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') - license = user.apply_for(WellType::NFW, location) + describe "#apply_for" do + context "when applying for a license" do + it "creates a new license" do + company = Company.create(name: 'ABC Resources Ltd.') + user = User.new(company: company) + location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') + license = user.apply_for(WellType::NFW, location) - license.company.should == user.company - license.well_type.should == WellType::NFW - license.location.should == location - license.applicant.should == user + license.company.should == user.company + license.well_type.should == WellType::NFW + license.location.should == location + license.applicant.should == user + end end end end -- cgit v1.2.3 From e7902a5ecf47391c50290c06c2df06732a5c6fd0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:36:24 -0700 Subject: create location model. --- app/models/license.rb | 1 + app/models/location.rb | 5 ++--- app/models/user.rb | 3 ++- db/migrate/20140222053352_create_locations.rb | 11 +++++++++++ db/schema.rb | 11 ++++++++++- spec/models/license_spec.rb | 2 +- 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20140222053352_create_locations.rb diff --git a/app/models/license.rb b/app/models/license.rb index 3da7b24..ccf9b23 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,6 +1,7 @@ class License < ActiveRecord::Base belongs_to :company belongs_to :well_type + has_one :location def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page diff --git a/app/models/location.rb b/app/models/location.rb index 611ae87..bf7b7ef 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,4 +1,3 @@ -class Location - def initialize(latitude: 0, longitude: 0, township: 'unknown') - end +class Location < ActiveRecord::Base + belongs_to :license end diff --git a/app/models/user.rb b/app/models/user.rb index 7085ac2..f2197dd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,7 +10,8 @@ class User license.company = company license.well_type = well_type license.location = location - license.applicant = self + #license.applicant = self + license.save! license end end diff --git a/db/migrate/20140222053352_create_locations.rb b/db/migrate/20140222053352_create_locations.rb new file mode 100644 index 0000000..c5faa93 --- /dev/null +++ b/db/migrate/20140222053352_create_locations.rb @@ -0,0 +1,11 @@ +class CreateLocations < ActiveRecord::Migration + def change + create_table :locations do |t| + t.uuid :license_id + t.float :latitude + t.float :longitude + t.string :township + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d6e0d44..f34633a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222052902) do +ActiveRecord::Schema.define(version: 20140222053352) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -33,6 +33,15 @@ ActiveRecord::Schema.define(version: 20140222052902) do t.integer "well_type_id" end + create_table "locations", force: true do |t| + t.uuid "license_id" + t.float "latitude" + t.float "longitude" + t.string "township" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "well_types", force: true do |t| t.string "name" t.string "acronym" diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index ac4c37c..8fbf01a 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -41,7 +41,7 @@ describe License do license.company.should == user.company license.well_type.should == WellType::NFW license.location.should == location - license.applicant.should == user + #license.applicant.should == user end end end -- cgit v1.2.3 From bf5c3435155c0ee9c2172bea6b6b3c5dec2c2463 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:40:59 -0700 Subject: use a uuid as the primary key for locations. --- db/migrate/20140222053352_create_locations.rb | 2 +- db/schema.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20140222053352_create_locations.rb b/db/migrate/20140222053352_create_locations.rb index c5faa93..fb2bca2 100644 --- a/db/migrate/20140222053352_create_locations.rb +++ b/db/migrate/20140222053352_create_locations.rb @@ -1,6 +1,6 @@ class CreateLocations < ActiveRecord::Migration def change - create_table :locations do |t| + create_table :locations, id: :uuid do |t| t.uuid :license_id t.float :latitude t.float :longitude diff --git a/db/schema.rb b/db/schema.rb index f34633a..c9d8190 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -33,7 +33,7 @@ ActiveRecord::Schema.define(version: 20140222053352) do t.integer "well_type_id" end - create_table "locations", force: true do |t| + create_table "locations", id: :uuid, default: "uuid_generate_v4()", force: true do |t| t.uuid "license_id" t.float "latitude" t.float "longitude" -- cgit v1.2.3 From 33cb4e479decb1f7e15048b8c81924fe7498aec1 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:57:51 -0700 Subject: create users table and save applicant with the license. --- app/models/license.rb | 1 + app/models/user.rb | 10 +++------- db/migrate/20140222054248_create_users.rb | 8 ++++++++ .../20140222055630_add_applicant_to_licenses.rb | 5 +++++ db/schema.rb | 9 ++++++++- spec/models/license_spec.rb | 16 ---------------- spec/models/user_spec.rb | 19 +++++++++++++++++++ 7 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20140222054248_create_users.rb create mode 100644 db/migrate/20140222055630_add_applicant_to_licenses.rb create mode 100644 spec/models/user_spec.rb diff --git a/app/models/license.rb b/app/models/license.rb index ccf9b23..6170683 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -2,6 +2,7 @@ class License < ActiveRecord::Base belongs_to :company belongs_to :well_type has_one :location + belongs_to :applicant, class_name: 'User', foreign_key: 'user_id' def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page diff --git a/app/models/user.rb b/app/models/user.rb index f2197dd..446d3e2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,16 +1,12 @@ -class User - attr_reader :company - - def initialize(company: nil) - @company = company - end +class User < ActiveRecord::Base + belongs_to :company def apply_for(well_type, location) license = License.new license.company = company license.well_type = well_type license.location = location - #license.applicant = self + license.applicant = self license.save! license end diff --git a/db/migrate/20140222054248_create_users.rb b/db/migrate/20140222054248_create_users.rb new file mode 100644 index 0000000..791bf2f --- /dev/null +++ b/db/migrate/20140222054248_create_users.rb @@ -0,0 +1,8 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users, id: :uuid do |t| + t.uuid :company_id + t.timestamps + end + end +end diff --git a/db/migrate/20140222055630_add_applicant_to_licenses.rb b/db/migrate/20140222055630_add_applicant_to_licenses.rb new file mode 100644 index 0000000..ca96b8f --- /dev/null +++ b/db/migrate/20140222055630_add_applicant_to_licenses.rb @@ -0,0 +1,5 @@ +class AddApplicantToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :user_id, :uuid + end +end diff --git a/db/schema.rb b/db/schema.rb index c9d8190..d58c3ae 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222053352) do +ActiveRecord::Schema.define(version: 20140222055630) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -31,6 +31,7 @@ ActiveRecord::Schema.define(version: 20140222053352) do t.uuid "company_id" t.boolean "confidential", default: false t.integer "well_type_id" + t.uuid "user_id" end create_table "locations", id: :uuid, default: "uuid_generate_v4()", force: true do |t| @@ -42,6 +43,12 @@ ActiveRecord::Schema.define(version: 20140222053352) do t.datetime "updated_at" end + create_table "users", id: :uuid, default: "uuid_generate_v4()", force: true do |t| + t.uuid "company_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "well_types", force: true do |t| t.string "name" t.string "acronym" diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index 8fbf01a..a939372 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -29,20 +29,4 @@ describe License do results.first.should == newest_license end end - - describe "#apply_for" do - context "when applying for a license" do - it "creates a new license" do - company = Company.create(name: 'ABC Resources Ltd.') - user = User.new(company: company) - location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') - license = user.apply_for(WellType::NFW, location) - - license.company.should == user.company - license.well_type.should == WellType::NFW - license.location.should == location - #license.applicant.should == user - end - end - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..02e52be --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,19 @@ +require "spec_helper" + +describe User do + describe "#apply_for" do + context "when applying for a license" do + it "creates a new license" do + company = Company.create(name: 'ABC Resources Ltd.') + user = User.create(company: company) + location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') + license = user.apply_for(WellType::NFW, location) + + license.company.should == user.company + license.well_type.should == WellType::NFW + license.location.should == location + license.applicant.should == user + end + end + end +end -- cgit v1.2.3 From dcb8cddfc3adeb3be6885c00933f1354d3d1e576 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:59:41 -0700 Subject: rename method and use relation to create new license. --- app/models/user.rb | 10 ++-------- spec/models/user_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 446d3e2..056039b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,13 +1,7 @@ class User < ActiveRecord::Base belongs_to :company - def apply_for(well_type, location) - license = License.new - license.company = company - license.well_type = well_type - license.location = location - license.applicant = self - license.save! - license + def apply_for_license(well_type, location) + company.licenses.create(well_type: well_type, location: location, applicant: self) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 02e52be..4db73fd 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,13 +1,13 @@ require "spec_helper" describe User do - describe "#apply_for" do + describe "#apply_for_license" do context "when applying for a license" do it "creates a new license" do company = Company.create(name: 'ABC Resources Ltd.') user = User.create(company: company) location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') - license = user.apply_for(WellType::NFW, location) + license = user.apply_for_license(WellType::NFW, location) license.company.should == user.company license.well_type.should == WellType::NFW -- cgit v1.2.3 From d0aaa1ee5724c4981aba10efeb7e9abde27da13d Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:29:26 -0700 Subject: add integration test and add township query method. --- app/models/company.rb | 2 +- app/models/license.rb | 8 ++++++++ spec/controllers/v1/company_licenses_controller_spec.rb | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/company.rb b/app/models/company.rb index 4b6e798..7691bf5 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -2,6 +2,6 @@ class Company < ActiveRecord::Base has_many :licenses def status(status) - status.filter(licenses) + licenses.status(status) end end diff --git a/app/models/license.rb b/app/models/license.rb index 6170683..77aad5f 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -9,4 +9,12 @@ class License < ActiveRecord::Base offset = offset >= 0 ? offset : 0 License.order(created_at: :desc).offset(offset).limit(per_page) end + + def self.township(township) + joins(:location).where('locations.township = ?', township) + end + + def self.status(status) + status.filter(self) + end end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index 2784a1d..198b4f3 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -28,4 +28,17 @@ describe V1::CompanyLicensesController do assigns(:active_licenses).should == active_licenses_in_township end end + + describe :integration do + describe :index do + let(:company) { Company.create(name: 'ABC Resources Ltd.') } + let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } + let!(:license) { company.licenses.create(well_type: WellType::DEV, location: location, issued_at: 2.days.ago, expired_at: 1.day.ago) } + + it "finds expired licenses from a specific township" do + xhr :get, :index, company_id: company.id, status: "expired", township: "1" + assigns(:active_licenses).should include(license) + end + end + end end -- cgit v1.2.3 From daf9b2bb2302e0d8901dd6dee12468f72d5b1ea7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:33:01 -0700 Subject: add spec for License.township. --- spec/models/license_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index a939372..a53fcbe 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -29,4 +29,17 @@ describe License do results.first.should == newest_license end end + + describe ".township" do + let(:location) { Location.create(township: "2") } + let!(:license) { License.create(location: location) } + let(:other_location) { Location.create(township: "1") } + let!(:other_license) { License.create(location: other_location) } + + it "returns a license in the township" do + results = License.township("2") + results.count.should == 1 + results.should include(license) + end + end end -- cgit v1.2.3 From 6f1ae8d74d3e9c7837e8b0bbdfc4c5f1ee354a8c Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:33:58 -0700 Subject: replace string with hash notation. --- app/models/license.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/license.rb b/app/models/license.rb index 77aad5f..2b4fc3c 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -11,7 +11,7 @@ class License < ActiveRecord::Base end def self.township(township) - joins(:location).where('locations.township = ?', township) + joins(:location).where(locations: { township: township }) end def self.status(status) -- cgit v1.2.3 From 18e3102f4e64d206c72efb28bbe7021b1ba09a16 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:35:23 -0700 Subject: add License.status specs. --- spec/models/license_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index a53fcbe..7df556e 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -42,4 +42,29 @@ describe License do results.should include(license) end end + + describe ".status" do + let(:today) { DateTime.now } + let!(:active_license) { License.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } + let!(:expired_license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) } + let!(:confidential_license) { License.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) } + + it "returns all the licenses that are active" do + licenses = License.status(LicenseStatus::ACTIVE) + licenses.count.should == 1 + licenses.should include(active_license) + end + + it "returns all expired licenses" do + licenses = License.status(LicenseStatus::EXPIRED) + licenses.count.should == 1 + licenses.should include(expired_license) + end + + it "returns all confidential licenses" do + licenses = License.status(LicenseStatus::CONFIDENTIAL) + licenses.count.should == 1 + licenses.should include(confidential_license) + end + end end -- cgit v1.2.3 From 39fc3e184c1c185ffc9fc1f17bd19c5a8d9d0106 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:43:42 -0700 Subject: move search filter method from controller down to model. --- app/controllers/v1/company_licenses_controller.rb | 8 +------- app/models/company.rb | 6 ++++++ spec/controllers/v1/company_licenses_controller_spec.rb | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 234345c..3b4850f 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -2,7 +2,7 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company def index - @active_licenses = filter_using(@company, search_filters) + @active_licenses = @company.filter_licenses_using(search_filters) render json: @active_licenses end @@ -12,12 +12,6 @@ class V1::CompanyLicensesController < ApplicationController { status: LicenseStatus.find_match(params[:status]), township: params[:township] } end - def filter_using(scope, filters) - result = scope - filters.each { |key, value| result = result.public_send(key, value) if value.present? } - result - end - def load_company @company = Company.find(params[:company_id]) end diff --git a/app/models/company.rb b/app/models/company.rb index 7691bf5..630610f 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -4,4 +4,10 @@ class Company < ActiveRecord::Base def status(status) licenses.status(status) end + + def filter_licenses_using(search_filters) + result = self.licenses + search_filters.each { |key, value| result = result.public_send(key, value) if value.present? } + result + end end diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index 198b4f3..e811179 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -2,18 +2,18 @@ require "spec_helper" describe V1::CompanyLicensesController do describe :index do - let(:company) { Object.new } + let(:company) { Company.new } let(:company_id) { SecureRandom.uuid } let(:active_licenses) { ["active"] } let(:active_licenses_in_township) { ["active township"] } before :each do Company.stub(:find).with(company_id).and_return(company) - company.stub(:status).with(LicenseStatus::ACTIVE).and_return(active_licenses) active_licenses.stub(:township).with("123").and_return(active_licenses_in_township) end it "returns the active licenses" do + company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: nil}).and_return(active_licenses) xhr :get, :index, company_id: company_id assigns(:active_licenses).should == active_licenses end @@ -24,6 +24,7 @@ describe V1::CompanyLicensesController do end it "returns the active licenses for a given township" do + company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: "123"}).and_return(active_licenses_in_township) xhr :get, :index, company_id: company_id, township: "123" assigns(:active_licenses).should == active_licenses_in_township end -- cgit v1.2.3 From 842ee349392844ff08e818151a8eb5ca00b67d10 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:50:52 -0700 Subject: refactor specs to target the filter licenses method. --- app/models/company.rb | 4 ---- spec/models/company_spec.rb | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/models/company.rb b/app/models/company.rb index 630610f..c1c2d9f 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,10 +1,6 @@ class Company < ActiveRecord::Base has_many :licenses - def status(status) - licenses.status(status) - end - def filter_licenses_using(search_filters) result = self.licenses search_filters.each { |key, value| result = result.public_send(key, value) if value.present? } diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb index 1acef1c..4f0a322 100644 --- a/spec/models/company_spec.rb +++ b/spec/models/company_spec.rb @@ -1,29 +1,31 @@ require "spec_helper" describe Company do - describe ".status" do + describe "#filter_licenses_using" do let(:company) { Company.create } - let(:today) { DateTime.now } + let(:calgary) { Location.create(township: 'calgary') } + let(:edmonton) { Location.create(township: 'edmonton') } let!(:active_license) { company.licenses.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } - let!(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) } - let!(:confidential_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) } + let!(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago, location: calgary) } + let!(:other_expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago, location: edmonton) } it "returns all the licenses that are active" do - licenses = company.status(LicenseStatus::ACTIVE) - licenses.count.should == 1 - licenses.should include(active_license) + results = company.filter_licenses_using(status: LicenseStatus::ACTIVE) + results.count.should == 1 + results.should include(active_license) end it "returns all expired licenses" do - licenses = company.status(LicenseStatus::EXPIRED) - licenses.count.should == 1 - licenses.should include(expired_license) + results = company.filter_licenses_using(status: LicenseStatus::EXPIRED) + results.count.should == 2 + results.should include(expired_license) + results.should include(other_expired_license) end - it "returns all confidential licenses" do - licenses = company.status(LicenseStatus::CONFIDENTIAL) - licenses.count.should == 1 - licenses.should include(confidential_license) + it "returns expired licenses in township" do + results = company.filter_licenses_using(status: LicenseStatus::EXPIRED, township: 'edmonton') + results.count.should == 1 + results.should include(other_expired_license) end end end -- cgit v1.2.3 From 83b84f58d7817077c76970d80a936bc82c086006 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:56:22 -0700 Subject: add specs for expired license. --- spec/models/license_status/expired_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 spec/models/license_status/expired_spec.rb diff --git a/spec/models/license_status/expired_spec.rb b/spec/models/license_status/expired_spec.rb new file mode 100644 index 0000000..33092f7 --- /dev/null +++ b/spec/models/license_status/expired_spec.rb @@ -0,0 +1,12 @@ +require "spec_helper" + +describe LicenseStatus::Expired do + let!(:active_license) { License.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } + let!(:expired_license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.ago) } + + it "returns expired results" do + results = LicenseStatus::Expired.new.filter(License) + results.should include(expired_license) + results.should_not include(active_license) + end +end -- cgit v1.2.3 From b7935784e09235ca1bd760b2cfc7335731568d63 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 00:05:22 -0700 Subject: add specs for active status. --- app/models/license_status/active.rb | 2 +- spec/models/license_status/active_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 spec/models/license_status/active_spec.rb diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb index 76fb4c0..aea5652 100644 --- a/app/models/license_status/active.rb +++ b/app/models/license_status/active.rb @@ -1,6 +1,6 @@ class LicenseStatus::Active def filter(licenses) - today = DateTime.now + today = Date.today licenses.where('issued_at < ? AND expired_at > ?', today, today) end diff --git a/spec/models/license_status/active_spec.rb b/spec/models/license_status/active_spec.rb new file mode 100644 index 0000000..21764dc --- /dev/null +++ b/spec/models/license_status/active_spec.rb @@ -0,0 +1,13 @@ +require "spec_helper" + +describe LicenseStatus::Active do + let!(:active_license) { License.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) } + let!(:expired_license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.ago) } + subject { LicenseStatus::Active.new } + + it "returns active results" do + results = subject.filter(License) + results.should include(active_license) + results.should_not include(expired_license) + end +end -- cgit v1.2.3 From 1a937e5e8594a281b5071333476847371aff4049 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 00:10:33 -0700 Subject: review readme. --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2bb9994..79654cf 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,10 @@ A typical well license has the following structure (all fields are required): WellLicense (aggregate root) * belongs_to applicant -* has_one well_type -* has_one location +* belongs_to well_type +* belongs_to location * issued_at * expired_at -* status WellType (flyweight value object) * id @@ -85,7 +84,7 @@ Applicant Location (value object) * latitude * longitude -* township_name +* township LicenseStatus (flyweight, state) * id @@ -96,8 +95,4 @@ LicenseStatus (flyweight, state) * GET /licenses/:guid - details of a single license * GET /company/:guid/licenses - list of all active licences for company * GET /company/:guid/licenses?township=:township - list of active licenses for township, for company. - -Start with a versioned api using urls cuz it's easy peasy. Won't worry -about token auth at this point. - -What should i call this thing? hrmm.... +* GET /company/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. -- cgit v1.2.3 From ccf2255a1c3bb597c1a2c0048cfc7670a0741fc0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 00:15:52 -0700 Subject: remove database.yml --- config/database.yml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 config/database.yml diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index 95db128..0000000 --- a/config/database.yml +++ /dev/null @@ -1,15 +0,0 @@ -development: - adapter: postgresql - encoding: unicode - database: licenses_dev - pool: 5 - username: mo - password: password - host: localhost - -test: - adapter: postgresql - database: licenses_test - username: mo - password: password - host: localhost -- cgit v1.2.3 From 3db1f24191ff0a5c1638b5f89e1f0ed595185cd8 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 00:20:40 -0700 Subject: extract let declarations. --- spec/models/user_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4db73fd..71d9e18 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3,12 +3,12 @@ require "spec_helper" describe User do describe "#apply_for_license" do context "when applying for a license" do + let(:company) { Company.create(name: 'ABC Resources Ltd.') } + let(:user) { User.create(company: company) } + let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } + it "creates a new license" do - company = Company.create(name: 'ABC Resources Ltd.') - user = User.create(company: company) - location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') license = user.apply_for_license(WellType::NFW, location) - license.company.should == user.company license.well_type.should == WellType::NFW license.location.should == location -- cgit v1.2.3 From c76e1f97aec3c59cd5e3563e660bbb8905e64136 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 00:27:11 -0700 Subject: start view specs for each json response. --- app/views/v1/licenses/index.jbuilder | 9 +++++++++ app/views/v1/licenses/show.jbuilder | 2 ++ spec/views/v1/licenses/index.json.jbuilder_spec.rb | 17 +++++++++++++++++ spec/views/v1/licenses/show.json.jbuilder_spec.rb | 17 +++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 app/views/v1/licenses/index.jbuilder create mode 100644 app/views/v1/licenses/show.jbuilder create mode 100644 spec/views/v1/licenses/index.json.jbuilder_spec.rb create mode 100644 spec/views/v1/licenses/show.json.jbuilder_spec.rb diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder new file mode 100644 index 0000000..ff31792 --- /dev/null +++ b/app/views/v1/licenses/index.jbuilder @@ -0,0 +1,9 @@ +json.array! @licenses do |license| + json.issued_at license.issued_at.to_s + json.expired_at license.expired_at.to_s + json.well_type do + json.id 1 + json.pneumonic "NFW" + json.name "New Field Wildcat" + end +end diff --git a/app/views/v1/licenses/show.jbuilder b/app/views/v1/licenses/show.jbuilder new file mode 100644 index 0000000..98f59e8 --- /dev/null +++ b/app/views/v1/licenses/show.jbuilder @@ -0,0 +1,2 @@ +json.issued_at @license.issued_at.to_s +json.expired_at @license.expired_at.to_s diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb new file mode 100644 index 0000000..d2583a3 --- /dev/null +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe 'v1/licenses/index' do + let!(:license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + + before :each do + assign(:licenses, License.all) + render + end + + let(:result) { JSON.parse(rendered) } + + it "includes the license date range" do + result.first["issued_at"].should == license.issued_at.to_s + result.first["expired_at"].should == license.expired_at.to_s + end +end diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb new file mode 100644 index 0000000..e4b337c --- /dev/null +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe 'v1/licenses/show' do + let!(:license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + + before :each do + assign(:license, license) + render + end + + let(:result) { JSON.parse(rendered) } + + it "includes the license date range" do + result["issued_at"].should == license.issued_at.to_s + result["expired_at"].should == license.expired_at.to_s + end +end -- cgit v1.2.3 From 2dd2a09d8c9f939639e72c62ecd4367f7a3ec059 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 00:36:48 -0700 Subject: define json for licenses#index endpoint. --- app/views/v1/licenses/index.jbuilder | 18 +++++++++++++----- spec/views/v1/licenses/index.json.jbuilder_spec.rb | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder index ff31792..5eaf41e 100644 --- a/app/views/v1/licenses/index.jbuilder +++ b/app/views/v1/licenses/index.jbuilder @@ -1,9 +1,17 @@ json.array! @licenses do |license| - json.issued_at license.issued_at.to_s - json.expired_at license.expired_at.to_s json.well_type do - json.id 1 - json.pneumonic "NFW" - json.name "New Field Wildcat" + json.id license.well_type.id + json.acronym license.well_type.acronym + json.name license.well_type.name + end + json.location do + json.township license.location.township + json.latitude license.location.latitude + json.longitude license.location.longitude end + json.company do + json.name license.company.name + end + json.issued_at license.issued_at.to_s + json.expired_at license.expired_at.to_s end diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index d2583a3..38d9955 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -1,10 +1,14 @@ require "spec_helper" describe 'v1/licenses/index' do - let!(:license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + let(:company) { Company.new(name: 'ABC Resources Ltd.') } + let(:user) { User.new(company: company) } + let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } + let(:well_type) { WellType::DEV } + let!(:license) { License.new(company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do - assign(:licenses, License.all) + assign(:licenses, [license]) render end @@ -13,5 +17,12 @@ describe 'v1/licenses/index' do it "includes the license date range" do result.first["issued_at"].should == license.issued_at.to_s result.first["expired_at"].should == license.expired_at.to_s + result.first["well_type"]["id"].should == well_type.id + result.first["well_type"]["acronym"].should == well_type.acronym + result.first["well_type"]["name"].should == well_type.name + result.first["location"]["latitude"].should == location.latitude + result.first["location"]["longitude"].should == location.longitude + result.first["location"]["township"].should == location.township + result.first["company"]["name"].should == license.company.name end end -- cgit v1.2.3 From 1b5f09e0fa8049e68053ad8c20e0c602460a0dc5 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:18:53 -0700 Subject: add id to json response. --- app/views/v1/licenses/index.jbuilder | 1 + spec/views/v1/licenses/index.json.jbuilder_spec.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder index 5eaf41e..b6afb2d 100644 --- a/app/views/v1/licenses/index.jbuilder +++ b/app/views/v1/licenses/index.jbuilder @@ -1,4 +1,5 @@ json.array! @licenses do |license| + json.id license.id json.well_type do json.id license.well_type.id json.acronym license.well_type.acronym diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index 38d9955..412f6fb 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -5,24 +5,26 @@ describe 'v1/licenses/index' do let(:user) { User.new(company: company) } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let(:well_type) { WellType::DEV } - let!(:license) { License.new(company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } + let!(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do assign(:licenses, [license]) render + puts rendered end let(:result) { JSON.parse(rendered) } it "includes the license date range" do - result.first["issued_at"].should == license.issued_at.to_s - result.first["expired_at"].should == license.expired_at.to_s + result.first["id"].should == license.id + result.first["company"]["name"].should == license.company.name result.first["well_type"]["id"].should == well_type.id result.first["well_type"]["acronym"].should == well_type.acronym result.first["well_type"]["name"].should == well_type.name result.first["location"]["latitude"].should == location.latitude result.first["location"]["longitude"].should == location.longitude result.first["location"]["township"].should == location.township - result.first["company"]["name"].should == license.company.name + result.first["issued_at"].should == license.issued_at.to_s + result.first["expired_at"].should == license.expired_at.to_s end end -- cgit v1.2.3 From d135f8b87de18d684b815d758ec2eaef9149ee23 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:19:06 -0700 Subject: put together todo list for morning. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 79654cf..dc8a928 100644 --- a/README.md +++ b/README.md @@ -96,3 +96,22 @@ LicenseStatus (flyweight, state) * GET /company/:guid/licenses - list of all active licences for company * GET /company/:guid/licenses?township=:township - list of active licenses for township, for company. * GET /company/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. + +#### todo +* error handling +* finish json views + * add well statuses and well types to json response. +* update deploy script to seed db. +* update license status to use a hash +* add pagination to company licenses controller +* remove action mailer +* update application controller to inherit directly from metal controllers +* move secret token to env variable +* delete + * application_helper + * application.html.erb + +#### nice to haves +* simplecov +* factory girl +* dotenv -- cgit v1.2.3 From 10d812064f745c4d11eeba91daf3376e608f0c6f Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:27:56 -0700 Subject: update json response for company_licenses#index. --- README.md | 1 + app/views/v1/company_licenses/index.jbuilder | 19 ++++++++++---- .../company_licenses/index.json.jbuilder_spec.rb | 29 +++++++++++++++++++--- spec/views/v1/licenses/index.json.jbuilder_spec.rb | 21 ++++++++++++---- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index dc8a928..2727bdb 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ LicenseStatus (flyweight, state) * error handling * finish json views * add well statuses and well types to json response. +* rename license to well license * update deploy script to seed db. * update license status to use a hash * add pagination to company licenses controller diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder index ff31792..b6afb2d 100644 --- a/app/views/v1/company_licenses/index.jbuilder +++ b/app/views/v1/company_licenses/index.jbuilder @@ -1,9 +1,18 @@ json.array! @licenses do |license| - json.issued_at license.issued_at.to_s - json.expired_at license.expired_at.to_s + json.id license.id json.well_type do - json.id 1 - json.pneumonic "NFW" - json.name "New Field Wildcat" + json.id license.well_type.id + json.acronym license.well_type.acronym + json.name license.well_type.name + end + json.location do + json.township license.location.township + json.latitude license.location.latitude + json.longitude license.location.longitude end + json.company do + json.name license.company.name + end + json.issued_at license.issued_at.to_s + json.expired_at license.expired_at.to_s end diff --git a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb index 52b5fe5..6d85141 100644 --- a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb @@ -1,18 +1,41 @@ require "spec_helper" describe 'v1/company_licenses/index' do - let!(:company) { Company.create(name: 'acme') } - let!(:license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + let(:company) { Company.new(name: 'ABC Resources Ltd.') } + let(:user) { User.new(company: company) } + let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } + let(:well_type) { WellType::DEV } + let(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do - assign(:licenses, company.licenses) + assign(:licenses, [license]) render end let(:result) { JSON.parse(rendered) } + it "includes the license id" do + result.first["id"].should == license.id + end + it "includes the license date range" do result.first["issued_at"].should == license.issued_at.to_s result.first["expired_at"].should == license.expired_at.to_s end + + it "includes the company information" do + result.first["company"]["name"].should == license.company.name + end + + it "includes information on the type of well" do + result.first["well_type"]["id"].should == well_type.id + result.first["well_type"]["acronym"].should == well_type.acronym + result.first["well_type"]["name"].should == well_type.name + end + + it "includes location information" do + result.first["location"]["latitude"].should == location.latitude + result.first["location"]["longitude"].should == location.longitude + result.first["location"]["township"].should == location.township + end end diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index 412f6fb..c3743a5 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -5,26 +5,37 @@ describe 'v1/licenses/index' do let(:user) { User.new(company: company) } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let(:well_type) { WellType::DEV } - let!(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } + let(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do assign(:licenses, [license]) render - puts rendered end let(:result) { JSON.parse(rendered) } - it "includes the license date range" do + it "includes the license id" do result.first["id"].should == license.id + end + + it "includes the license date range" do + result.first["issued_at"].should == license.issued_at.to_s + result.first["expired_at"].should == license.expired_at.to_s + end + + it "includes the company information" do result.first["company"]["name"].should == license.company.name + end + + it "includes information on the type of well" do result.first["well_type"]["id"].should == well_type.id result.first["well_type"]["acronym"].should == well_type.acronym result.first["well_type"]["name"].should == well_type.name + end + + it "includes location information" do result.first["location"]["latitude"].should == location.latitude result.first["location"]["longitude"].should == location.longitude result.first["location"]["township"].should == location.township - result.first["issued_at"].should == license.issued_at.to_s - result.first["expired_at"].should == license.expired_at.to_s end end -- cgit v1.2.3 From 85009727fccd91a27c658993417ca2d3b50c2364 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:31:20 -0700 Subject: add json response for licenses#show. --- app/views/v1/licenses/show.jbuilder | 14 ++++++++++++ spec/views/v1/licenses/show.json.jbuilder_spec.rb | 26 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/views/v1/licenses/show.jbuilder b/app/views/v1/licenses/show.jbuilder index 98f59e8..6ada656 100644 --- a/app/views/v1/licenses/show.jbuilder +++ b/app/views/v1/licenses/show.jbuilder @@ -1,2 +1,16 @@ +json.id @license.id +json.well_type do + json.id @license.well_type.id + json.acronym @license.well_type.acronym + json.name @license.well_type.name +end +json.location do + json.township @license.location.township + json.latitude @license.location.latitude + json.longitude @license.location.longitude +end +json.company do + json.name @license.company.name +end json.issued_at @license.issued_at.to_s json.expired_at @license.expired_at.to_s diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb index e4b337c..dff07fa 100644 --- a/spec/views/v1/licenses/show.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -1,7 +1,11 @@ require "spec_helper" describe 'v1/licenses/show' do - let!(:license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + let(:company) { Company.new(name: 'ABC Resources Ltd.') } + let(:user) { User.new(company: company) } + let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } + let(:well_type) { WellType::DEV } + let(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do assign(:license, license) @@ -14,4 +18,24 @@ describe 'v1/licenses/show' do result["issued_at"].should == license.issued_at.to_s result["expired_at"].should == license.expired_at.to_s end + + it "includes the license id" do + result["id"].should == license.id + end + + it "includes the company information" do + result["company"]["name"].should == license.company.name + end + + it "includes information on the type of well" do + result["well_type"]["id"].should == well_type.id + result["well_type"]["acronym"].should == well_type.acronym + result["well_type"]["name"].should == well_type.name + end + + it "includes location information" do + result["location"]["latitude"].should == location.latitude + result["location"]["longitude"].should == location.longitude + result["location"]["township"].should == location.township + end end -- cgit v1.2.3 From 2e7e24211668fc35f0cc417f3295d0728afedde8 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:37:05 -0700 Subject: extract partial to render the license information. --- app/views/v1/company_licenses/index.jbuilder | 17 +---------------- app/views/v1/licenses/_license.json.jbuilder | 16 ++++++++++++++++ app/views/v1/licenses/index.jbuilder | 17 +---------------- app/views/v1/licenses/show.jbuilder | 17 +---------------- 4 files changed, 19 insertions(+), 48 deletions(-) create mode 100644 app/views/v1/licenses/_license.json.jbuilder diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder index b6afb2d..1cc2069 100644 --- a/app/views/v1/company_licenses/index.jbuilder +++ b/app/views/v1/company_licenses/index.jbuilder @@ -1,18 +1,3 @@ json.array! @licenses do |license| - json.id license.id - json.well_type do - json.id license.well_type.id - json.acronym license.well_type.acronym - json.name license.well_type.name - end - json.location do - json.township license.location.township - json.latitude license.location.latitude - json.longitude license.location.longitude - end - json.company do - json.name license.company.name - end - json.issued_at license.issued_at.to_s - json.expired_at license.expired_at.to_s + json.partial! 'v1/licenses/license', license: license end diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder new file mode 100644 index 0000000..d1e2aa8 --- /dev/null +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -0,0 +1,16 @@ + json.id license.id + json.well_type do + json.id license.well_type.id + json.acronym license.well_type.acronym + json.name license.well_type.name + end + json.location do + json.township license.location.township + json.latitude license.location.latitude + json.longitude license.location.longitude + end + json.company do + json.name license.company.name + end + json.issued_at license.issued_at.to_s + json.expired_at license.expired_at.to_s diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder index b6afb2d..1cc2069 100644 --- a/app/views/v1/licenses/index.jbuilder +++ b/app/views/v1/licenses/index.jbuilder @@ -1,18 +1,3 @@ json.array! @licenses do |license| - json.id license.id - json.well_type do - json.id license.well_type.id - json.acronym license.well_type.acronym - json.name license.well_type.name - end - json.location do - json.township license.location.township - json.latitude license.location.latitude - json.longitude license.location.longitude - end - json.company do - json.name license.company.name - end - json.issued_at license.issued_at.to_s - json.expired_at license.expired_at.to_s + json.partial! 'v1/licenses/license', license: license end diff --git a/app/views/v1/licenses/show.jbuilder b/app/views/v1/licenses/show.jbuilder index 6ada656..7d64d23 100644 --- a/app/views/v1/licenses/show.jbuilder +++ b/app/views/v1/licenses/show.jbuilder @@ -1,16 +1 @@ -json.id @license.id -json.well_type do - json.id @license.well_type.id - json.acronym @license.well_type.acronym - json.name @license.well_type.name -end -json.location do - json.township @license.location.township - json.latitude @license.location.latitude - json.longitude @license.location.longitude -end -json.company do - json.name @license.company.name -end -json.issued_at @license.issued_at.to_s -json.expired_at @license.expired_at.to_s +json.partial! 'v1/licenses/license', license: @license -- cgit v1.2.3 From 455c4f06a54b02dacbc5f93d437d07689dc03fc1 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:38:49 -0700 Subject: extract well_type partial. --- app/views/v1/licenses/_license.json.jbuilder | 6 +----- app/views/v1/licenses/_well_type.json.jbuilder | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 app/views/v1/licenses/_well_type.json.jbuilder diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index d1e2aa8..58b9282 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,9 +1,5 @@ json.id license.id - json.well_type do - json.id license.well_type.id - json.acronym license.well_type.acronym - json.name license.well_type.name - end + json.partial! 'v1/licenses/well_type', well_type: license.well_type json.location do json.township license.location.township json.latitude license.location.latitude diff --git a/app/views/v1/licenses/_well_type.json.jbuilder b/app/views/v1/licenses/_well_type.json.jbuilder new file mode 100644 index 0000000..dd5176e --- /dev/null +++ b/app/views/v1/licenses/_well_type.json.jbuilder @@ -0,0 +1,5 @@ +json.well_type do + json.id well_type.id + json.acronym well_type.acronym + json.name well_type.name +end -- cgit v1.2.3 From 010bd343157ae02c95709359f0137d45e562e629 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:40:29 -0700 Subject: extract partial for location. --- README.md | 1 + app/views/v1/licenses/_license.json.jbuilder | 6 +----- app/views/v1/licenses/_location.json.jbuilder | 5 +++++ 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 app/views/v1/licenses/_location.json.jbuilder diff --git a/README.md b/README.md index 2727bdb..e8076f5 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ LicenseStatus (flyweight, state) * finish json views * add well statuses and well types to json response. * rename license to well license +* add applicant name to users * update deploy script to seed db. * update license status to use a hash * add pagination to company licenses controller diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 58b9282..607ce60 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,10 +1,6 @@ json.id license.id json.partial! 'v1/licenses/well_type', well_type: license.well_type - json.location do - json.township license.location.township - json.latitude license.location.latitude - json.longitude license.location.longitude - end + json.partial! 'v1/licenses/location', location: license.location json.company do json.name license.company.name end diff --git a/app/views/v1/licenses/_location.json.jbuilder b/app/views/v1/licenses/_location.json.jbuilder new file mode 100644 index 0000000..5b43756 --- /dev/null +++ b/app/views/v1/licenses/_location.json.jbuilder @@ -0,0 +1,5 @@ +json.location do + json.township location.township + json.latitude location.latitude + json.longitude location.longitude +end -- cgit v1.2.3 From d385a99f504dc183e92ffe87c18ac27bf0c88872 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:42:16 -0700 Subject: extract partial for company. --- app/views/v1/licenses/_company.json.jbuilder | 3 +++ app/views/v1/licenses/_license.json.jbuilder | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 app/views/v1/licenses/_company.json.jbuilder diff --git a/app/views/v1/licenses/_company.json.jbuilder b/app/views/v1/licenses/_company.json.jbuilder new file mode 100644 index 0000000..223a2b1 --- /dev/null +++ b/app/views/v1/licenses/_company.json.jbuilder @@ -0,0 +1,3 @@ +json.company do + json.name company.name +end diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 607ce60..3ef54ff 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,8 +1,6 @@ - json.id license.id - json.partial! 'v1/licenses/well_type', well_type: license.well_type - json.partial! 'v1/licenses/location', location: license.location - json.company do - json.name license.company.name - end - json.issued_at license.issued_at.to_s - json.expired_at license.expired_at.to_s +json.id license.id +json.partial! 'v1/licenses/well_type', well_type: license.well_type +json.partial! 'v1/licenses/location', location: license.location +json.partial! 'v1/licenses/company', company: license.company +json.issued_at license.issued_at.to_s +json.expired_at license.expired_at.to_s -- cgit v1.2.3 From b675903ccb615c1f1868cd46095fec140a4198ae Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 07:53:37 -0700 Subject: do not disclose company or well type information for confidential licenses. --- .../licenses/_confidential_company.json.jbuilder | 3 + .../licenses/_confidential_well_type.json.jbuilder | 5 ++ app/views/v1/licenses/_license.json.jbuilder | 9 ++- spec/views/v1/licenses/show.json.jbuilder_spec.rb | 76 +++++++++++++++------- 4 files changed, 67 insertions(+), 26 deletions(-) create mode 100644 app/views/v1/licenses/_confidential_company.json.jbuilder create mode 100644 app/views/v1/licenses/_confidential_well_type.json.jbuilder diff --git a/app/views/v1/licenses/_confidential_company.json.jbuilder b/app/views/v1/licenses/_confidential_company.json.jbuilder new file mode 100644 index 0000000..676c5a1 --- /dev/null +++ b/app/views/v1/licenses/_confidential_company.json.jbuilder @@ -0,0 +1,3 @@ +json.company do + json.name "CONFIDENTIAL" +end diff --git a/app/views/v1/licenses/_confidential_well_type.json.jbuilder b/app/views/v1/licenses/_confidential_well_type.json.jbuilder new file mode 100644 index 0000000..43d8f39 --- /dev/null +++ b/app/views/v1/licenses/_confidential_well_type.json.jbuilder @@ -0,0 +1,5 @@ +json.well_type do + json.id "" + json.acronym "" + json.name "CONFIDENTIAL" +end diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 3ef54ff..0035ea4 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,6 +1,11 @@ json.id license.id -json.partial! 'v1/licenses/well_type', well_type: license.well_type json.partial! 'v1/licenses/location', location: license.location -json.partial! 'v1/licenses/company', company: license.company +if license.confidential? + json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type + json.partial! 'v1/licenses/confidential_company' +else + json.partial! 'v1/licenses/well_type', well_type: license.well_type + json.partial! 'v1/licenses/company', company: license.company +end json.issued_at license.issued_at.to_s json.expired_at license.expired_at.to_s diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb index dff07fa..576c1bb 100644 --- a/spec/views/v1/licenses/show.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -5,37 +5,65 @@ describe 'v1/licenses/show' do let(:user) { User.new(company: company) } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let(:well_type) { WellType::DEV } - let(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } - before :each do - assign(:license, license) - render - end + context "for public licenses" do + let(:public_license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } - let(:result) { JSON.parse(rendered) } + before :each do + assign(:license, public_license) + render + end - it "includes the license date range" do - result["issued_at"].should == license.issued_at.to_s - result["expired_at"].should == license.expired_at.to_s - end + let(:result) { JSON.parse(rendered) } - it "includes the license id" do - result["id"].should == license.id - end + it "includes the license date range" do + result["issued_at"].should == public_license.issued_at.to_s + result["expired_at"].should == public_license.expired_at.to_s + end - it "includes the company information" do - result["company"]["name"].should == license.company.name - end + it "includes the license id" do + result["id"].should == public_license.id + end + + it "includes the company information" do + result["company"]["name"].should == public_license.company.name + end + + it "includes information on the type of well" do + result["well_type"]["id"].should == well_type.id + result["well_type"]["acronym"].should == well_type.acronym + result["well_type"]["name"].should == well_type.name + end - it "includes information on the type of well" do - result["well_type"]["id"].should == well_type.id - result["well_type"]["acronym"].should == well_type.acronym - result["well_type"]["name"].should == well_type.name + it "includes location information" do + result["location"]["latitude"].should == location.latitude + result["location"]["longitude"].should == location.longitude + result["location"]["township"].should == location.township + end end - it "includes location information" do - result["location"]["latitude"].should == location.latitude - result["location"]["longitude"].should == location.longitude - result["location"]["township"].should == location.township + context "for confidential licenses" do + let(:confidential_license) { License.new(confidential: true, company: company, applicant: user, location: location, well_type: well_type) } + + before :each do + assign(:license, confidential_license) + render + end + + let(:result) { JSON.parse(rendered) } + + it "should hide the name of the applicant" do + + end + + it "should hide the type of well" do + result['well_type']['id'].should == '' + result['well_type']['acronym'].should == '' + result['well_type']['name'].should == 'CONFIDENTIAL' + end + + it "should hide the company name" do + result["company"]["name"].should == "CONFIDENTIAL" + end end end -- cgit v1.2.3 From 86036fa0e99d77b34edf16349b1e681db660558f Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:00:50 -0700 Subject: add applicant name to json response. --- app/models/user.rb | 4 ++++ app/views/v1/licenses/_company.json.jbuilder | 1 + app/views/v1/licenses/_confidential_company.json.jbuilder | 1 + app/views/v1/licenses/_license.json.jbuilder | 2 +- db/migrate/20140222145409_add_name_to_users.rb | 6 ++++++ db/schema.rb | 4 +++- spec/models/user_spec.rb | 6 ++++++ spec/views/v1/licenses/show.json.jbuilder_spec.rb | 5 +++-- 8 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20140222145409_add_name_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index 056039b..c298241 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,10 @@ class User < ActiveRecord::Base belongs_to :company + def full_name + "#{first_name} #{last_name}" + end + def apply_for_license(well_type, location) company.licenses.create(well_type: well_type, location: location, applicant: self) end diff --git a/app/views/v1/licenses/_company.json.jbuilder b/app/views/v1/licenses/_company.json.jbuilder index 223a2b1..91a79da 100644 --- a/app/views/v1/licenses/_company.json.jbuilder +++ b/app/views/v1/licenses/_company.json.jbuilder @@ -1,3 +1,4 @@ json.company do json.name company.name + json.applicant_name applicant.full_name end diff --git a/app/views/v1/licenses/_confidential_company.json.jbuilder b/app/views/v1/licenses/_confidential_company.json.jbuilder index 676c5a1..312961a 100644 --- a/app/views/v1/licenses/_confidential_company.json.jbuilder +++ b/app/views/v1/licenses/_confidential_company.json.jbuilder @@ -1,3 +1,4 @@ json.company do json.name "CONFIDENTIAL" + json.applicant_name "CONFIDENTIAL" end diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 0035ea4..9fd0ce8 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -5,7 +5,7 @@ if license.confidential? json.partial! 'v1/licenses/confidential_company' else json.partial! 'v1/licenses/well_type', well_type: license.well_type - json.partial! 'v1/licenses/company', company: license.company + json.partial! 'v1/licenses/company', company: license.company, applicant: license.applicant end json.issued_at license.issued_at.to_s json.expired_at license.expired_at.to_s diff --git a/db/migrate/20140222145409_add_name_to_users.rb b/db/migrate/20140222145409_add_name_to_users.rb new file mode 100644 index 0000000..2f30a88 --- /dev/null +++ b/db/migrate/20140222145409_add_name_to_users.rb @@ -0,0 +1,6 @@ +class AddNameToUsers < ActiveRecord::Migration + def change + add_column :users, :first_name, :string + add_column :users, :last_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index d58c3ae..f102db8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222055630) do +ActiveRecord::Schema.define(version: 20140222145409) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -47,6 +47,8 @@ ActiveRecord::Schema.define(version: 20140222055630) do t.uuid "company_id" t.datetime "created_at" t.datetime "updated_at" + t.string "first_name" + t.string "last_name" end create_table "well_types", force: true do |t| diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 71d9e18..1117f00 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -16,4 +16,10 @@ describe User do end end end + + describe "#full_name" do + it "returns the full name" do + User.new(first_name: "mo", last_name: "khan").full_name.should == "mo khan" + end + end end diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb index 576c1bb..db8730f 100644 --- a/spec/views/v1/licenses/show.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" describe 'v1/licenses/show' do let(:company) { Company.new(name: 'ABC Resources Ltd.') } - let(:user) { User.new(company: company) } + let(:user) { User.new(first_name: 'john', last_name: 'dielwart', company: company) } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let(:well_type) { WellType::DEV } @@ -27,6 +27,7 @@ describe 'v1/licenses/show' do it "includes the company information" do result["company"]["name"].should == public_license.company.name + result["company"]["applicant_name"].should == user.full_name end it "includes information on the type of well" do @@ -53,7 +54,7 @@ describe 'v1/licenses/show' do let(:result) { JSON.parse(rendered) } it "should hide the name of the applicant" do - + result["company"]["applicant_name"].should == "CONFIDENTIAL" end it "should hide the type of well" do -- cgit v1.2.3 From 50bd8659e26cebb8c729b25f09eef7e3a25111c5 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:12:03 -0700 Subject: add well types to the json response. --- app/views/v1/licenses/index.jbuilder | 13 ++++++++-- spec/views/v1/licenses/index.json.jbuilder_spec.rb | 29 ++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder index 1cc2069..2f31916 100644 --- a/app/views/v1/licenses/index.jbuilder +++ b/app/views/v1/licenses/index.jbuilder @@ -1,3 +1,12 @@ -json.array! @licenses do |license| - json.partial! 'v1/licenses/license', license: license +json.licenses do + json.array! @licenses do |license| + json.partial! 'v1/licenses/license', license: license + end +end +json.well_types do + json.array! @well_types do |well_type| + json.id well_type.id + json.acronym well_type.acronym + json.name well_type.name + end end diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index c3743a5..f88ecc5 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -9,33 +9,42 @@ describe 'v1/licenses/index' do before :each do assign(:licenses, [license]) + assign(:well_types, WellType::ALL) render end let(:result) { JSON.parse(rendered) } it "includes the license id" do - result.first["id"].should == license.id + result["licenses"].first["id"].should == license.id end it "includes the license date range" do - result.first["issued_at"].should == license.issued_at.to_s - result.first["expired_at"].should == license.expired_at.to_s + result["licenses"].first["issued_at"].should == license.issued_at.to_s + result["licenses"].first["expired_at"].should == license.expired_at.to_s end it "includes the company information" do - result.first["company"]["name"].should == license.company.name + result["licenses"].first["company"]["name"].should == license.company.name end it "includes information on the type of well" do - result.first["well_type"]["id"].should == well_type.id - result.first["well_type"]["acronym"].should == well_type.acronym - result.first["well_type"]["name"].should == well_type.name + result["licenses"].first["well_type"]["id"].should == well_type.id + result["licenses"].first["well_type"]["acronym"].should == well_type.acronym + result["licenses"].first["well_type"]["name"].should == well_type.name end it "includes location information" do - result.first["location"]["latitude"].should == location.latitude - result.first["location"]["longitude"].should == location.longitude - result.first["location"]["township"].should == location.township + result["licenses"].first["location"]["latitude"].should == location.latitude + result["licenses"].first["location"]["longitude"].should == location.longitude + result["licenses"].first["location"]["township"].should == location.township + end + + it "includes all the well types" do + WellType::ALL.each do |well_type| + row = result["well_types"].find { |x| x['id'] == well_type.id } + row['acronym'].should == well_type.acronym + row['name'].should == well_type.name + end end end -- cgit v1.2.3 From ba07bb7f1ea83845cfd8e0fdae5f860087147b5c Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:16:49 -0700 Subject: add license statuses to the json response. --- app/views/v1/licenses/index.jbuilder | 5 +++++ spec/views/v1/licenses/index.json.jbuilder_spec.rb | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder index 2f31916..f8125e5 100644 --- a/app/views/v1/licenses/index.jbuilder +++ b/app/views/v1/licenses/index.jbuilder @@ -10,3 +10,8 @@ json.well_types do json.name well_type.name end end +json.license_statuses do + json.array! @license_statuses do |status| + json.name status.to_s + end +end diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index f88ecc5..297f2af 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -10,6 +10,7 @@ describe 'v1/licenses/index' do before :each do assign(:licenses, [license]) assign(:well_types, WellType::ALL) + assign(:license_statuses, LicenseStatus::ALL) render end @@ -47,4 +48,12 @@ describe 'v1/licenses/index' do row['name'].should == well_type.name end end + + it "includes all the license statuses" do + puts rendered + LicenseStatus::ALL.each do |status| + row = result["license_statuses"].find { |x| x['name'] == status.to_s } + row.should_not be_nil + end + end end -- cgit v1.2.3 From 1de5ac98002e9057bd5a163deb93f630464185fc Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:18:15 -0700 Subject: pretty print the active status name. --- app/models/license_status/active.rb | 6 +++++- spec/models/license_status/active_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb index aea5652..864ee1a 100644 --- a/app/models/license_status/active.rb +++ b/app/models/license_status/active.rb @@ -5,7 +5,11 @@ class LicenseStatus::Active end def matches?(name) - "active" == name + to_s == name + end + + def to_s + 'active' end end diff --git a/spec/models/license_status/active_spec.rb b/spec/models/license_status/active_spec.rb index 21764dc..4d44737 100644 --- a/spec/models/license_status/active_spec.rb +++ b/spec/models/license_status/active_spec.rb @@ -10,4 +10,8 @@ describe LicenseStatus::Active do results.should include(active_license) results.should_not include(expired_license) end + + it "returns it's name" do + subject.to_s.should == 'active' + end end -- cgit v1.2.3 From 224eef2913cba14d052554ff6276680ba62d6430 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:19:33 -0700 Subject: pretty print the expired status. --- app/models/license_status/expired.rb | 6 +++++- spec/models/license_status/expired_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/license_status/expired.rb b/app/models/license_status/expired.rb index 393e34f..adbc3fb 100644 --- a/app/models/license_status/expired.rb +++ b/app/models/license_status/expired.rb @@ -5,6 +5,10 @@ class LicenseStatus::Expired end def matches?(name) - "expired" == name + to_s == name + end + + def to_s + 'expired' end end diff --git a/spec/models/license_status/expired_spec.rb b/spec/models/license_status/expired_spec.rb index 33092f7..ed5ea5d 100644 --- a/spec/models/license_status/expired_spec.rb +++ b/spec/models/license_status/expired_spec.rb @@ -9,4 +9,8 @@ describe LicenseStatus::Expired do results.should include(expired_license) results.should_not include(active_license) end + + it "returns it's name" do + subject.to_s.should == 'expired' + end end -- cgit v1.2.3 From 04de304268a3bacec6a6ada46a0641c0b0e68ddf Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:22:51 -0700 Subject: add missing specs for confidential status. --- app/models/license_status/confidential.rb | 6 +++++- spec/models/license_status/confidential_spec.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 spec/models/license_status/confidential_spec.rb diff --git a/app/models/license_status/confidential.rb b/app/models/license_status/confidential.rb index 81178f6..d108491 100644 --- a/app/models/license_status/confidential.rb +++ b/app/models/license_status/confidential.rb @@ -4,6 +4,10 @@ class LicenseStatus::Confidential end def matches?(name) - "confidential" == name + to_s == name + end + + def to_s + 'confidential' end end diff --git a/spec/models/license_status/confidential_spec.rb b/spec/models/license_status/confidential_spec.rb new file mode 100644 index 0000000..2b13449 --- /dev/null +++ b/spec/models/license_status/confidential_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe LicenseStatus::Confidential do + let!(:public_license) { License.create(confidential: false) } + let!(:confidential_license) { License.create(confidential: true) } + subject { LicenseStatus::Confidential.new } + + it "returns confidential results" do + results = subject.filter(License) + results.should include(confidential_license) + results.should_not include(public_license) + end + + it "returns it's name" do + subject.to_s.should == 'confidential' + end +end -- cgit v1.2.3 From c75462efb418746940ba474281a7518510624e5d Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:26:28 -0700 Subject: extract partials for well types and license types. --- app/views/v1/licenses/index.jbuilder | 14 ++------------ app/views/v1/shared/_license_statuses.json.jbuilder | 5 +++++ app/views/v1/shared/_well_types.json.jbuilder | 7 +++++++ spec/views/v1/licenses/index.json.jbuilder_spec.rb | 1 - 4 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 app/views/v1/shared/_license_statuses.json.jbuilder create mode 100644 app/views/v1/shared/_well_types.json.jbuilder diff --git a/app/views/v1/licenses/index.jbuilder b/app/views/v1/licenses/index.jbuilder index f8125e5..8228f3e 100644 --- a/app/views/v1/licenses/index.jbuilder +++ b/app/views/v1/licenses/index.jbuilder @@ -3,15 +3,5 @@ json.licenses do json.partial! 'v1/licenses/license', license: license end end -json.well_types do - json.array! @well_types do |well_type| - json.id well_type.id - json.acronym well_type.acronym - json.name well_type.name - end -end -json.license_statuses do - json.array! @license_statuses do |status| - json.name status.to_s - end -end +json.partial! 'v1/shared/well_types', well_types: @well_types +json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses diff --git a/app/views/v1/shared/_license_statuses.json.jbuilder b/app/views/v1/shared/_license_statuses.json.jbuilder new file mode 100644 index 0000000..76c2ec6 --- /dev/null +++ b/app/views/v1/shared/_license_statuses.json.jbuilder @@ -0,0 +1,5 @@ +json.license_statuses do + json.array! license_statuses do |status| + json.name status.to_s + end +end diff --git a/app/views/v1/shared/_well_types.json.jbuilder b/app/views/v1/shared/_well_types.json.jbuilder new file mode 100644 index 0000000..e1b588d --- /dev/null +++ b/app/views/v1/shared/_well_types.json.jbuilder @@ -0,0 +1,7 @@ +json.well_types do + json.array! well_types do |well_type| + json.id well_type.id + json.acronym well_type.acronym + json.name well_type.name + end +end diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index 297f2af..6a17700 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -50,7 +50,6 @@ describe 'v1/licenses/index' do end it "includes all the license statuses" do - puts rendered LicenseStatus::ALL.each do |status| row = result["license_statuses"].find { |x| x['name'] == status.to_s } row.should_not be_nil -- cgit v1.2.3 From 32c64df4b8b48f87c6e9a3c86496eed85a1d078c Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:27:34 -0700 Subject: add well types and license statuses to the company licenses json response. --- app/views/v1/company_licenses/index.jbuilder | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder index 1cc2069..db62113 100644 --- a/app/views/v1/company_licenses/index.jbuilder +++ b/app/views/v1/company_licenses/index.jbuilder @@ -1,3 +1,5 @@ json.array! @licenses do |license| json.partial! 'v1/licenses/license', license: license end +json.partial! 'v1/shared/well_types', well_types: @well_types +json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses -- cgit v1.2.3 From 1388b346450b975703b7890eb87505e975713c22 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:30:56 -0700 Subject: add the license status to the json response. --- app/views/v1/licenses/_license.json.jbuilder | 1 + spec/views/v1/licenses/show.json.jbuilder_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 9fd0ce8..33109d8 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,4 +1,5 @@ json.id license.id +json.status license.status json.partial! 'v1/licenses/location', location: license.location if license.confidential? json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb index db8730f..404a514 100644 --- a/spec/views/v1/licenses/show.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -10,6 +10,7 @@ describe 'v1/licenses/show' do let(:public_license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do + public_license.stub(:status).and_return('active') assign(:license, public_license) render end @@ -41,12 +42,17 @@ describe 'v1/licenses/show' do result["location"]["longitude"].should == location.longitude result["location"]["township"].should == location.township end + + it "includes the license status" do + result['status'].should == 'active' + end end context "for confidential licenses" do let(:confidential_license) { License.new(confidential: true, company: company, applicant: user, location: location, well_type: well_type) } before :each do + confidential_license.stub(:status).and_return('confidential') assign(:license, confidential_license) render end @@ -66,5 +72,9 @@ describe 'v1/licenses/show' do it "should hide the company name" do result["company"]["name"].should == "CONFIDENTIAL" end + + it "includes the license status" do + result['status'].should == 'confidential' + end end end -- cgit v1.2.3 From 7947414c935aa6a20a2de068b343df2a0f141384 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:52:13 -0700 Subject: add status to license and fix broken jbuilder spec. --- app/models/license.rb | 4 +++ app/models/license_status.rb | 5 +++ app/models/license_status/active.rb | 5 +++ app/models/license_status/confidential.rb | 4 +++ app/models/license_status/expired.rb | 4 +++ app/views/v1/company_licenses/index.jbuilder | 6 ++-- app/views/v1/licenses/_license.json.jbuilder | 2 +- spec/models/license_spec.rb | 18 +++++++++++ .../company_licenses/index.json.jbuilder_spec.rb | 37 ++++++++++++++++------ spec/views/v1/licenses/show.json.jbuilder_spec.rb | 4 +-- 10 files changed, 74 insertions(+), 15 deletions(-) diff --git a/app/models/license.rb b/app/models/license.rb index 2b4fc3c..12bb387 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -4,6 +4,10 @@ class License < ActiveRecord::Base has_one :location belongs_to :applicant, class_name: 'User', foreign_key: 'user_id' + def status + LicenseStatus.status_for(self) + end + def self.most_recent(page: 1, per_page: 10) offset = (page - 1) * per_page offset = offset >= 0 ? offset : 0 diff --git a/app/models/license_status.rb b/app/models/license_status.rb index 41b54c5..d5da68f 100644 --- a/app/models/license_status.rb +++ b/app/models/license_status.rb @@ -2,10 +2,15 @@ class LicenseStatus ACTIVE=Active.new EXPIRED=Expired.new CONFIDENTIAL=Confidential.new + UNKNOWN=Object.new ALL=[ACTIVE, EXPIRED, CONFIDENTIAL] def self.find_match(status = "") ALL.find { |x| x.matches?("#{status}".downcase) } || ACTIVE end + + def self.status_for(license) + ALL.find { |x| x.best_represents?(license) } || UNKNOWN + end end diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb index 864ee1a..f959efb 100644 --- a/app/models/license_status/active.rb +++ b/app/models/license_status/active.rb @@ -8,6 +8,11 @@ class LicenseStatus::Active to_s == name end + def best_represents?(license) + today = Date.today + license.issued_at < today && license.expired_at > today + end + def to_s 'active' end diff --git a/app/models/license_status/confidential.rb b/app/models/license_status/confidential.rb index d108491..b2354cd 100644 --- a/app/models/license_status/confidential.rb +++ b/app/models/license_status/confidential.rb @@ -7,6 +7,10 @@ class LicenseStatus::Confidential to_s == name end + def best_represents?(license) + license.confidential? + end + def to_s 'confidential' end diff --git a/app/models/license_status/expired.rb b/app/models/license_status/expired.rb index adbc3fb..8e24af9 100644 --- a/app/models/license_status/expired.rb +++ b/app/models/license_status/expired.rb @@ -8,6 +8,10 @@ class LicenseStatus::Expired to_s == name end + def best_represents?(license) + license.expired_at < Date.today + end + def to_s 'expired' end diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder index db62113..8228f3e 100644 --- a/app/views/v1/company_licenses/index.jbuilder +++ b/app/views/v1/company_licenses/index.jbuilder @@ -1,5 +1,7 @@ -json.array! @licenses do |license| - json.partial! 'v1/licenses/license', license: license +json.licenses do + json.array! @licenses do |license| + json.partial! 'v1/licenses/license', license: license + end end json.partial! 'v1/shared/well_types', well_types: @well_types json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 33109d8..c66fb3f 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,5 +1,5 @@ json.id license.id -json.status license.status +json.status license.status.to_s json.partial! 'v1/licenses/location', location: license.location if license.confidential? json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb index 7df556e..1093d17 100644 --- a/spec/models/license_spec.rb +++ b/spec/models/license_spec.rb @@ -67,4 +67,22 @@ describe License do licenses.should include(confidential_license) end end + + describe "#status" do + let!(:active_license) { License.new(issued_at: 1.day.ago, expired_at: 1.day.from_now) } + let!(:expired_license) { License.new(issued_at: 2.days.ago, expired_at: 1.day.ago ) } + let!(:confidential_license) { License.new(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) } + + it "returns an active status" do + active_license.status.should == LicenseStatus::ACTIVE + end + + it "returns an expired status" do + expired_license.status.should == LicenseStatus::EXPIRED + end + + it "returns an confidential status" do + confidential_license.status.should == LicenseStatus::CONFIDENTIAL + end + end end diff --git a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb index 6d85141..90eefb9 100644 --- a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb @@ -9,33 +9,50 @@ describe 'v1/company_licenses/index' do before :each do assign(:licenses, [license]) + assign(:well_types, WellType::ALL) + assign(:license_statuses, LicenseStatus::ALL) render end let(:result) { JSON.parse(rendered) } it "includes the license id" do - result.first["id"].should == license.id + result["licenses"].first["id"].should == license.id end it "includes the license date range" do - result.first["issued_at"].should == license.issued_at.to_s - result.first["expired_at"].should == license.expired_at.to_s + result["licenses"].first["issued_at"].should == license.issued_at.to_s + result["licenses"].first["expired_at"].should == license.expired_at.to_s end it "includes the company information" do - result.first["company"]["name"].should == license.company.name + result["licenses"].first["company"]["name"].should == license.company.name end it "includes information on the type of well" do - result.first["well_type"]["id"].should == well_type.id - result.first["well_type"]["acronym"].should == well_type.acronym - result.first["well_type"]["name"].should == well_type.name + result["licenses"].first["well_type"]["id"].should == well_type.id + result["licenses"].first["well_type"]["acronym"].should == well_type.acronym + result["licenses"].first["well_type"]["name"].should == well_type.name end it "includes location information" do - result.first["location"]["latitude"].should == location.latitude - result.first["location"]["longitude"].should == location.longitude - result.first["location"]["township"].should == location.township + result["licenses"].first["location"]["latitude"].should == location.latitude + result["licenses"].first["location"]["longitude"].should == location.longitude + result["licenses"].first["location"]["township"].should == location.township + end + + it "includes all the well types" do + WellType::ALL.each do |well_type| + row = result["well_types"].find { |x| x['id'] == well_type.id } + row['acronym'].should == well_type.acronym + row['name'].should == well_type.name + end + end + + it "includes all the license statuses" do + LicenseStatus::ALL.each do |status| + row = result["license_statuses"].find { |x| x['name'] == status.to_s } + row.should_not be_nil + end end end diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb index 404a514..f000674 100644 --- a/spec/views/v1/licenses/show.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -10,7 +10,7 @@ describe 'v1/licenses/show' do let(:public_license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do - public_license.stub(:status).and_return('active') + public_license.stub(:status).and_return(LicenseStatus::ACTIVE) assign(:license, public_license) render end @@ -52,7 +52,7 @@ describe 'v1/licenses/show' do let(:confidential_license) { License.new(confidential: true, company: company, applicant: user, location: location, well_type: well_type) } before :each do - confidential_license.stub(:status).and_return('confidential') + confidential_license.stub(:status).and_return(LicenseStatus::CONFIDENTIAL) assign(:license, confidential_license) render end -- cgit v1.2.3 From 69fa85b4e6184eba33dc40901551fb7f0a57fbbb Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 08:57:33 -0700 Subject: update deploy script to seed db and add hconsole script to load heroku console. --- bin/deploy.sh | 1 + bin/hconsole.sh | 2 ++ 2 files changed, 3 insertions(+) create mode 100755 bin/hconsole.sh diff --git a/bin/deploy.sh b/bin/deploy.sh index c7cac2c..06c20da 100755 --- a/bin/deploy.sh +++ b/bin/deploy.sh @@ -3,3 +3,4 @@ set -e git push heroku master heroku run rake db:migrate +heroku run rake db:seed diff --git a/bin/hconsole.sh b/bin/hconsole.sh new file mode 100755 index 0000000..fb6066f --- /dev/null +++ b/bin/hconsole.sh @@ -0,0 +1,2 @@ +#!/bin/bash +heroku run bin/rails console -- cgit v1.2.3 From 42a7b9e904f304de6f1a1b399de2868a3fc045c7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:00:54 -0700 Subject: remove unused files. --- README.md | 9 --------- app/helpers/application_helper.rb | 2 -- app/views/layouts/application.html.erb | 14 -------------- 3 files changed, 25 deletions(-) delete mode 100644 app/helpers/application_helper.rb delete mode 100644 app/views/layouts/application.html.erb diff --git a/README.md b/README.md index e8076f5..4f7d65e 100644 --- a/README.md +++ b/README.md @@ -99,19 +99,10 @@ LicenseStatus (flyweight, state) #### todo * error handling -* finish json views - * add well statuses and well types to json response. * rename license to well license -* add applicant name to users -* update deploy script to seed db. -* update license status to use a hash * add pagination to company licenses controller -* remove action mailer * update application controller to inherit directly from metal controllers * move secret token to env variable -* delete - * application_helper - * application.html.erb #### nice to haves * simplecov diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb deleted file mode 100644 index de6be79..0000000 --- a/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index e6fe263..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - CodeChallengeMo - <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> - <%= javascript_include_tag "application", "data-turbolinks-track" => true %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - -- cgit v1.2.3 From 89b64a44f269bb6dfe68cdff8a168ee2a04ee9d6 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:06:00 -0700 Subject: add global error handler to respond with internal server error. --- app/controllers/application_controller.rb | 8 ++++++++ spec/controllers/application_controller_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 658a065..1b2f9f7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,9 +3,17 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :null_session before_filter :load_additional_payload_data + rescue_from StandardError, with: :return_server_error + def load_additional_payload_data @license_statuses = LicenseStatus::ALL @well_types = WellType::ALL end + + private + + def return_server_error + render nothing: true, status: :internal_server_error + end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index a26c465..7ccca09 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -5,6 +5,10 @@ describe ApplicationController do def index render nothing: true end + + def show + raise "heck" + end end it "includes all well statuses with every response" do @@ -16,4 +20,9 @@ describe ApplicationController do get :index assigns(:well_types).should =~ WellType::ALL end + + it "handles errors gracefully" do + get :show, id: 1 + response.status.should == 500 + end end -- cgit v1.2.3 From bf25475d2434452097abb14ab6f2df2c8a4ea856 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:17:41 -0700 Subject: start to write quick visual acceptance test as a shell script. --- README.md | 6 ++---- bin/acceptance.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100755 bin/acceptance.sh diff --git a/README.md b/README.md index 4f7d65e..c25095b 100644 --- a/README.md +++ b/README.md @@ -98,11 +98,9 @@ LicenseStatus (flyweight, state) * GET /company/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. #### todo -* error handling * rename license to well license -* add pagination to company licenses controller -* update application controller to inherit directly from metal controllers -* move secret token to env variable +* move secret token to env variable. +* cache additional payload data. #### nice to haves * simplecov diff --git a/bin/acceptance.sh b/bin/acceptance.sh new file mode 100755 index 0000000..dc2944b --- /dev/null +++ b/bin/acceptance.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +TARGET_HOST=http://infinite-atoll-2481.herokuapp.com + +clear + +echo connecting to $TARGET_HOST +curl $TARGET_HOST +echo + +echo connecting to $TARGET_HOST/v1/licenses +curl $TARGET_HOST/v1/licenses +echo -- cgit v1.2.3 From fc9bc1a5be3463afc4b33b5c9fa113f0663168ea Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:29:07 -0700 Subject: add script to load database with stub data. --- bin/sample.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bin/sample.rb diff --git a/bin/sample.rb b/bin/sample.rb new file mode 100755 index 0000000..20ca31b --- /dev/null +++ b/bin/sample.rb @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby +require ::File.expand_path('../../config/environment', __FILE__) + +abc_resources = Company.create(name: 'ABC Resources Ltd.') +xyz_resources = Company.create(name: 'XYZ Resources Ltd.') + +jd = User.create(first_name: 'john', last_name: 'dielwart', company: abc_resources) +hal = User.create(first_name: 'hal', last_name: 'kvisle', company: xyz_resources) + +township_1 = Location.create(latitude: 51.06, longitude: -114.09, township: '1') +township_2 = Location.create(latitude: 40.06, longitude: -100.09, township: '2') + +public_license = jd.apply_for_license(WellType::NFW, township_1) +public_license.update_attribute(:issued_at, 1.day.ago) +public_license.update_attribute(:expired_at, 1.year.from_now) + +public_expired_license = jd.apply_for_license(WellType::DPT, township_1) +public_expired_license.update_attribute(:issued_at, 1.year.ago) +public_expired_license.update_attribute(:expired_at, 1.day.ago) + +confidential_license = hal.apply_for_license(WellType::SPT, township_2) +confidential_license.update_attribute(:issued_at, 1.day.ago) +confidential_license.update_attribute(:expired_at, 1.year.from_now) -- cgit v1.2.3 From 4498e6ec9a169d1e39cf5b1f7980aeaa0796f3fe Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:40:57 -0700 Subject: mark license as confidential. --- bin/sample.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/sample.rb b/bin/sample.rb index 20ca31b..e1e92a3 100755 --- a/bin/sample.rb +++ b/bin/sample.rb @@ -19,5 +19,6 @@ public_expired_license.update_attribute(:issued_at, 1.year.ago) public_expired_license.update_attribute(:expired_at, 1.day.ago) confidential_license = hal.apply_for_license(WellType::SPT, township_2) +confidential_license.update_attribute(:confidential, true) confidential_license.update_attribute(:issued_at, 1.day.ago) confidential_license.update_attribute(:expired_at, 1.year.from_now) -- cgit v1.2.3 From 9f5b9e7a081742dfced42eabbd56a2d4267c21f0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 09:59:45 -0700 Subject: update acceptance script. --- bin/acceptance.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/bin/acceptance.sh b/bin/acceptance.sh index dc2944b..709ed6c 100755 --- a/bin/acceptance.sh +++ b/bin/acceptance.sh @@ -1,14 +1,59 @@ #!/bin/bash set -e +#company: +#["3a573311-af7a-4a22-8ac6-d62e0b23b804", "05956a2f-6251-4705-9bba-48ac8b36ac86"] + +#license: +#["3806087a-ce07-47be-b613-85ee586fe5d3", "e35d2649-9bd0-4cea-9159-0daaad3f1115", "7a4bebeb-c067-44a1-9f9c-2c1ee513b526"] + TARGET_HOST=http://infinite-atoll-2481.herokuapp.com +COMPANY_ABC=3a573311-af7a-4a22-8ac6-d62e0b23b804 +COMPANY_XYZ=05956a2f-6251-4705-9bba-48ac8b36ac86 + +PUBLIC_ACTIVE_LICENSE=3806087a-ce07-47be-b613-85ee586fe5d3 +PUBLIC_EXPIRED_LICENSE=e35d2649-9bd0-4cea-9159-0daaad3f1115 +CONFIDENTIAL_ACTIVE_LICENSE=7a4bebeb-c067-44a1-9f9c-2c1ee513b526 clear -echo connecting to $TARGET_HOST +# GET /licenses - list of all well licenses +echo $TARGET_HOST curl $TARGET_HOST echo +echo -echo connecting to $TARGET_HOST/v1/licenses +echo $TARGET_HOST/v1/licenses curl $TARGET_HOST/v1/licenses echo +echo + +# GET /licenses/:guid - details of a single license +echo $TARGET_HOST/v1/licenses/$PUBLIC_ACTIVE_LICENSE +curl $TARGET_HOST/v1/licenses/7a4bebeb-c067-44a1-9f9c-2c1ee513b526 +echo +echo + +echo $TARGET_HOST/v1/licenses/$CONFIDENTIAL_ACTIVE_LICENSE +curl $TARGET_HOST/v1/licenses/7a4bebeb-c067-44a1-9f9c-2c1ee513b526 +echo +echo + +#* GET /company/:guid/licenses - list of all active licences for company +echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses +curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses +echo +echo + +#* GET /company/:guid/licenses?township=:township - list of active licenses for township, for company. +echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?township=1 +curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?township=1 +echo +echo + +#* GET /company/:guid/licenses?township=:township&status=expired - list of active licenses for township, for company. +echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?status=expired +curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?status=expired +echo +echo + -- cgit v1.2.3 From b73503c320ac6fd7cdf93974859ae501862ce4c8 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 10:23:55 -0700 Subject: add more examples to acceptance script. --- bin/acceptance.sh | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/bin/acceptance.sh b/bin/acceptance.sh index 709ed6c..12b1406 100755 --- a/bin/acceptance.sh +++ b/bin/acceptance.sh @@ -1,12 +1,6 @@ #!/bin/bash set -e -#company: -#["3a573311-af7a-4a22-8ac6-d62e0b23b804", "05956a2f-6251-4705-9bba-48ac8b36ac86"] - -#license: -#["3806087a-ce07-47be-b613-85ee586fe5d3", "e35d2649-9bd0-4cea-9159-0daaad3f1115", "7a4bebeb-c067-44a1-9f9c-2c1ee513b526"] - TARGET_HOST=http://infinite-atoll-2481.herokuapp.com COMPANY_ABC=3a573311-af7a-4a22-8ac6-d62e0b23b804 COMPANY_XYZ=05956a2f-6251-4705-9bba-48ac8b36ac86 @@ -39,21 +33,31 @@ curl $TARGET_HOST/v1/licenses/7a4bebeb-c067-44a1-9f9c-2c1ee513b526 echo echo -#* GET /company/:guid/licenses - list of all active licences for company +#* GET /companies/:guid/licenses - list of all active licences for company echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses echo echo -#* GET /company/:guid/licenses?township=:township - list of active licenses for township, for company. -echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?township=1 -curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?township=1 +#* GET /companies/:guid/licenses?township=:township - list of active licenses for township, for company. +echo $TARGET_HOST/v1/companies/$COMPANY_XYZ/licenses?township=2 +curl $TARGET_HOST/v1/companies/$COMPANY_XYZ/licenses?township=2 echo echo -#* GET /company/:guid/licenses?township=:township&status=expired - list of active licenses for township, for company. -echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?status=expired -curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?status=expired +#* GET /companies/:guid/licenses?township=:township&status=expired - list of active licenses for township, for company. +echo $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?status=expired&township=1 +curl $TARGET_HOST/v1/companies/$COMPANY_ABC/licenses?status=expired&township=1 echo echo +#* GET /companies/:guid/licenses?status=confidential - list of confidential licenses for company. +echo $TARGET_HOST/v1/companies/$COMPANY_XYZ/licenses?status=confidential +curl $TARGET_HOST/v1/companies/$COMPANY_XYZ/licenses?status=confidential +echo +echo + +sleep 1 +echo +echo +echo "goodbye" -- cgit v1.2.3 From 64d63822a09d674d1257759b593a562711305d75 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 10:26:56 -0700 Subject: replace hard coded id. --- bin/acceptance.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/acceptance.sh b/bin/acceptance.sh index 12b1406..25c23bb 100755 --- a/bin/acceptance.sh +++ b/bin/acceptance.sh @@ -24,12 +24,12 @@ echo # GET /licenses/:guid - details of a single license echo $TARGET_HOST/v1/licenses/$PUBLIC_ACTIVE_LICENSE -curl $TARGET_HOST/v1/licenses/7a4bebeb-c067-44a1-9f9c-2c1ee513b526 +curl $TARGET_HOST/v1/licenses/$PUBLIC_ACTIVE_LICENSE echo echo echo $TARGET_HOST/v1/licenses/$CONFIDENTIAL_ACTIVE_LICENSE -curl $TARGET_HOST/v1/licenses/7a4bebeb-c067-44a1-9f9c-2c1ee513b526 +curl $TARGET_HOST/v1/licenses/$CONFIDENTIAL_ACTIVE_LICENSE echo echo -- cgit v1.2.3 From ef7eeb8ed18092bde97ebc30d249d32e56d5645f Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 11:12:06 -0700 Subject: found a weird bug with jbuilder and trying to render the location json node. --- app/controllers/application_controller.rb | 1 - app/controllers/v1/licenses_controller.rb | 2 -- app/models/location.rb | 2 +- app/views/v1/company_licenses/index.jbuilder | 7 ------- app/views/v1/company_licenses/index.json.jbuilder | 7 +++++++ app/views/v1/licenses/_license.json.jbuilder | 2 +- spec/controllers/v1/licenses_controller_spec.rb | 19 ++++--------------- 7 files changed, 13 insertions(+), 27 deletions(-) delete mode 100644 app/views/v1/company_licenses/index.jbuilder create mode 100644 app/views/v1/company_licenses/index.json.jbuilder diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1b2f9f7..424262c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base before_filter :load_additional_payload_data rescue_from StandardError, with: :return_server_error - def load_additional_payload_data @license_statuses = LicenseStatus::ALL @well_types = WellType::ALL diff --git a/app/controllers/v1/licenses_controller.rb b/app/controllers/v1/licenses_controller.rb index c62c78b..8966100 100644 --- a/app/controllers/v1/licenses_controller.rb +++ b/app/controllers/v1/licenses_controller.rb @@ -5,12 +5,10 @@ class V1::LicensesController < ApplicationController def index @licenses = License.most_recent(page: @page, per_page: @per_page) - render json: @licenses end def show @license = License.find(params[:id]) - render json: @license end private diff --git a/app/models/location.rb b/app/models/location.rb index bf7b7ef..b74eabc 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,3 +1,3 @@ class Location < ActiveRecord::Base - belongs_to :license + belongs_to :license, autosave: true end diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder deleted file mode 100644 index 8228f3e..0000000 --- a/app/views/v1/company_licenses/index.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.licenses do - json.array! @licenses do |license| - json.partial! 'v1/licenses/license', license: license - end -end -json.partial! 'v1/shared/well_types', well_types: @well_types -json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses diff --git a/app/views/v1/company_licenses/index.json.jbuilder b/app/views/v1/company_licenses/index.json.jbuilder new file mode 100644 index 0000000..8228f3e --- /dev/null +++ b/app/views/v1/company_licenses/index.json.jbuilder @@ -0,0 +1,7 @@ +json.licenses do + json.array! @licenses do |license| + json.partial! 'v1/licenses/license', license: license + end +end +json.partial! 'v1/shared/well_types', well_types: @well_types +json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index c66fb3f..b62f91b 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -1,6 +1,6 @@ json.id license.id json.status license.status.to_s -json.partial! 'v1/licenses/location', location: license.location +#json.partial! 'v1/licenses/location', location: license.location if license.confidential? json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type json.partial! 'v1/licenses/confidential_company' diff --git a/spec/controllers/v1/licenses_controller_spec.rb b/spec/controllers/v1/licenses_controller_spec.rb index e8538d0..ca51f95 100644 --- a/spec/controllers/v1/licenses_controller_spec.rb +++ b/spec/controllers/v1/licenses_controller_spec.rb @@ -7,7 +7,7 @@ describe V1::LicensesController do it "returns the first page of licenses" do License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) - xhr :get, :index + get :index response.should be_success assigns(:licenses).should == licenses @@ -16,7 +16,7 @@ describe V1::LicensesController do it "returns the second page of licenses" do License.stub(:most_recent).with(page: 2, per_page: 10).and_return(licenses) - xhr :get, :index, page: 2 + get :index, page: 2 response.should be_success assigns(:licenses).should == licenses @@ -25,17 +25,10 @@ describe V1::LicensesController do it "returns the specified number of results" do License.stub(:most_recent).with(page: 1, per_page: 100).and_return(licenses) - xhr :get, :index, per_page: 100 + get :index, per_page: 100 response.should be_success assigns(:licenses).should == licenses end - - it "returns a json response" do - License.stub(:most_recent).with(page: 1, per_page: 10).and_return(licenses) - - xhr :get, :index - -> { JSON.parse(response.body) }.should_not raise_error - end end describe :show do @@ -43,15 +36,11 @@ describe V1::LicensesController do before :each do License.stub(:find).with(license.id).and_return(license) - xhr :get, :show, id: license.id + get :show, id: license.id end it "returns the correct license" do assigns(:license).should == license end - - it "returns a json response" do - expect(-> { JSON.parse(response.body) }).not_to raise_error - end end end -- cgit v1.2.3 From ed601666363d62ca5a334c3c2414a1215118c019 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 11:19:57 -0700 Subject: remove explicit render :json. --- app/controllers/v1/company_licenses_controller.rb | 1 - app/views/v1/company_licenses/index.jbuilder | 7 +++++++ app/views/v1/company_licenses/index.json.jbuilder | 7 ------- spec/controllers/v1/company_licenses_controller_spec.rb | 11 +++-------- 4 files changed, 10 insertions(+), 16 deletions(-) create mode 100644 app/views/v1/company_licenses/index.jbuilder delete mode 100644 app/views/v1/company_licenses/index.json.jbuilder diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 3b4850f..6f2f666 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -3,7 +3,6 @@ class V1::CompanyLicensesController < ApplicationController def index @active_licenses = @company.filter_licenses_using(search_filters) - render json: @active_licenses end private diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder new file mode 100644 index 0000000..8228f3e --- /dev/null +++ b/app/views/v1/company_licenses/index.jbuilder @@ -0,0 +1,7 @@ +json.licenses do + json.array! @licenses do |license| + json.partial! 'v1/licenses/license', license: license + end +end +json.partial! 'v1/shared/well_types', well_types: @well_types +json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses diff --git a/app/views/v1/company_licenses/index.json.jbuilder b/app/views/v1/company_licenses/index.json.jbuilder deleted file mode 100644 index 8228f3e..0000000 --- a/app/views/v1/company_licenses/index.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.licenses do - json.array! @licenses do |license| - json.partial! 'v1/licenses/license', license: license - end -end -json.partial! 'v1/shared/well_types', well_types: @well_types -json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index e811179..c6f34c9 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -14,18 +14,13 @@ describe V1::CompanyLicensesController do it "returns the active licenses" do company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: nil}).and_return(active_licenses) - xhr :get, :index, company_id: company_id + get :index, company_id: company_id assigns(:active_licenses).should == active_licenses end - it "returns a json response" do - xhr :get, :index, company_id: company_id - expect(-> { JSON.parse(response.body) }).not_to raise_error - end - it "returns the active licenses for a given township" do company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: "123"}).and_return(active_licenses_in_township) - xhr :get, :index, company_id: company_id, township: "123" + get :index, company_id: company_id, township: "123" assigns(:active_licenses).should == active_licenses_in_township end end @@ -37,7 +32,7 @@ describe V1::CompanyLicensesController do let!(:license) { company.licenses.create(well_type: WellType::DEV, location: location, issued_at: 2.days.ago, expired_at: 1.day.ago) } it "finds expired licenses from a specific township" do - xhr :get, :index, company_id: company.id, status: "expired", township: "1" + get :index, company_id: company.id, status: "expired", township: "1" assigns(:active_licenses).should include(license) end end -- cgit v1.2.3 From 0ab1fca101cdad532904d3df1fdf225625209ac0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 11:31:55 -0700 Subject: rename active_licenses to licenses to match jbuilder template. --- app/controllers/v1/company_licenses_controller.rb | 2 +- spec/controllers/v1/company_licenses_controller_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb index 6f2f666..e3701d2 100644 --- a/app/controllers/v1/company_licenses_controller.rb +++ b/app/controllers/v1/company_licenses_controller.rb @@ -2,7 +2,7 @@ class V1::CompanyLicensesController < ApplicationController before_filter :load_company def index - @active_licenses = @company.filter_licenses_using(search_filters) + @licenses = @company.filter_licenses_using(search_filters) end private diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb index c6f34c9..0ba61eb 100644 --- a/spec/controllers/v1/company_licenses_controller_spec.rb +++ b/spec/controllers/v1/company_licenses_controller_spec.rb @@ -15,13 +15,13 @@ describe V1::CompanyLicensesController do it "returns the active licenses" do company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: nil}).and_return(active_licenses) get :index, company_id: company_id - assigns(:active_licenses).should == active_licenses + assigns(:licenses).should == active_licenses end it "returns the active licenses for a given township" do company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: "123"}).and_return(active_licenses_in_township) get :index, company_id: company_id, township: "123" - assigns(:active_licenses).should == active_licenses_in_township + assigns(:licenses).should == active_licenses_in_township end end @@ -33,7 +33,7 @@ describe V1::CompanyLicensesController do it "finds expired licenses from a specific township" do get :index, company_id: company.id, status: "expired", township: "1" - assigns(:active_licenses).should include(license) + assigns(:licenses).should include(license) end end end -- cgit v1.2.3 From 4e7bab146a58bd3a985db87de58bf6115ba084e8 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 11:41:13 -0700 Subject: remove .json extension from jbuilder templates. --- app/views/v1/licenses/_company.jbuilder | 4 ++++ app/views/v1/licenses/_company.json.jbuilder | 4 ---- app/views/v1/licenses/_confidential_company.jbuilder | 4 ++++ app/views/v1/licenses/_confidential_company.json.jbuilder | 4 ---- app/views/v1/licenses/_confidential_well_type.jbuilder | 5 +++++ app/views/v1/licenses/_confidential_well_type.json.jbuilder | 5 ----- app/views/v1/licenses/_license.jbuilder | 12 ++++++++++++ app/views/v1/licenses/_license.json.jbuilder | 12 ------------ app/views/v1/licenses/_location.jbuilder | 5 +++++ app/views/v1/licenses/_location.json.jbuilder | 5 ----- app/views/v1/licenses/_well_type.jbuilder | 5 +++++ app/views/v1/licenses/_well_type.json.jbuilder | 5 ----- app/views/v1/shared/_license_statuses.jbuilder | 5 +++++ app/views/v1/shared/_license_statuses.json.jbuilder | 5 ----- app/views/v1/shared/_well_types.jbuilder | 7 +++++++ app/views/v1/shared/_well_types.json.jbuilder | 7 ------- 16 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 app/views/v1/licenses/_company.jbuilder delete mode 100644 app/views/v1/licenses/_company.json.jbuilder create mode 100644 app/views/v1/licenses/_confidential_company.jbuilder delete mode 100644 app/views/v1/licenses/_confidential_company.json.jbuilder create mode 100644 app/views/v1/licenses/_confidential_well_type.jbuilder delete mode 100644 app/views/v1/licenses/_confidential_well_type.json.jbuilder create mode 100644 app/views/v1/licenses/_license.jbuilder delete mode 100644 app/views/v1/licenses/_license.json.jbuilder create mode 100644 app/views/v1/licenses/_location.jbuilder delete mode 100644 app/views/v1/licenses/_location.json.jbuilder create mode 100644 app/views/v1/licenses/_well_type.jbuilder delete mode 100644 app/views/v1/licenses/_well_type.json.jbuilder create mode 100644 app/views/v1/shared/_license_statuses.jbuilder delete mode 100644 app/views/v1/shared/_license_statuses.json.jbuilder create mode 100644 app/views/v1/shared/_well_types.jbuilder delete mode 100644 app/views/v1/shared/_well_types.json.jbuilder diff --git a/app/views/v1/licenses/_company.jbuilder b/app/views/v1/licenses/_company.jbuilder new file mode 100644 index 0000000..91a79da --- /dev/null +++ b/app/views/v1/licenses/_company.jbuilder @@ -0,0 +1,4 @@ +json.company do + json.name company.name + json.applicant_name applicant.full_name +end diff --git a/app/views/v1/licenses/_company.json.jbuilder b/app/views/v1/licenses/_company.json.jbuilder deleted file mode 100644 index 91a79da..0000000 --- a/app/views/v1/licenses/_company.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.company do - json.name company.name - json.applicant_name applicant.full_name -end diff --git a/app/views/v1/licenses/_confidential_company.jbuilder b/app/views/v1/licenses/_confidential_company.jbuilder new file mode 100644 index 0000000..312961a --- /dev/null +++ b/app/views/v1/licenses/_confidential_company.jbuilder @@ -0,0 +1,4 @@ +json.company do + json.name "CONFIDENTIAL" + json.applicant_name "CONFIDENTIAL" +end diff --git a/app/views/v1/licenses/_confidential_company.json.jbuilder b/app/views/v1/licenses/_confidential_company.json.jbuilder deleted file mode 100644 index 312961a..0000000 --- a/app/views/v1/licenses/_confidential_company.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.company do - json.name "CONFIDENTIAL" - json.applicant_name "CONFIDENTIAL" -end diff --git a/app/views/v1/licenses/_confidential_well_type.jbuilder b/app/views/v1/licenses/_confidential_well_type.jbuilder new file mode 100644 index 0000000..43d8f39 --- /dev/null +++ b/app/views/v1/licenses/_confidential_well_type.jbuilder @@ -0,0 +1,5 @@ +json.well_type do + json.id "" + json.acronym "" + json.name "CONFIDENTIAL" +end diff --git a/app/views/v1/licenses/_confidential_well_type.json.jbuilder b/app/views/v1/licenses/_confidential_well_type.json.jbuilder deleted file mode 100644 index 43d8f39..0000000 --- a/app/views/v1/licenses/_confidential_well_type.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.well_type do - json.id "" - json.acronym "" - json.name "CONFIDENTIAL" -end diff --git a/app/views/v1/licenses/_license.jbuilder b/app/views/v1/licenses/_license.jbuilder new file mode 100644 index 0000000..b62f91b --- /dev/null +++ b/app/views/v1/licenses/_license.jbuilder @@ -0,0 +1,12 @@ +json.id license.id +json.status license.status.to_s +#json.partial! 'v1/licenses/location', location: license.location +if license.confidential? + json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type + json.partial! 'v1/licenses/confidential_company' +else + json.partial! 'v1/licenses/well_type', well_type: license.well_type + json.partial! 'v1/licenses/company', company: license.company, applicant: license.applicant +end +json.issued_at license.issued_at.to_s +json.expired_at license.expired_at.to_s diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder deleted file mode 100644 index b62f91b..0000000 --- a/app/views/v1/licenses/_license.json.jbuilder +++ /dev/null @@ -1,12 +0,0 @@ -json.id license.id -json.status license.status.to_s -#json.partial! 'v1/licenses/location', location: license.location -if license.confidential? - json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type - json.partial! 'v1/licenses/confidential_company' -else - json.partial! 'v1/licenses/well_type', well_type: license.well_type - json.partial! 'v1/licenses/company', company: license.company, applicant: license.applicant -end -json.issued_at license.issued_at.to_s -json.expired_at license.expired_at.to_s diff --git a/app/views/v1/licenses/_location.jbuilder b/app/views/v1/licenses/_location.jbuilder new file mode 100644 index 0000000..5b43756 --- /dev/null +++ b/app/views/v1/licenses/_location.jbuilder @@ -0,0 +1,5 @@ +json.location do + json.township location.township + json.latitude location.latitude + json.longitude location.longitude +end diff --git a/app/views/v1/licenses/_location.json.jbuilder b/app/views/v1/licenses/_location.json.jbuilder deleted file mode 100644 index 5b43756..0000000 --- a/app/views/v1/licenses/_location.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.location do - json.township location.township - json.latitude location.latitude - json.longitude location.longitude -end diff --git a/app/views/v1/licenses/_well_type.jbuilder b/app/views/v1/licenses/_well_type.jbuilder new file mode 100644 index 0000000..dd5176e --- /dev/null +++ b/app/views/v1/licenses/_well_type.jbuilder @@ -0,0 +1,5 @@ +json.well_type do + json.id well_type.id + json.acronym well_type.acronym + json.name well_type.name +end diff --git a/app/views/v1/licenses/_well_type.json.jbuilder b/app/views/v1/licenses/_well_type.json.jbuilder deleted file mode 100644 index dd5176e..0000000 --- a/app/views/v1/licenses/_well_type.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.well_type do - json.id well_type.id - json.acronym well_type.acronym - json.name well_type.name -end diff --git a/app/views/v1/shared/_license_statuses.jbuilder b/app/views/v1/shared/_license_statuses.jbuilder new file mode 100644 index 0000000..76c2ec6 --- /dev/null +++ b/app/views/v1/shared/_license_statuses.jbuilder @@ -0,0 +1,5 @@ +json.license_statuses do + json.array! license_statuses do |status| + json.name status.to_s + end +end diff --git a/app/views/v1/shared/_license_statuses.json.jbuilder b/app/views/v1/shared/_license_statuses.json.jbuilder deleted file mode 100644 index 76c2ec6..0000000 --- a/app/views/v1/shared/_license_statuses.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.license_statuses do - json.array! license_statuses do |status| - json.name status.to_s - end -end diff --git a/app/views/v1/shared/_well_types.jbuilder b/app/views/v1/shared/_well_types.jbuilder new file mode 100644 index 0000000..e1b588d --- /dev/null +++ b/app/views/v1/shared/_well_types.jbuilder @@ -0,0 +1,7 @@ +json.well_types do + json.array! well_types do |well_type| + json.id well_type.id + json.acronym well_type.acronym + json.name well_type.name + end +end diff --git a/app/views/v1/shared/_well_types.json.jbuilder b/app/views/v1/shared/_well_types.json.jbuilder deleted file mode 100644 index e1b588d..0000000 --- a/app/views/v1/shared/_well_types.json.jbuilder +++ /dev/null @@ -1,7 +0,0 @@ -json.well_types do - json.array! well_types do |well_type| - json.id well_type.id - json.acronym well_type.acronym - json.name well_type.name - end -end -- cgit v1.2.3 From c7790748349449d9e6eb2c2a43c93bd2faf1a70d Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 12:14:00 -0700 Subject: pass location json to partial. active records lazy instantiation of has_one relationship keeps returning nil. --- app/views/v1/licenses/_license.jbuilder | 2 +- app/views/v1/licenses/_location.jbuilder | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/v1/licenses/_license.jbuilder b/app/views/v1/licenses/_license.jbuilder index b62f91b..9d04606 100644 --- a/app/views/v1/licenses/_license.jbuilder +++ b/app/views/v1/licenses/_license.jbuilder @@ -1,6 +1,6 @@ json.id license.id json.status license.status.to_s -#json.partial! 'v1/licenses/location', location: license.location +json.partial! 'v1/licenses/location', location: license.to_json if license.confidential? json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type json.partial! 'v1/licenses/confidential_company' diff --git a/app/views/v1/licenses/_location.jbuilder b/app/views/v1/licenses/_location.jbuilder index 5b43756..b9c0625 100644 --- a/app/views/v1/licenses/_location.jbuilder +++ b/app/views/v1/licenses/_location.jbuilder @@ -1,5 +1,5 @@ json.location do - json.township location.township - json.latitude location.latitude - json.longitude location.longitude + json.township location["township"] + json.latitude location["latitude"] + json.longitude location["longitude"] end -- cgit v1.2.3 From 71a2f279073d08e090bcee036cf0bbf54dde7e60 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 12:22:40 -0700 Subject: add solution notes to readme. --- README.md | 54 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c25095b..7a74feb 100644 --- a/README.md +++ b/README.md @@ -57,52 +57,40 @@ A typical well license has the following structure (all fields are required): 3. This private Github repo has been created just for you. Please push your code to it for review. -## Design (Rough) +### Solution -### Assumptions +This solution is hosted on heroku at: [http://infinite-atoll-2481.herokuapp.com](http://infinite-atoll-2481.herokuapp.com) -* Name of applicant is the name of the employee at the company that submitted the application. -* Date of license is the date the license was issued. -* Assume perf isn't the focus, so no need to over-engineer with a denorm read model. - -### Model +#### Endpoints -WellLicense (aggregate root) -* belongs_to applicant -* belongs_to well_type -* belongs_to location -* issued_at -* expired_at +There are 3 different endpoints that serve these requirements. An +example of how to connect to the endpoints can be found in bin/acceptance.sh. -WellType (flyweight value object) -* id -* name - -Applicant -* company +* GET /licenses - list of all well licenses +* GET /licenses/:guid - details of a single license +* GET /companies/:guid/licenses - list of all active licences for company +* GET /companies/:guid/licenses?township=:township - list of active licenses for township, for company. +* GET /companies/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. -Location (value object) -* latitude -* longitude -* township +#### Design (Rough) -LicenseStatus (flyweight, state) -* id +##### Assumptions -### Endpoints +* Name of applicant is the name of the employee at the company that submitted the application. +* Date of license is the date the license was issued. +* Assume perf isn't the focus, so no need to over-engineer with a denorm read model. -* GET /licenses - list of all well licenses -* GET /licenses/:guid - details of a single license -* GET /company/:guid/licenses - list of all active licences for company -* GET /company/:guid/licenses?township=:township - list of active licenses for township, for company. -* GET /company/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. +##### todo -#### todo * rename license to well license * move secret token to env variable. * cache additional payload data. +* resolve n+1 issues +* figure out why location doesn't lazy load in jbuilder template. + +##### nice to haves -#### nice to haves * simplecov * factory girl * dotenv +* bullet -- cgit v1.2.3 From b49f5f2edc5593f9489edfdd5d20a488cf3325ea Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 12:25:37 -0700 Subject: move solution notes to a separate file. --- README.md | 40 +--------------------------------------- SOLUTION.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 39 deletions(-) create mode 100644 SOLUTION.md diff --git a/README.md b/README.md index 7a74feb..c6ec8bb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -### Problem Description +### Problem Description [SOLUTION](SOLUTION.md) #### Background @@ -56,41 +56,3 @@ A typical well license has the following structure (all fields are required): 2. Your submission can be developed using any technology/language you like. 3. This private Github repo has been created just for you. Please push your code to it for review. - -### Solution - -This solution is hosted on heroku at: [http://infinite-atoll-2481.herokuapp.com](http://infinite-atoll-2481.herokuapp.com) - -#### Endpoints - -There are 3 different endpoints that serve these requirements. An -example of how to connect to the endpoints can be found in bin/acceptance.sh. - -* GET /licenses - list of all well licenses -* GET /licenses/:guid - details of a single license -* GET /companies/:guid/licenses - list of all active licences for company -* GET /companies/:guid/licenses?township=:township - list of active licenses for township, for company. -* GET /companies/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. - -#### Design (Rough) - -##### Assumptions - -* Name of applicant is the name of the employee at the company that submitted the application. -* Date of license is the date the license was issued. -* Assume perf isn't the focus, so no need to over-engineer with a denorm read model. - -##### todo - -* rename license to well license -* move secret token to env variable. -* cache additional payload data. -* resolve n+1 issues -* figure out why location doesn't lazy load in jbuilder template. - -##### nice to haves - -* simplecov -* factory girl -* dotenv -* bullet diff --git a/SOLUTION.md b/SOLUTION.md new file mode 100644 index 0000000..0488b00 --- /dev/null +++ b/SOLUTION.md @@ -0,0 +1,35 @@ +### Solution + +This solution is hosted on heroku at: [http://infinite-atoll-2481.herokuapp.com](http://infinite-atoll-2481.herokuapp.com) + +#### Endpoints + +There are 3 different endpoints that serve these requirements. An +example of how to connect to the endpoints can be found in [bin/acceptance.sh](bin/acceptance.sh) + +* GET /licenses - list of all well licenses +* GET /licenses/:guid - details of a single license +* GET /companies/:guid/licenses - list of all active licences for company +* GET /companies/:guid/licenses?township=:township - list of active licenses for township, for company. +* GET /companies/:guid/licenses?status=expired&township=:township - list of expired licenses for township, for company. + +##### Assumptions + +* Name of applicant is the name of the employee at the company that submitted the application. +* Date of license is the date the license was issued. +* Assume perf isn't the focus, so no need to over-engineer with a denorm read model. + +##### TODO + +* move secret token to env variable. +* cache additional payload data. +* resolve n+1 issues +* figure out why location doesn't lazy load in jbuilder template. +* rename license to well license + +##### nice to haves + +* simplecov +* factory girl +* dotenv +* bullet -- cgit v1.2.3 From f246a5b0d0fac8346035088257be328f63edf06f Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 12:45:59 -0700 Subject: display errors in dev mode. --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 424262c..419e9b0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :null_session before_filter :load_additional_payload_data - rescue_from StandardError, with: :return_server_error + rescue_from StandardError, with: :return_server_error unless Rails.env.development? def load_additional_payload_data @license_statuses = LicenseStatus::ALL -- cgit v1.2.3 From d62b19c584862b3c54559348475a93fffd985e7f Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 12:46:27 -0700 Subject: load the location as expected. --- app/views/v1/licenses/_license.jbuilder | 2 +- app/views/v1/licenses/_location.jbuilder | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/v1/licenses/_license.jbuilder b/app/views/v1/licenses/_license.jbuilder index 9d04606..c66fb3f 100644 --- a/app/views/v1/licenses/_license.jbuilder +++ b/app/views/v1/licenses/_license.jbuilder @@ -1,6 +1,6 @@ json.id license.id json.status license.status.to_s -json.partial! 'v1/licenses/location', location: license.to_json +json.partial! 'v1/licenses/location', location: license.location if license.confidential? json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type json.partial! 'v1/licenses/confidential_company' diff --git a/app/views/v1/licenses/_location.jbuilder b/app/views/v1/licenses/_location.jbuilder index b9c0625..5b43756 100644 --- a/app/views/v1/licenses/_location.jbuilder +++ b/app/views/v1/licenses/_location.jbuilder @@ -1,5 +1,5 @@ json.location do - json.township location["township"] - json.latitude location["latitude"] - json.longitude location["longitude"] + json.township location.township + json.latitude location.latitude + json.longitude location.longitude end -- cgit v1.2.3 From d363dc6298e8210fb3a5eddea8a6916a54005290 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 13:03:45 -0700 Subject: switch from has_one to belongs_to relationship. --- app/models/license.rb | 2 +- app/models/location.rb | 2 +- bin/sample.rb | 3 ++- db/migrate/20140222194718_add_location_id_to_licenses.rb | 6 ++++++ db/schema.rb | 4 ++-- 5 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20140222194718_add_location_id_to_licenses.rb diff --git a/app/models/license.rb b/app/models/license.rb index 12bb387..b7e1dff 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,7 +1,7 @@ class License < ActiveRecord::Base belongs_to :company belongs_to :well_type - has_one :location + belongs_to :location belongs_to :applicant, class_name: 'User', foreign_key: 'user_id' def status diff --git a/app/models/location.rb b/app/models/location.rb index b74eabc..5587398 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,3 +1,3 @@ class Location < ActiveRecord::Base - belongs_to :license, autosave: true + has_one :license, autosave: true end diff --git a/bin/sample.rb b/bin/sample.rb index e1e92a3..97bfcf0 100755 --- a/bin/sample.rb +++ b/bin/sample.rb @@ -9,12 +9,13 @@ hal = User.create(first_name: 'hal', last_name: 'kvisle', company: xyz_resources township_1 = Location.create(latitude: 51.06, longitude: -114.09, township: '1') township_2 = Location.create(latitude: 40.06, longitude: -100.09, township: '2') +township_3 = Location.create(latitude: 30.06, longitude: -90.01, township: '3') public_license = jd.apply_for_license(WellType::NFW, township_1) public_license.update_attribute(:issued_at, 1.day.ago) public_license.update_attribute(:expired_at, 1.year.from_now) -public_expired_license = jd.apply_for_license(WellType::DPT, township_1) +public_expired_license = jd.apply_for_license(WellType::DPT, township_3) public_expired_license.update_attribute(:issued_at, 1.year.ago) public_expired_license.update_attribute(:expired_at, 1.day.ago) diff --git a/db/migrate/20140222194718_add_location_id_to_licenses.rb b/db/migrate/20140222194718_add_location_id_to_licenses.rb new file mode 100644 index 0000000..067e7e4 --- /dev/null +++ b/db/migrate/20140222194718_add_location_id_to_licenses.rb @@ -0,0 +1,6 @@ +class AddLocationIdToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :location_id, :uuid + remove_column :locations, :license_id + end +end diff --git a/db/schema.rb b/db/schema.rb index f102db8..b397f77 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222145409) do +ActiveRecord::Schema.define(version: 20140222194718) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -32,10 +32,10 @@ ActiveRecord::Schema.define(version: 20140222145409) do t.boolean "confidential", default: false t.integer "well_type_id" t.uuid "user_id" + t.uuid "location_id" end create_table "locations", id: :uuid, default: "uuid_generate_v4()", force: true do |t| - t.uuid "license_id" t.float "latitude" t.float "longitude" t.string "township" -- cgit v1.2.3 From c55f2a19870e4077f2abdea4ed8db18c42d3b3c9 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 13:13:38 -0700 Subject: create a new heroku app. --- SOLUTION.md | 2 +- bin/acceptance.sh | 12 ++++++------ bin/logs.sh | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SOLUTION.md b/SOLUTION.md index 0488b00..ca5be91 100644 --- a/SOLUTION.md +++ b/SOLUTION.md @@ -1,6 +1,6 @@ ### Solution -This solution is hosted on heroku at: [http://infinite-atoll-2481.herokuapp.com](http://infinite-atoll-2481.herokuapp.com) +This solution is hosted on heroku at: [http://fast-crag-4288.herokuapp.com](http://fast-crag-4288.herokuapp.com) #### Endpoints diff --git a/bin/acceptance.sh b/bin/acceptance.sh index 25c23bb..c96c447 100755 --- a/bin/acceptance.sh +++ b/bin/acceptance.sh @@ -1,13 +1,13 @@ #!/bin/bash set -e -TARGET_HOST=http://infinite-atoll-2481.herokuapp.com -COMPANY_ABC=3a573311-af7a-4a22-8ac6-d62e0b23b804 -COMPANY_XYZ=05956a2f-6251-4705-9bba-48ac8b36ac86 +TARGET_HOST=http://fast-crag-4288.herokuapp.com +COMPANY_ABC=680fc2c1-9557-49fd-b05f-0f700a67ca0c +COMPANY_XYZ=04e6b076-41ca-4849-8a94-14e4e505ffe8 -PUBLIC_ACTIVE_LICENSE=3806087a-ce07-47be-b613-85ee586fe5d3 -PUBLIC_EXPIRED_LICENSE=e35d2649-9bd0-4cea-9159-0daaad3f1115 -CONFIDENTIAL_ACTIVE_LICENSE=7a4bebeb-c067-44a1-9f9c-2c1ee513b526 +PUBLIC_ACTIVE_LICENSE=e4650fd2-2298-463a-bfcd-fb953d996d6e +PUBLIC_EXPIRED_LICENSE=20d69330-ebc9-40b6-9d25-0174aea3c056 +CONFIDENTIAL_ACTIVE_LICENSE=fd3918dd-6296-49ce-83bb-c518916fb82e clear diff --git a/bin/logs.sh b/bin/logs.sh index 3662a74..d088ddf 100755 --- a/bin/logs.sh +++ b/bin/logs.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -heroku logs --tail --app infinite-atoll-2481 +heroku logs --tail --app fast-crag-4288 -- cgit v1.2.3 From f0cd650dbaae9cae6f3a532690c6984b02e4663f Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 13:35:05 -0700 Subject: hardcode ids in sample script. --- bin/sample.rb | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/bin/sample.rb b/bin/sample.rb index 97bfcf0..5297ff4 100755 --- a/bin/sample.rb +++ b/bin/sample.rb @@ -1,25 +1,41 @@ #!/usr/bin/env ruby require ::File.expand_path('../../config/environment', __FILE__) -abc_resources = Company.create(name: 'ABC Resources Ltd.') -xyz_resources = Company.create(name: 'XYZ Resources Ltd.') +ActiveRecord::Base.transaction do + abc_resources = Company.create(id: '680fc2c1-9557-49fd-b05f-0f700a67ca0c', name: 'ABC Resources Ltd.') + xyz_resources = Company.create(id: '04e6b076-41ca-4849-8a94-14e4e505ffe8', name: 'XYZ Resources Ltd.') -jd = User.create(first_name: 'john', last_name: 'dielwart', company: abc_resources) -hal = User.create(first_name: 'hal', last_name: 'kvisle', company: xyz_resources) + jd = User.create(first_name: 'john', last_name: 'dielwart', company: abc_resources) + hal = User.create(first_name: 'hal', last_name: 'kvisle', company: xyz_resources) -township_1 = Location.create(latitude: 51.06, longitude: -114.09, township: '1') -township_2 = Location.create(latitude: 40.06, longitude: -100.09, township: '2') -township_3 = Location.create(latitude: 30.06, longitude: -90.01, township: '3') + township_1 = Location.create(latitude: 51.06, longitude: -114.09, township: '1') + township_2 = Location.create(latitude: 40.06, longitude: -100.09, township: '2') + township_3 = Location.create(latitude: 30.06, longitude: -90.01, township: '3') -public_license = jd.apply_for_license(WellType::NFW, township_1) -public_license.update_attribute(:issued_at, 1.day.ago) -public_license.update_attribute(:expired_at, 1.year.from_now) + public_license = abc_resources.licenses.create( + id: 'e4650fd2-2298-463a-bfcd-fb953d996d6e', + well_type: WellType::NFW, + location: township_1, + applicant: jd, + issued_at: 1.day.ago, + expired_at: 1.year.from_now + ) -public_expired_license = jd.apply_for_license(WellType::DPT, township_3) -public_expired_license.update_attribute(:issued_at, 1.year.ago) -public_expired_license.update_attribute(:expired_at, 1.day.ago) + public_expired_license = abc_resources.licenses.create( + id: '20d69330-ebc9-40b6-9d25-0174aea3c056', + well_type: WellType::DPT, + location: township_3, + applicant: jd, + issued_at: 1.year.ago, + expired_at: 1.day.ago + ) -confidential_license = hal.apply_for_license(WellType::SPT, township_2) -confidential_license.update_attribute(:confidential, true) -confidential_license.update_attribute(:issued_at, 1.day.ago) -confidential_license.update_attribute(:expired_at, 1.year.from_now) + confidential_license = xyz_resources.licenses.create( + id: 'fd3918dd-6296-49ce-83bb-c518916fb82e', + well_type: WellType::SPT, + location: township_2, + applicant: hal, + issued_at: 1.day.ago, + expired_at: 1.year.from_now + ) +end -- cgit v1.2.3 From ec7a4537c4559613e65e79ab780041c9666817b9 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Feb 2014 13:37:09 -0700 Subject: switch host. --- SOLUTION.md | 2 +- bin/acceptance.sh | 2 +- bin/logs.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SOLUTION.md b/SOLUTION.md index ca5be91..21f2934 100644 --- a/SOLUTION.md +++ b/SOLUTION.md @@ -1,6 +1,6 @@ ### Solution -This solution is hosted on heroku at: [http://fast-crag-4288.herokuapp.com](http://fast-crag-4288.herokuapp.com) +This solution is hosted on heroku at: [http://damp-scrubland-3368.herokuapp.com](http://damp-scrubland-3368.herokuapp.com) #### Endpoints diff --git a/bin/acceptance.sh b/bin/acceptance.sh index c96c447..4644deb 100755 --- a/bin/acceptance.sh +++ b/bin/acceptance.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -TARGET_HOST=http://fast-crag-4288.herokuapp.com +TARGET_HOST=http://damp-scrubland-3368.herokuapp.com COMPANY_ABC=680fc2c1-9557-49fd-b05f-0f700a67ca0c COMPANY_XYZ=04e6b076-41ca-4849-8a94-14e4e505ffe8 diff --git a/bin/logs.sh b/bin/logs.sh index d088ddf..89aa147 100755 --- a/bin/logs.sh +++ b/bin/logs.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e -heroku logs --tail --app fast-crag-4288 +heroku logs --tail --app damp-scrubland-3368 -- cgit v1.2.3