Created
August 2, 2014 07:58
-
-
Save rocknrollMarc/9630e14cb22c2f7a12fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Feature | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include Mongoid::Attributes::Dynamic | |
field :filename, type: String | |
field :title, type: String | |
field :description, type: String | |
field :tags, type: String | |
# This is a sub-document embedded in the project | |
embedded_in :project | |
embeds_many :scenarios | |
accepts_nested_attributes_for :scenarios, cascade_callbacks: true, :allow_destroy => true | |
### Functions for various things that the workers need to do | |
def self.updateScenarios(project_id, feature_id) | |
# Get the project and feature | |
@project = Project.find(project_id) | |
@feature = @project.features.find(feature_id) | |
content = File.open(@feature.filename).read() | |
puts content | |
temp_matches = content.scan(/Scenario:(.*)\n/) | |
unless temp_matches | |
puts "No Scenarios found" | |
end | |
puts temp_matches.inspect | |
temp_matches.each do |each_string| | |
puts each_string[0] | |
new_scenario_data = Scenario.new | |
new_scenario_data.title = each_string[0] | |
# TODO: Get the tags from each scenario | |
# field :tags, type: String | |
if(@feature.scenarios.where(:title => each_string[0]).exists?) | |
puts @feature.scenarios.where(:title => each_string[0]).first.inspect | |
# TODO: just update the tags and whatever else is here | |
#temp = @feature.scenarios.find_by(:title => each_string) | |
else | |
#this is a new feature file, so append it to the array | |
@feature.scenarios << new_scenario_data | |
end | |
# OPTIMIZE This should be using a recurring JSON to then replace the entire tree instead of the mongo updates | |
Scenario.updateSteps(project_id, feature_id, @feature.scenarios.where(:title => each_string[0]).first['_id'] ) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment