From 82c07fd8ca095abb1a88bb82adf4f583e81d4338 Mon Sep 17 00:00:00 2001 From: Chris Radcliff Date: Wed, 9 Nov 2011 14:52:18 -0800 Subject: [PATCH] Basic setup and super-basic outlet model. Added Boxer for JSON packaging, mysql-centric database example configuration, and the core of the outlet object. --- .gitignore | 2 + Gemfile | 31 +-- app/assets/javascripts/outlets.js.coffee | 3 + app/assets/stylesheets/outlets.css.scss | 3 + app/controllers/outlets_controller.rb | 6 + app/helpers/outlets_helper.rb | 2 + app/models/outlet.rb | 33 +++ app/views/outlets/add.html.erb | 2 + config/database.example.yml | 37 ++- config/initializers/boxer.rb | 5 + config/routes.rb | 5 +- db/migrate/20111109005849_create_outlets.rb | 16 ++ db/schema.rb | 29 +++ public/index.html | 243 +------------------- spec/controllers/outlets_controller_spec.rb | 12 + spec/models/outlet_spec.rb | 44 ++++ spec/spec_helper.rb | 27 +++ 17 files changed, 224 insertions(+), 276 deletions(-) create mode 100644 app/assets/javascripts/outlets.js.coffee create mode 100644 app/assets/stylesheets/outlets.css.scss create mode 100644 app/controllers/outlets_controller.rb create mode 100644 app/helpers/outlets_helper.rb create mode 100644 app/models/outlet.rb create mode 100644 app/views/outlets/add.html.erb create mode 100644 config/initializers/boxer.rb create mode 100644 db/migrate/20111109005849_create_outlets.rb create mode 100644 db/schema.rb create mode 100644 spec/controllers/outlets_controller_spec.rb create mode 100644 spec/models/outlet_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index 5916280d1..8bdd4126e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ tmp/ *.lock bin/ config/database.yml +.autotest +.rspec diff --git a/Gemfile b/Gemfile index 957054c19..796eb2f9a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,11 +2,12 @@ source 'http://rubygems.org' gem 'rails', '3.1.1' -# Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' - -gem 'sqlite3' +gem 'mysql2' +# Templates for generating JSON and other data output +# see https://github.com/gowalla/boxer +gem 'boxer' +gem 'json' # Gems used only for assets and not required # in production environments by default. @@ -18,19 +19,19 @@ end gem 'jquery-rails' -# To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' - -# Use unicorn as the web server -# gem 'unicorn' - -# Deploy with Capistrano -# gem 'capistrano' - -# To use debugger -# gem 'ruby-debug19', :require => 'ruby-debug' +group :development do + gem 'rspec-rails', '2.6.1' + gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git' + gem 'faker', '0.3.1' +end group :test do # Pretty printed test output gem 'turn', :require => false + gem 'rspec-rails', '2.6.1' + gem 'webrat', '0.7.1' + gem 'autotest', '4.4.6' + gem 'autotest-rails-pure', '4.1.2' + gem 'autotest-fsevent', '0.2.4' + gem 'autotest-growl', '0.2.9' end diff --git a/app/assets/javascripts/outlets.js.coffee b/app/assets/javascripts/outlets.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/outlets.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/outlets.css.scss b/app/assets/stylesheets/outlets.css.scss new file mode 100644 index 000000000..817b97425 --- /dev/null +++ b/app/assets/stylesheets/outlets.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Outlets controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/outlets_controller.rb b/app/controllers/outlets_controller.rb new file mode 100644 index 000000000..96d84f960 --- /dev/null +++ b/app/controllers/outlets_controller.rb @@ -0,0 +1,6 @@ +class OutletsController < ApplicationController + def add + @outlet = Outlet.resolve(params[:service_url]) + end + +end diff --git a/app/helpers/outlets_helper.rb b/app/helpers/outlets_helper.rb new file mode 100644 index 000000000..3a13737b4 --- /dev/null +++ b/app/helpers/outlets_helper.rb @@ -0,0 +1,2 @@ +module OutletsHelper +end diff --git a/app/models/outlet.rb b/app/models/outlet.rb new file mode 100644 index 000000000..dac44ee48 --- /dev/null +++ b/app/models/outlet.rb @@ -0,0 +1,33 @@ +# == Schema Information +# +# Table name: outlets +# +# id :integer(4) not null, primary key +# service_url :string(255) +# organization :string(255) +# info_url :string(255) +# account :string(255) +# language :string(255) +# updated_by :string(255) +# created_at :datetime +# updated_at :datetime +# + +class Outlet < ActiveRecord::Base + attr_accessor :updated_by + attr_accessible :service_url, :organization, :info_url, :account, :language + + validates :service_url, + :presence => true, + :format => { :with => URI::regexp(%w(http https)) }, + :uniqueness => { :case_sensitive => false } + + def self.resolve(url) + # TODO: + # Resolve the URL down to a service and account ID + # Look up existing settings for this outlet, or + # set up sensible defaults for the object. + self.new(:service_url => url) + end + +end diff --git a/app/views/outlets/add.html.erb b/app/views/outlets/add.html.erb new file mode 100644 index 000000000..01c8e2e48 --- /dev/null +++ b/app/views/outlets/add.html.erb @@ -0,0 +1,2 @@ +

