Skip to content

Commit

Permalink
try to get tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronwiggins committed Aug 3, 2015
1 parent f240e58 commit ff65128
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/models/experiment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Experiment < ActiveRecord::Base
has_attached_file :uploaded_file

validates_attachment_content_type :uploaded_file, :content_type => ['image/jpeg', 'image/png', 'image/pdf']
# validates :uploaded_file, presence: true

has_many :comments, as: :commentable

Expand All @@ -24,7 +23,8 @@ class Experiment < ActiveRecord::Base
reject_if: :all_blank,
allow_destroy: true

validates :description, :complete_time, :name, presence: true
validates :description, :complete_time, :name, :age, presence: true

validates_format_of :youtube_link,
:allow_blank => true,
:with => /\A(?:https?:\/\/)?(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=)?([\w-]{10,})\z/,
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions test/controllers/concepts_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'test_helper'

class ConceptsControllerTest < ActionController::TestCase
setup do
sign_in users(:one)
end

test "should get index" do
get :index
assert_response :success
Expand Down
16 changes: 13 additions & 3 deletions test/controllers/experiments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
class ExperimentsControllerTest < ActionController::TestCase
setup do
sign_in users(:one)
@user = users(:one)
@experiment = experiments(:one)
@experiments = Experiment.all
@material = materials(:one)
@instruction = instructions(:one)
end

test "should get index" do
Expand All @@ -20,7 +23,12 @@ class ExperimentsControllerTest < ActionController::TestCase

test "should create experiment" do
assert_difference('Experiment.count') do
post :create, experiment: { id: @experiment, complete_time: @experiment.complete_time, description: @experiment.description, user_id: @experiment.user_id, youtube_link: @experiment.youtube_link }
post :create, experiment: { name: @experiment.name, complete_time: @experiment.complete_time,
description: @experiment.description, age: @experiment.age, user_id: @experiment.user_id,
materials_attributes: {"0" => { experiment_id: @experiment.id, item: @material.item } },
instructions_attributes: {"0" => { experiment_id: @experiment.id, information: @instruction.information,
order_number: @instruction.order_number } }
}
end

assert_redirected_to experiment_path(assigns(:experiment))
Expand All @@ -37,8 +45,10 @@ class ExperimentsControllerTest < ActionController::TestCase
end

test "should update experiment" do
patch :update, id: @experiment, experiment: { complete_time: @experiment.complete_time, description: @experiment.description, user_id: @experiment.user_id, youtube_link: @experiment.youtube_link }
assert_redirected_to experiment_path(assigns(:experiment))
patch :update, id: @experiment, experiment: { complete_time: @experiment.complete_time,
description: @experiment.description, user_id: @experiment.user_id,
youtube_link: @experiment.youtube_link }
assert_redirected_to experiment_path(asigns(:experiment))
end

test "should destroy experiment" do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/materials_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MaterialsControllerTest < ActionController::TestCase
end

test "should get index" do
get :index
get :index, experiment_id: @experiment
assert_response :success
assert_not_nil assigns(:materials)
end
Expand Down
11 changes: 7 additions & 4 deletions test/fixtures/experiments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
one:
user_id: 1
description: MyText
youtube_link: MyText
complete_time: 1.5
complete_time: 1
age: 1
uploaded_file_file_name: "image.jpg"
user: :one

two:
user_id: 1
description: MyText
youtube_link: MyText
complete_time: 1.5
complete_time: 1
age: 2
uploaded_file_file_name: "image.jpg"

0 comments on commit ff65128

Please sign in to comment.