Module: Saki::RestfulPathwayHelpers
- Defined in:
- lib/saki.rb
Instance Method Summary collapse
- #create(item_name) ⇒ Object
- #factory(name, hash = {}) ⇒ Object
- #factory_build(name, hash = {}) ⇒ Object
- #has_index_link_list(item, opts = {}) ⇒ Object
- #has_show_link_list(item, opts = {}) ⇒ Object
- #lets_me_create_the(item_name) ⇒ Object
- #lets_me_edit_the(item_name) ⇒ Object
- #refetch(item_name) ⇒ Object
- #shows_failure_on_invalid_create ⇒ Object
- #shows_failure_on_invalid_update_of(model) ⇒ Object
- #shows_in_list(resource, attrs = nil) ⇒ Object
Instance Method Details
#create(item_name) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/saki.rb', line 60 def create(item_name) eval %{ @#{item_name} = factory_build :#{item_name} if respond_to? :before_#{item_name}_create before_#{item_name}_create end fill_in_#{item_name}_details click_button "Create" } end |
#factory(name, hash = {}) ⇒ Object
93 94 95 |
# File 'lib/saki.rb', line 93 def factory(name, hash = {}) Factory name, hash end |
#factory_build(name, hash = {}) ⇒ Object
89 90 91 |
# File 'lib/saki.rb', line 89 def factory_build(name, hash = {}) Factory.build name, hash end |
#has_index_link_list(item, opts = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/saki.rb', line 20 def has_index_link_list(item, opts = {}) has_link_for item, opts has_link_for_editing item, opts has_link_for_deleting item, opts has_link_for_creating item.class.to_s.tableize.singularize, opts end |
#has_show_link_list(item, opts = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/saki.rb', line 27 def has_show_link_list(item, opts = {}) has_link_for_editing item, opts has_link_for_deleting item, opts has_link_for_indexing item.class.to_s.tableize.singularize, opts end |
#lets_me_create_the(item_name) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/saki.rb', line 73 def lets_me_create_the(item_name) eval %{ create(:#{item_name}) refetch(item_name) if respond_to? :after_#{item_name}_create after_#{item_name}_create end has_#{item_name}_details has_show_link_list(@#{item_name}) } end |
#lets_me_edit_the(item_name) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/saki.rb', line 50 def lets_me_edit_the(item_name) eval %{ @#{item_name} = factory_build item_name fill_in_#{item_name}_details click_button "Update" refetch(item_name) has_#{item_name}_details } end |
#refetch(item_name) ⇒ Object
85 86 87 |
# File 'lib/saki.rb', line 85 def refetch(item_name) eval "@#{item_name} = respond_to?(:refetch_#{item_name}_func) ? refetch_#{item_name}_func : @#{item_name}.class.where(:name => @#{item_name}.name).first" end |
#shows_failure_on_invalid_create ⇒ Object
44 45 46 47 48 |
# File 'lib/saki.rb', line 44 def shows_failure_on_invalid_create "Create" page.should have_xpath("//input[@type='submit' and starts-with(@value, 'Create')]") page.should have_content("error") end |
#shows_failure_on_invalid_update_of(model) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/saki.rb', line 33 def shows_failure_on_invalid_update_of(model) if respond_to?("invalidate_#{model}_form") send("invalidate_#{model}_form") else fill_in "#{model}[name]", :with => "" end "Update" page.should have_xpath("//input[@type='submit' and starts-with(@value, 'Update')]") page.should have_content("error") end |
#shows_in_list(resource, attrs = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/saki.rb', line 5 def shows_in_list(resource, attrs = nil) visit "/#{resource.to_s.pluralize}" resource_instance = eval "@#{resource}" if attrs attrs.each do |attr| page.should have_content(resource_instance.send(attr)) end elsif respond_to?("displays_#{resource}") send "displays_#{resource}" else page.should have_content(resource_instance.name) end has_index_link_list(resource_instance) end |