Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ingridh committed Apr 4, 2015
2 parents 0cb88d7 + 0e1fbfc commit c476074
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 18 deletions.
18 changes: 1 addition & 17 deletions app/controllers/upload_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,14 @@ def upload()
#@collection1 = Collection.create(name: "Fall 14")
question_open = false
p = Problem.new
puts params["myfile"].original_filename
puts "PASS PASS PASS PASS"
File.open(params["myfile"].tempfile, 'r') do |f1|
puts 'here'
col = f1.gets
col2 = /'(.*?)'/.match(col).to_s.gsub! /'/, ''
puts "FUCK FUCK FUCK FUCK"
puts col
puts col2

@collection1 = @current_user.collections.create(name: col2)
@tag1 = Tag.create(name: col2)

while line = f1.gets
puts line
#next if line =~ /\s*quiz*/
if question_open
if not line =~ /\s*end.*/
Expand All @@ -36,15 +29,6 @@ def upload()
p.instructor = @current_user
p.tags << @tag1
p.collections<< @collection1
puts "HERE "
puts "HERE "
puts "HERE "
puts "HERE "
puts "HERE "
puts "HERE "
puts "HERE"
puts @collection1
puts p.instructor.id.to_s
p.text<<line
p.save!
p = Problem.new
Expand Down Expand Up @@ -84,4 +68,4 @@ def upload()
end
render 'complete'
end
end
end
2 changes: 1 addition & 1 deletion app/views/upload/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
%body
%h1 File uploader!
%form(method="post" enctype='multipart/form-data')
%input(type='file' name='myfile')
%input(type='file' name='myfile' id='file_upload')
%br
%input(type='submit' value='Upload!')
28 changes: 28 additions & 0 deletions features/step_definitions/upload_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Given(/^I have selected a file to upload$/) do
page.driver.browser.post('/upload', "myfile" => "test_files/foo.txt")
end

Given(/^I press the upload button$/) do
click_button "Upload!"
end

Given(/^the upload fails$/) do
pending # express the regexp above with the code you wish you had
end

Then(/^I should see a flash message telling me of failure$/) do
pending # express the regexp above with the code you wish you had
end

Given(/^I successfully upload a file$/) do
pending # express the regexp above with the code you wish you had
end

Given(/^I press upload without selecting a file$/) do
params["myfile"] = nil
end

Then(/^I should see a flash message asking me to select a file$/) do
flash[:notice] = "Please select a file"
end

1 change: 1 addition & 0 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def path_to(page_name)
when /^the login page$/ then '/login'
when /^the problems page$/ then '/problems'
when /^the dashboard$/ then '/profile'
when /^the upload page$/ then '/upload'

# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
Expand Down
46 changes: 46 additions & 0 deletions features/test_files/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
quiz 'A few example questions' do

choice_answer :randomize => true do
text "Which of the following best identifies the four basic operations supported by RDBMS?"
distractor "HTTP", :explanation => 'HTTP stands for HyperText Transfer Protocol, which is used to transfer SaaS content to browsers.'
distractor "Get, Put, Post, Delete", :explanation => 'These are four of the methods or "verbs" used by HTTP.'
answer "CRUD", :explanation => 'Create, Read, Update, Delete are the four basic database operations commonly performed by SaaS apps.'
distractor "REST", :explanation => 'REpresentational State Transfer is a design approach for making SaaS requests self-contained by having each request refer to a resource and an operation on that resource.'
end

truefalse 'If an app has a RESTful API, it must be performing CRUD operations.',
false,
:explanation => 'The REST principle can be applied to any kind of operation'

choice_answer :randomize => true do
text "The implied port number of the URI <tt>http://google.com</tt> is"
answer "80"
distractor "400"
distractor "3000"
distractor "8000"
end

select_multiple :randomize => true do
text "Which tiers in the three-tier architecture are involved in handling views?"
answer "Presentation"
answer "Logic"
distractor "Persistence"
distractor "Database"
end

choice_answer :randomize => true do
text "The ----- tier of three-tier SaaS apps is the most complicated to scale."
answer "Presentation"
distractor "Logic"
distractor "Persistence"
distractor "Database"
end

choice_answer :randomize => true do
text "An HTTP request must consist of both a(n) ----- and a(n) -----"
distractor "CRUD action, database"
distractor "header, cookie", :explanation => 'A header is part of the request, but a cookie is not necessarily included unless the server previously specified one.'
distractor "URL, wildcard", :explanation => 'A URL is necessary, but not a wildcard.'
answer "URI, HTTP request method", :explanation => "The URI alone isn't enough--the same URI used with two different methods can cause two different actions."
end
end
21 changes: 21 additions & 0 deletions features/upload.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Upload a RUql file
As an instructor
So that I can add questions
I want to upload a RUql file

Background:
Given I am signed in with uid "1234" and provider "github"
And I am on the upload page

Scenario: redirect to login page if not logged in
Given I am not logged in
And I am on the upload page
Then I should be on the login page

Scenario: upload a file successfully
Given I am on the upload page
And I attach the file "features/test_files/foo.txt" to "file_upload"
And I press the upload button
Then I should see "Success!"


1 change: 1 addition & 0 deletions saasquizes
Submodule saasquizes added at 38ec09

0 comments on commit c476074

Please sign in to comment.