Skip to content

Commit

Permalink
Merge pull request #89 from AaronLindsayDaisy/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
aaronwiggins committed Aug 9, 2015
2 parents 45d3ea2 + e7deae7 commit 24d0771
Show file tree
Hide file tree
Showing 15 changed files with 5,370 additions and 212 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $(function() {
});
});

// order function

$(function() {
$('.order').change(function(){
var selectValue = $(this).val();
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ def show

def concept_tree
@concepts = Concept.all
# @tree = Concept.first.display_concepts
# render json: @tree
end

def new
Expand Down
17 changes: 10 additions & 7 deletions app/controllers/experiments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def landing_page

def index
if params[:query]
@experiments = Experiment.text_search(params[:query])
@experiments = Experiment.text_search(params[:query]).all.by_votes
if @experiments.length == 0
flash.now[:notice] = "No items found"
end
Expand All @@ -20,21 +20,24 @@ def index
end

def order_experiments
if params[:selectValue] == "1"
@sorted_experiments = Experiment.all.sort_by {|e| [e.age, -1*e.experiment_votes.count]}
elsif params[:selectValue] == "2"
@sorted_experiments = Experiment.all.sort_by {|e| [e.complete_time, -1*e.experiment_votes.count]}
if params[:queryValue] && params[:selectValue] == "1"
@experiments = Experiment.text_search(params[:queryValue]).all.sort_by {|e| [e.age, -1*e.experiment_votes.count]}
elsif params[:queryValue] && params[:selectValue] == "2"
@experiments = Experiment.text_search(params[:queryValue]).all.sort_by {|e| [e.complete_time, -1*e.experiment_votes.count]}
end
end

# end

# GET /experiments/1
# GET /experiments/1.json
def show
@parents = @experiment.concept_parents
@children = @experiment.concept_children
@concept = @experiment.find_concept
@first_experiment = Experiment.first_experiment(@concept, @experiment)[1]
@first_concept = Experiment.first_experiment(@concept, @experiment)[0]
@second_experiment = Experiment.second_experiment(@concept, @experiment)[1]
@second_concept = Experiment.second_experiment(@concept, @experiment)[0]

@comment = Comment.new
if Experiment.by_votes[0] != @experiment
@top_experiment = Experiment.by_votes[0]
Expand Down
36 changes: 34 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 Expand Up @@ -85,4 +85,36 @@ def find_concept
self.concepts.sample
end

def self.first_experiment(concept, experiment) #show recommended
concept_experiment = []
if experiment.concepts.count == 1 && concept.experiments.count == 1
if Experiment.by_votes[0] != experiment
top_experiment = Experiment.by_votes[0]
else
top_experiment = Experiment.by_votes[1]
end
concept_experiment << top_experiment.concepts.sample << top_experiment
elsif concept.experiments.where.not(name: experiment.name).blank? #if current concept doesn't have any more experiments, do this
concept = experiment.concepts.where.not(name: concept.name).sample #look for other concepts for the current experiment
experiment = concept.experiments.where.not(name: experiment.name).sample
concept_experiment << concept << experiment
else
# Another Experiment about concept.name
experiment = concept.experiments.where.not(name: experiment.name).sample
concept_experiment << concept << experiment
end
end

def self.second_experiment(concept, experiment) #show extended learning
concept_experiment = []
if concept.children.count > 0
random_child = concept.children.sample
random_child_experiment = random_child.experiments.sample
concept_experiment << random_child << random_child_experiment
else #work on your fundamenetals
random_parent = concept.parents.sample
random_parent_experiment = random_parent.experiments.sample
concept_experiment << random_parent << random_parent_experiment
end
end
end
5 changes: 2 additions & 3 deletions app/views/experiments/_experiments.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

<div class="index-wrapper">
<% @experiments.each do |experiment| %>
<% @experiments.each do |experiment| %>

<div class="index-experiment-card">
<% if experiment.uploaded_file.blank? %>
Expand All @@ -26,7 +26,6 @@
<a href="<%= url_for experiment %>" class="index-photo" style="background-image: url('<%= experiment.uploaded_file %>')">
<% end %>
<span class="index-exp-title-bar"><h3 class="index-exp-title"><%= experiment.name %></h3>

<i class="fa fa-thumbs-up index-likes"> <%= pluralize experiment.votes, "like" %></i>
</span>
</a>
Expand Down Expand Up @@ -58,6 +57,6 @@
</div>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/experiments/order_experiments.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$(".index-wrapper").replaceWith("<%= j(render partial: 'experiments/order_experiments', locals: { experiments: @sorted_experiments }) %>");
$(".index-wrapper").replaceWith("<%= j(render partial: 'experiments/ordered_experiments', locals: { experiments: @experiments }) %>");
initStars();
Loading

0 comments on commit 24d0771

Please sign in to comment.