scidea-cv-sco_completion 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ 0.0.1
2
+ - initial release
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Scitent, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # Scidea (CardioVillage) Sco Completion
2
+
3
+ This gem adds an alternative method for CardioVillage to signal exercise completion to Scidea.
4
+
5
+ It responds to `POST scos/sco_records/update`.
6
+
7
+ ## Usage
8
+
9
+ 1. Add `scidea-cv-sco_completion` to your Scidea Gemfile:
10
+
11
+ ```
12
+ # Gemfile
13
+ gem 'requirejs-rails'
14
+ ```
15
+
16
+ 2. Add the following key to your config.yml file; it's a secret key allowing the backdoor to sidestep regular authentication:
17
+
18
+ ```
19
+ sco_record_completion_key: YOUR_SECRET_KEY_HERE
20
+ ```
21
+
22
+ ## Development Environment and Testing
23
+
24
+ The gem is configured to use rspec tests. Because there are so many dependencies upon the Scidea core, rspec has been configured to launch an instance of the core application with the plugin's resources tied in. The features and specs of the plugin, however, are the only ones executed when you run rspec.
25
+
26
+ To set up your environment for testing, perform the following:
27
+
28
+ 1. In your local Scidea core instance, add the following line to the Gemfile:
29
+
30
+ ```
31
+ # Gemfile
32
+ gem 'scidea-cv-sco_completion', :path => 'LOCAL_PATH_TO_THIS_GEM'
33
+ ```
34
+
35
+ 2. Copy the contents of the Scidea core Gemfile *after* ``gemspec``, and paste it to the end of the Gemfile in the scidea-cv-sco_completion code. When you run rspec, it requires this Gemfile, thus you need all of the gems that Scidea core requires as well.
36
+
37
+ ```
38
+ source 'http://rubygems.org'
39
+
40
+ gemspec
41
+
42
+ gem 'scidea', :path => 'LOCAL_PATH_TO_SCIDEA-CORE'
43
+
44
+ #from scidea core Gemfile:
45
+ gem 'rails', '= 3.1.3'
46
+
47
+ # db
48
+ gem 'mysql2', '>= 0.3'
49
+
50
+ # authentication and authorization
51
+ gem 'devise', '< 2.0'
52
+ gem 'cancan'
53
+
54
+ ... and so on
55
+ ```
56
+
57
+ From scidea-schools, you can run ``rspec``. Note that FactoryGirl factories from the Scidea core are included in the testing runtime and added to whatever you include in ``spec/factories``. The database configuration from the Scidea core will also be used. You must run all rake operations for that database in the context of the Scidea core folder. They will not work in the scidea-cv-sco_completion folder.
58
+
59
+ ----
60
+
61
+ Copyright 2012 Scitent, Inc. See the file MIT-LICENSE for terms.
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'rake'
@@ -0,0 +1,32 @@
1
+ require 'active_resource/exceptions'
2
+
3
+ module Client
4
+ class ScoRecordsController < ApplicationController
5
+
6
+ ssl_required :complete
7
+ skip_filter :authenticate_user!, :only => :complete
8
+ protect_from_forgery :except => :complete
9
+
10
+ def complete
11
+ begin
12
+ throw ActiveResource::UnauthorizedAccess.new('Invalid key') unless params.has_key?(:key) && params[:key] == APP_CONFIG['sco_record_completion_key']
13
+
14
+ sco = Sco.find_by_identifier_ref(params[:identifier_ref])
15
+ user = User.find_by_id(params[:user_id])
16
+
17
+ @sco_record = ScoRecord.by_sco(sco).for_user(user).first || ScoRecord.new(:sco => sco, :user => user)
18
+
19
+ @sco_record.status = "completed"
20
+
21
+ if @sco_record.save
22
+ head :ok
23
+ else
24
+ throw ActiveResource::ResourceNotFound.new('Exercise record validation error')
25
+ end
26
+ rescue
27
+ head :bad_request
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ # Load local Gemfile and get the path to the local core application
2
+ # (from standard rails config/boot.rb)
3
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
4
+ begin
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ rescue Bundler::GemNotFound => e
9
+ STDERR.puts e.message
10
+ STDERR.puts "Try running `bundle install`."
11
+ exit!
12
+ end if File.exist?(gemfile)
13
+
14
+ # get only the paths constants; let scidea core load all gems
15
+ require 'scidea/paths.rb'
16
+
17
+ # Load and initialize the Scidea core application
18
+ require File.expand_path('../config/environment', Scidea::APP_PATH)
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ post 'scos/sco_records/complete', :to => 'client/sco_records#complete'
3
+ end
@@ -0,0 +1,16 @@
1
+ module SeedUserRoles
2
+ def self.seed
3
+ Role.public || Factory( :role_public )
4
+ Role.learner || Factory( :role_learner )
5
+ Role.user_admin || Factory(:role_user_admin)
6
+ Role.course_admin || Factory(:role_course_admin)
7
+ Role.product_admin || Factory(:role_product_admin)
8
+ Role.tech_support || Factory(:role_tech_support)
9
+ Role.scitent_admin || Factory(:role_scitent_admin)
10
+ end
11
+
12
+ def self.clean
13
+ Role.destroy_all
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ module TestUtilities
2
+ class AssetDirectory
3
+ def self.create_test_asset_directory
4
+ FileUtils.mkdir_p APP_CONFIG['system_path']
5
+ end
6
+
7
+ def self.clear_test_asset_directory
8
+ delete_test_asset_directory
9
+ create_test_asset_directory
10
+ end
11
+
12
+ def self.delete_test_asset_directory
13
+ FileUtils.remove_dir APP_CONFIG['test_system_path_root'], force = true
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ require 'scidea/cv.rb'
@@ -0,0 +1 @@
1
+ require 'scidea/cv/sco_completion'
@@ -0,0 +1,7 @@
1
+ module Scidea
2
+ module CV
3
+ module ScoCompletion
4
+ require 'scidea/cv/sco_completion/engine' if defined?(::Rails)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'models/ability'
2
+
3
+ module Scidea
4
+ module CV
5
+ module ScoCompletion
6
+ class Engine < ::Rails::Engine
7
+ config.to_prepare do
8
+ Ability.class_eval { include Scidea::CV::ScoCompletion::Models::Ability }
9
+ end
10
+ end # class Engine
11
+ end # module Redirects
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Scidea
2
+ module CV
3
+ module ScoCompletion
4
+ module Models
5
+ module Ability
6
+ extend ActiveSupport::Concern
7
+
8
+ module InstanceMethods
9
+ def initialize_namespace_none(user)
10
+ super
11
+
12
+ # required for registration form
13
+ can(:update, ScoRecord)
14
+ end
15
+ end
16
+
17
+ end # ability
18
+ end # models
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module Scidea
2
+ module CV
3
+ module ScoCompletion
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+ require 'active_resource/exceptions'
3
+
4
+ describe Client::ScoRecordsController do
5
+ describe "update" do
6
+ before do
7
+ APP_CONFIG['sco_record_completion_key'] = "some-key-value"
8
+ end
9
+
10
+ context "the proper key is not submitted" do
11
+ it "should reject the post" do
12
+ post :complete, :key => "something else"
13
+ response.should_not be_success
14
+ end
15
+ end
16
+
17
+ context "the proper key is submitted" do
18
+ let(:sco) { Factory.build :sco, :id => 64 }
19
+ let(:user) { Factory.build :user_learner, :id => 42 }
20
+
21
+ before do
22
+ @params = { :key => APP_CONFIG['sco_record_completion_key'] }
23
+ end
24
+
25
+ context "the identifier_ref is bad" do
26
+ before do
27
+ Sco.stub(:find_by_sco_id).and_raise(ActiveResource::ResourceNotFound)
28
+ end
29
+
30
+ it "should reject the post" do
31
+ post :complete, @params
32
+ response.should_not be_success
33
+ end
34
+ end
35
+
36
+ context "the user id is incorrect" do
37
+ before do
38
+ Sco.stub(:find_by_identifier_ref).and_return(sco)
39
+ User.stub(:find_by_id).and_raise(ActiveResource::ResourceNotFound)
40
+ end
41
+
42
+ it "should reject the post" do
43
+ post :complete, @params
44
+ response.should_not be_success
45
+ end
46
+ end
47
+
48
+ context "the user id and identifier ref are correct" do
49
+ let(:sco_record) { Factory.build :sco_record }
50
+
51
+ before do
52
+ Sco.stub(:find_by_identifier_ref).with(sco.identifier_ref).and_return(sco)
53
+ User.stub(:find_by_id).with(user.id.to_s).and_return(user)
54
+ @params[:user_id] = user.id.to_s
55
+ @params[:identifier_ref] = sco.identifier_ref
56
+ end
57
+
58
+ context "the sco_record exists" do
59
+ before do
60
+ ScoRecord.stub_chain(:by_sco, :for_user, :first).and_return(sco_record)
61
+ sco_record.stub(:save).and_return(true)
62
+ end
63
+
64
+ it "should update the sco_record" do
65
+ sco_record.should_receive(:status=).with('completed')
66
+ post :complete, @params
67
+ end
68
+
69
+ it "should return a success" do
70
+ post :complete, @params
71
+ response.should be_success
72
+ end
73
+ end
74
+
75
+ context "the sco_record does not exist" do
76
+ let(:sco_record) { mock_model(ScoRecord) }
77
+
78
+ before do
79
+ ScoRecord.stub_chain(:by_sco, :for_user, :first).and_return(nil)
80
+ ScoRecord.stub(:new).and_return(sco_record)
81
+ sco_record.stub(:save).and_return(true)
82
+ sco_record.stub(:status=)
83
+ end
84
+
85
+ it "should create a new sco_record" do
86
+ ScoRecord.should_receive(:new).with({:user => user, :sco => sco}).and_return(sco_record)
87
+ post :complete, @params
88
+ end
89
+
90
+ it "should update the sco_record" do
91
+ sco_record.should_receive(:status=).with('completed')
92
+ post :complete, @params
93
+ end
94
+
95
+ it "should save the record" do
96
+ sco_record.should_receive(:save).and_return(true)
97
+ post :complete, @params
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ability do
4
+
5
+ describe "as an unregistered user" do
6
+ subject { Ability.new(User.new) }
7
+
8
+ it { should be_able_to(:update, ScoRecord) }
9
+ end
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Client::ScoRecordsController do
4
+ describe "routing" do
5
+ it "should recognize #complete" do
6
+ { :post => "scos/sco_records/complete" }.should route_to(:controller => 'client/sco_records', :action => "complete")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rspec'
8
+ require 'scidea-cv-sco_completion'
9
+
10
+ require 'rspec/rails'
11
+ require 'rspec_tag_matchers'
12
+ require 'cancan/matchers'
13
+ require 'paperclip/matchers'
14
+ require File.expand_path("../../features/support/test_utilities.rb", __FILE__)
15
+ require File.expand_path("../../features/support/seed_user_roles.rb", __FILE__)
16
+
17
+ # Requires supporting files with custom matchers and macros, etc,
18
+ # in ./support/ and its subdirectories.
19
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
20
+
21
+ RSpec.configure do |config|
22
+ config.mock_with :rspec
23
+ config.use_transactional_fixtures = true
24
+
25
+ config.before(:suite) do
26
+ DatabaseCleaner.strategy = :transaction
27
+ DatabaseCleaner.clean_with(:truncation)
28
+ TestUtilities::AssetDirectory.create_test_asset_directory
29
+ ::SeedUserRoles.seed
30
+ end
31
+
32
+ config.before(:each) do
33
+ DatabaseCleaner.start
34
+ TestUtilities::AssetDirectory.clear_test_asset_directory
35
+ end
36
+
37
+ config.after(:each) do
38
+ DatabaseCleaner.clean
39
+ end
40
+
41
+ config.after(:suite) do
42
+ ::SeedUserRoles.clean
43
+ TestUtilities::AssetDirectory.delete_test_asset_directory
44
+ end
45
+
46
+ config.include Devise::TestHelpers, :type => :controller
47
+ config.include Devise::TestHelpers, :type => :view
48
+ config.extend ControllerMacros, :type => :controller
49
+ end
50
+
51
+ # load local factories which will be added to the factories from scidea.
52
+ Rails.configuration.after_initialize do
53
+ FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
54
+ FactoryGirl.find_definitions
55
+ end
@@ -0,0 +1,15 @@
1
+ module ControllerMacros
2
+ def login_scitent_admin
3
+ before(:each) do
4
+ @request.env["devise.mapping"] = Devise.mappings[:users]
5
+ sign_in Factory(:user_scitent_admin)
6
+ end
7
+ end
8
+
9
+ def login_learner
10
+ before(:each) do
11
+ @request.env["devise.mapping"] = Devise.mappings[:users]
12
+ sign_in Factory(:user_learner)
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scidea-cv-sco_completion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phoenix Team
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-29 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Custom exercise completion mechanism for CardioVillage. This is not a
15
+ reusable Gem
16
+ email:
17
+ - phoenix@scitent.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - app/controllers/client/sco_records_controller.rb
23
+ - lib/scidea-cv-sco_completion.rb
24
+ - lib/scidea/cv.rb
25
+ - lib/scidea/cv/sco_completion.rb
26
+ - lib/scidea/cv/sco_completion/engine.rb
27
+ - lib/scidea/cv/sco_completion/models/ability.rb
28
+ - lib/scidea/cv/sco_completion/version.rb
29
+ - config/routes.rb
30
+ - config/environment.rb
31
+ - features/support/seed_user_roles.rb
32
+ - features/support/test_utilities.rb
33
+ - spec/controllers/client/sco_records_controller_spec.rb
34
+ - spec/routing/sco_records_routing_spec.rb
35
+ - spec/support/controller_macros.rb
36
+ - spec/models/ability_spec.rb
37
+ - spec/spec_helper.rb
38
+ - MIT-LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - CHANGELOG
42
+ homepage: https://github.com/phoenix-scitent/scidea-cv-sco_completion
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.10
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Custom exercise completion mechanism for CardioVillage
66
+ test_files: []