Commit 05ba97a

mo khan <mo@mokhan.ca>
2014-11-10 16:53:19
show list of applications.
1 parent 33c445a
app/assets/javascripts/controllers/applications.js.coffee
@@ -0,0 +1,2 @@
+App.ApplicationsController = Ember.ArrayController.extend(
+)
app/assets/javascripts/models/application.js.coffee
@@ -0,0 +1,2 @@
+App.Application = DS.Model.extend
+  name: DS.attr('string')
app/assets/javascripts/routes/applications_route.js.coffee
@@ -0,0 +1,4 @@
+App.ApplicationsRoute = Ember.Route.extend(
+  model: ->
+    @store.findAll('application')
+)
app/assets/javascripts/templates/application.hbs
@@ -4,6 +4,7 @@
       <ul class="nav nav-sidebar">
         <li>{{#link-to 'index'}}Overview{{/link-to}}</li>
         <li>{{#link-to 'videos'}}Videos{{/link-to}}</li>
+        <li>{{#link-to 'applications'}}Applications{{/link-to}}</li>
       </ul>
     </div>
     <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
app/assets/javascripts/templates/applications.hbs
@@ -0,0 +1,9 @@
+<h1>Applications</h1>
+
+{{#link-to 'applications.new'}}new application{{/link-to}}
+
+{{#each application in controller}}
+  {{application.name}}
+{{/each}}
+
+{{outlet}}
app/assets/javascripts/router.js.coffee
@@ -8,3 +8,5 @@ App.Router.map ()->
     @route 'new'
     @resource 'video', { path: ':video_id' }, ->
       @route 'edit'
+  @resource 'applications', ->
+    @route 'new'
app/controllers/application_controller.rb
@@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base
   private
 
   def ensure_valid_session
+    #::TODO look up session by unique session key not id.
     unless session[:user_session_id] && @current_session = Session.find(session[:user_session_id])
       redirect_to new_session_path
     end
app/controllers/applications_controller.rb
@@ -0,0 +1,5 @@
+class ApplicationsController < ApplicationController
+  def index
+    @applications = Application.all
+  end
+end
app/models/application.rb
@@ -0,0 +1,2 @@
+class Application < ActiveRecord::Base
+end
app/views/applications/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.applications @applications do |application|
+  json.id application.id
+  json.title application.title
+end
config/routes.rb
@@ -1,6 +1,7 @@
 Erkell::Application.routes.draw do
   resources :sessions, only: [:new, :create, :destroy]
   resources :videos, only: [:index, :create, :update, :destroy]
+  resources :applications, only: [:index]
   get 'dashboard', to: 'dashboard#index'
   root 'dashboard#index'
   # The priority is based upon order of creation: first created -> highest priority.
db/migrate/20141110163805_create_applications.rb
@@ -0,0 +1,9 @@
+class CreateApplications < ActiveRecord::Migration
+  def change
+    create_table :applications do |t|
+      t.string :name
+
+      t.timestamps
+    end
+  end
+end
db/schema.rb
@@ -11,11 +11,17 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20141110011156) do
+ActiveRecord::Schema.define(version: 20141110163805) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
 
+  create_table "applications", force: true do |t|
+    t.string   "name"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+  end
+
   create_table "sessions", force: true do |t|
     t.integer  "user_id"
     t.string   "ip_address"
spec/controllers/applications_controller_spec.rb
@@ -0,0 +1,19 @@
+require 'rails_helper'
+
+describe ApplicationsController do
+  let(:user) { user_session.user }
+  let(:user_session) { create(:session) }
+
+  before :each do
+    session[:user_session_id] = user_session.id
+  end
+
+  describe "#index" do
+    let!(:application) { create(:application) }
+
+    it 'returns a list of all registered applications' do
+      xhr :get, :index
+      expect(assigns(:applications)).to include(application)
+    end
+  end
+end
spec/models/application_spec.rb
@@ -0,0 +1,4 @@
+require 'rails_helper'
+
+describe Application do
+end
spec/factories.rb
@@ -15,4 +15,8 @@ FactoryGirl.define do
   factory :session do
     user
   end
+
+  factory :application do
+    name Faker::Company.name
+  end
 end