Outlets#add

+

Find me in app/views/outlets/add.html.erb

diff --git a/config/database.example.yml b/config/database.example.yml index 51a4dd459..1a32dad11 100644 --- a/config/database.example.yml +++ b/config/database.example.yml @@ -1,25 +1,18 @@ -# 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. + adapter: mysql2 + database: ringsail_development + encoding: utf8 + collation: utf8_unicode_ci + host: localhost test: - adapter: sqlite3 - database: db/test.sqlite3 - pool: 5 - timeout: 5000 - + adapter: mysql2 + database: ringsail_test + encoding: utf8 + collation: utf8_unicode_ci + host: localhost production: - adapter: sqlite3 - database: db/production.sqlite3 - pool: 5 - timeout: 5000 + adapter: mysql2 + database: ringsail_production + encoding: utf8 + collation: utf8_unicode_ci + host: localhost diff --git a/config/initializers/boxer.rb b/config/initializers/boxer.rb new file mode 100644 index 000000000..bd5c466d8 --- /dev/null +++ b/config/initializers/boxer.rb @@ -0,0 +1,5 @@ +# Make URL helpers available in all boxes +Boxer.configure do |config| + config.box_includes = [Rails.application.routes.url_helpers] +end + diff --git a/config/routes.rb b/config/routes.rb index 11c49024a..db47d9f64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Ringsail::Application.routes.draw do + get "outlets/add" + # The priority is based upon order of creation: # first created -> highest priority. @@ -52,7 +54,4 @@ # See how all your routes lay out with "rake routes" - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id(.:format)))' end diff --git a/db/migrate/20111109005849_create_outlets.rb b/db/migrate/20111109005849_create_outlets.rb new file mode 100644 index 000000000..c563955c6 --- /dev/null +++ b/db/migrate/20111109005849_create_outlets.rb @@ -0,0 +1,16 @@ +class CreateOutlets < ActiveRecord::Migration + def change + create_table :outlets do |t| + t.string :service_url + t.string :organization + t.string :info_url + t.string :account + t.string :language + t.string :updated_by + + t.timestamps + end + + add_index :outlets, :account + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..093e1acf6 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,29 @@ +# 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 to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20111109005849) do + + create_table "outlets", :force => true do |t| + t.string "service_url" + t.string "organization" + t.string "info_url" + t.string "account" + t.string "language" + t.string "updated_by" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "outlets", ["account"], :name => "index_outlets_on_account" + +end diff --git a/public/index.html b/public/index.html index 9d9811a5b..8ab6a0434 100644 --- a/public/index.html +++ b/public/index.html @@ -1,241 +1,12 @@ - - Ruby on Rails: Welcome aboard - - - - -
- - -
- - - - -
-

Getting started

-

Here’s how to get rolling:

- -
    -
  1. -

    Use rails generate to create your models and controllers

    -

    To see all available options, run it without parameters.

    -
  2. - -
  3. -

    Set up a default route and remove public/index.html

    -

    Routes are set up in config/routes.rb.

    -
  4. - -
  5. -

    Create your database

    -

    Run rake db:create to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

    -
  6. -
-
-
- - -
- + diff --git a/spec/controllers/outlets_controller_spec.rb b/spec/controllers/outlets_controller_spec.rb new file mode 100644 index 000000000..cd6979f38 --- /dev/null +++ b/spec/controllers/outlets_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe OutletsController do + + describe "GET 'add'" do + it "should be successful" do + get 'add' + response.should be_success + end + end + +end diff --git a/spec/models/outlet_spec.rb b/spec/models/outlet_spec.rb new file mode 100644 index 000000000..d9082e11a --- /dev/null +++ b/spec/models/outlet_spec.rb @@ -0,0 +1,44 @@ +# == Schema Information +# +# Table name: outlets +# +# id :integer(4) not null, primary key +# service_url :string(255) +# organization :string(255) +# info_url :string(255) +# account :string(255) +# language :string(255) +# updated_by :string(255) +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe Outlet do + + before(:each) do + @attr = { + :service_url => "http://twitter.com/example", + :organization => "Example Project", + :info_url => "http://example.gov", + :account => "example", + :language => "English", + :updated_by => "user@example.gov", + } + end + + it "should create a new instance given valid attributes" do + Outlet.create!(@attr) + end + + it "should require a service URL" do + no_url_outlet = Outlet.new(@attr.merge(:service_url => "")) + no_url_outlet.should_not be_valid + end + + it "should require valid URLs" do + no_url_outlet = Outlet.new(@attr.merge(:service_url => "blern.foo.com")) + no_url_outlet.should_not be_valid + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 000000000..9b8b02c8f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,27 @@ +# 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' + +# 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} + +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 + config.mock_with :rspec + + # 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 +end