Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH
coursemology-evaluator (0.0.0)
active_rest_client (~> 1.2)
activesupport (~> 4.2.0)
faraday_middleware

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -36,6 +37,8 @@ GEM
unf (>= 0.0.5, < 1.0.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.10.0)
faraday (>= 0.7.4, < 0.10)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
Expand Down Expand Up @@ -79,6 +82,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
vcr (3.0.0)

PLATFORMS
mswin64
Expand All @@ -91,6 +95,7 @@ DEPENDENCIES
rake
rspec
simplecov
vcr

BUNDLED WITH
1.10.6
2 changes: 2 additions & 0 deletions coursemology-evaluator.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'codeclimate-test-reporter'
spec.add_development_dependency 'vcr'

spec.add_dependency 'activesupport', '~> 4.2.0'
spec.add_dependency 'active_rest_client', '~> 1.2'
spec.add_dependency 'faraday_middleware'
end
1 change: 1 addition & 0 deletions lib/coursemology/evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_support/all'
require 'active_rest_client'
require 'faraday_middleware'
require 'coursemology/evaluator/version'

module Coursemology::Evaluator
Expand Down
2 changes: 2 additions & 0 deletions lib/coursemology/evaluator/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def self.initialize(host, api_user_email, api_token)
Coursemology::Evaluator::Models::Base.base_url = host
Coursemology::Evaluator::Models::Base.api_user_email = api_user_email
Coursemology::Evaluator::Models::Base.api_token = api_token

Coursemology::Evaluator::Models::Base.initialize
end

def initialize
Expand Down
12 changes: 12 additions & 0 deletions lib/coursemology/evaluator/models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ class Coursemology::Evaluator::Models::Base < ActiveRestClient::Base
class << self
attr_accessor :api_user_email
attr_accessor :api_token

def initialize
ActiveRestClient::Base.perform_caching = false
default_config = ActiveRestClient::Base.faraday_config
ActiveRestClient::Base.faraday_config do |faraday|
# +follow_redirects+ must be added before declaring the adapter. See faraday_middleware#32,
# last comment.
faraday.response :follow_redirects

default_config.call(faraday)
end
end
end

before_request :add_authentication
Expand Down
28 changes: 28 additions & 0 deletions lib/coursemology/evaluator/models/programming_evaluation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Coursemology::Evaluator::Models::ProgrammingEvaluation < Coursemology::Evaluator::Models::Base
extend ActiveSupport::Autoload
autoload :Package

get :find, 'courses/assessment/programming_evaluations/:id'
post :allocate, 'courses/assessment/programming_evaluations/allocate'

# Obtains the package.
#
# @return [Coursemology::Evaluator::Models::ProgrammingEvaluation::Package]
def package
body = plain_request('courses/assessment/programming_evaluations/:id/package', id: id)
Package.new(StringIO.new(body))
end

private

# Performs a plain request.
#
# @param [String] url The URL to request.
# @param [Hash] params The parameter to be part of the request.
# @return [String] The response body.
def plain_request(url, params = {})
request = ActiveRestClient::Request.new({ url: url, method: :get, options: { plain: true } },
self.class)
request.call(params)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Coursemology::Evaluator::Models::ProgrammingEvaluation::Package
# Constructs a new Package.
#
# @param [IO] io The IO object containing the package data.
def initialize(io)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method argument - io. If it's necessary, use _ or _io as an argument name to indicate that it won't be used. You can also write as initialize(*) if you want the method to accept any arguments but don't care about them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allenwq I'll ignore this first, I want to implement the logic in a separate PR.

end
end
4 changes: 2 additions & 2 deletions spec/coursemology/evaluator/models/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
subject { Coursemology::Evaluator::Models::Base }

describe '.api_user_email' do
it { is_expected.to have_attributes(api_user_email: nil) }
it { is_expected.to have_attributes(api_user_email: anything) }
end

describe '.api_token' do
it { is_expected.to have_attributes(api_token: nil) }
it { is_expected.to have_attributes(api_token: anything) }
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'spec_helper'

RSpec.describe Coursemology::Evaluator::Models::ProgrammingEvaluation::Package do
around(:each) do |example|
File.open(Pathname.new(__dir__).join('../../../..',
'fixtures/programming_question_template.zip')) do |file|
define_singleton_method(:file) { file }
example.call
end
end

let(:package) { Coursemology::Evaluator::Models::ProgrammingEvaluation::Package.new(file) }
describe '#initialize' do
it 'accepts an IO object' do
package
end
end
end
34 changes: 34 additions & 0 deletions spec/coursemology/evaluator/models/programming_evaluation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

RSpec.describe Coursemology::Evaluator::Models::ProgrammingEvaluation do
describe '.allocate' do
let(:evaluation) { Coursemology::Evaluator::Models::ProgrammingEvaluation.allocate.first }
it 'obtains an unallocated evaluation' do
VCR.use_cassette 'programming_evaluation/allocate' do
expect(evaluation.id).not_to be_nil
end
end
end

describe '.find' do
let(:find_id) { 2 }
let(:evaluation) { Coursemology::Evaluator::Models::ProgrammingEvaluation.find(find_id) }

it 'obtains the requested evaluation' do
VCR.use_cassette 'programming_evaluation/find' do
expect(evaluation.id).to eq(find_id)
end
end
end

describe '#package' do
let(:evaluation) { Coursemology::Evaluator::Models::ProgrammingEvaluation.find(3) }

it 'obtains the requested package' do
VCR.use_cassette 'programming_evaluation/package' do
expect(evaluation.package).to \
be_a(Coursemology::Evaluator::Models::ProgrammingEvaluation::Package)
end
end
end
end
Binary file added spec/fixtures/programming_question_template.zip
Binary file not shown.
58 changes: 58 additions & 0 deletions spec/fixtures/vcr/cassettes/programming_evaluation/allocate.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions spec/fixtures/vcr/cassettes/programming_evaluation/find.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading