diff options
| author | mo khan <mo@mokhan.ca> | 2014-11-10 09:53:19 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-11-10 09:53:19 -0700 |
| commit | 05ba97aa19dde08954ee4e105b008d41a56e6903 (patch) | |
| tree | 9c7610a87ae70dcf9b902d7149a2267f901597e7 | |
| parent | 33c445a5c514a7b2f0bd4039b177043033f7b7fb (diff) | |
show list of applications.
| -rw-r--r-- | app/assets/javascripts/controllers/applications.js.coffee | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/models/application.js.coffee | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/router.js.coffee | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/routes/applications_route.js.coffee | 4 | ||||
| -rw-r--r-- | app/assets/javascripts/templates/application.hbs | 1 | ||||
| -rw-r--r-- | app/assets/javascripts/templates/applications.hbs | 9 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/applications_controller.rb | 5 | ||||
| -rw-r--r-- | app/models/application.rb | 2 | ||||
| -rw-r--r-- | app/views/applications/index.json.jbuilder | 4 | ||||
| -rw-r--r-- | config/routes.rb | 1 | ||||
| -rw-r--r-- | db/migrate/20141110163805_create_applications.rb | 9 | ||||
| -rw-r--r-- | db/schema.rb | 8 | ||||
| -rw-r--r-- | spec/controllers/applications_controller_spec.rb | 19 | ||||
| -rw-r--r-- | spec/factories.rb | 4 | ||||
| -rw-r--r-- | spec/models/application_spec.rb | 4 |
16 files changed, 76 insertions, 1 deletions
diff --git a/app/assets/javascripts/controllers/applications.js.coffee b/app/assets/javascripts/controllers/applications.js.coffee new file mode 100644 index 0000000..f44d64f --- /dev/null +++ b/app/assets/javascripts/controllers/applications.js.coffee @@ -0,0 +1,2 @@ +App.ApplicationsController = Ember.ArrayController.extend( +) diff --git a/app/assets/javascripts/models/application.js.coffee b/app/assets/javascripts/models/application.js.coffee new file mode 100644 index 0000000..7d847d5 --- /dev/null +++ b/app/assets/javascripts/models/application.js.coffee @@ -0,0 +1,2 @@ +App.Application = DS.Model.extend + name: DS.attr('string') diff --git a/app/assets/javascripts/router.js.coffee b/app/assets/javascripts/router.js.coffee index 3420870..132e89b 100644 --- a/app/assets/javascripts/router.js.coffee +++ b/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' diff --git a/app/assets/javascripts/routes/applications_route.js.coffee b/app/assets/javascripts/routes/applications_route.js.coffee new file mode 100644 index 0000000..beef96b --- /dev/null +++ b/app/assets/javascripts/routes/applications_route.js.coffee @@ -0,0 +1,4 @@ +App.ApplicationsRoute = Ember.Route.extend( + model: -> + @store.findAll('application') +) diff --git a/app/assets/javascripts/templates/application.hbs b/app/assets/javascripts/templates/application.hbs index d3be80d..3f7c19b 100644 --- a/app/assets/javascripts/templates/application.hbs +++ b/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"> diff --git a/app/assets/javascripts/templates/applications.hbs b/app/assets/javascripts/templates/applications.hbs new file mode 100644 index 0000000..8289250 --- /dev/null +++ b/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}} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 08650a8..f94dcfa 100644 --- a/app/controllers/application_controller.rb +++ b/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 diff --git a/app/controllers/applications_controller.rb b/app/controllers/applications_controller.rb new file mode 100644 index 0000000..28201e4 --- /dev/null +++ b/app/controllers/applications_controller.rb @@ -0,0 +1,5 @@ +class ApplicationsController < ApplicationController + def index + @applications = Application.all + end +end diff --git a/app/models/application.rb b/app/models/application.rb new file mode 100644 index 0000000..3adac78 --- /dev/null +++ b/app/models/application.rb @@ -0,0 +1,2 @@ +class Application < ActiveRecord::Base +end diff --git a/app/views/applications/index.json.jbuilder b/app/views/applications/index.json.jbuilder new file mode 100644 index 0000000..0219209 --- /dev/null +++ b/app/views/applications/index.json.jbuilder @@ -0,0 +1,4 @@ +json.applications @applications do |application| + json.id application.id + json.title application.title +end diff --git a/config/routes.rb b/config/routes.rb index bde8f92..e415386 100644 --- a/config/routes.rb +++ b/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. diff --git a/db/migrate/20141110163805_create_applications.rb b/db/migrate/20141110163805_create_applications.rb new file mode 100644 index 0000000..f9c652f --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index c73bd92..a06e22f 100644 --- a/db/schema.rb +++ b/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" diff --git a/spec/controllers/applications_controller_spec.rb b/spec/controllers/applications_controller_spec.rb new file mode 100644 index 0000000..33ed7c1 --- /dev/null +++ b/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 diff --git a/spec/factories.rb b/spec/factories.rb index 64fe089..71e9916 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,4 +15,8 @@ FactoryGirl.define do factory :session do user end + + factory :application do + name Faker::Company.name + end end diff --git a/spec/models/application_spec.rb b/spec/models/application_spec.rb new file mode 100644 index 0000000..68f4ab0 --- /dev/null +++ b/spec/models/application_spec.rb @@ -0,0 +1,4 @@ +require 'rails_helper' + +describe Application do +end |
