Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved helpers into their own files and linked them appropriately to t…
…he env file.
- Loading branch information
Showing
3 changed files
with
54 additions
and
54 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module AssociationsHelper | ||
|
||
def build_associations_by_amount amount, model, assoc | ||
amount = amount.to_i | ||
amount.times { eval("@#{model}.#{assoc.pluralize}") << assoc.capitalize.singularize.constantize.make } unless assoc.empty? | ||
end | ||
|
||
def build_model_associations_more_than amount, model | ||
number = amount.to_i + 1 | ||
current_model = eval("@#{model}") | ||
number.times { current_model.send(association.pluralize.to_sym) << association.singularize.capitalize.constantize.make } | ||
end | ||
|
||
def build_model_by_amount amount, model | ||
models = [] | ||
amount.times { models << model.capitalize.singularize.constantize.make } | ||
model.capitalize.singularize.constantize.stub!(:all).and_return models | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module FormsHelper | ||
def fill_form(form_name, opts = {}) | ||
values = {} | ||
case form_name | ||
when /feature/ | ||
values = {"title" => Sham.feature, "in_order" => 'to create the best app', "as_a" => 'user', "i_want" => 'the best project ever'} | ||
when /project/ | ||
values = {"title" => Sham.title, "aim" => 'An aim', "description" => 'A description', "location" => "#{RAILS_ROOT}"} | ||
when /story/ | ||
values = {"scenario" => Sham.scenario } | ||
when /step/ | ||
values = {"title" => Sham.step } | ||
when /resource/ | ||
values = {"name" => "baphled", "project" => "50164"} | ||
else | ||
raise "Can't find the form #{form_name}.\n" + | ||
"Now, go and add a mapping in #{__FILE__}" | ||
end | ||
|
||
parmas = values.merge(opts) | ||
parmas.each { |param, value| When %{we fill in the #{form_name} #{param} with '#{value}'} } | ||
end | ||
|
||
def fill_in_form_with_duplicate_data form_name | ||
model = form_name.capitalize.constantize.make | ||
opts = model.attributes | ||
unsubmitables = ['created_at', 'updated_at', 'path'] | ||
model.attributes.each { |key, attribute| unsubmitables << key if not key.match(/id$/).nil? } | ||
unsubmitables.each { |param| opts.delete param } | ||
fill_form form_name.singularize, opts | ||
end | ||
end |