Module: Saki::AcceptanceHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/saki.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_opts(link, opts = {}) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/saki.rb', line 149

def add_opts(link, opts = {})
  if opts[:parent]
    link = "/#{opts[:parent].class.to_s.tableize}/#{opts[:parent].id}" + link
  end
  if opts[:format]
    link = link + ".#{opts[:format]}"
  end
  link
end

#get_path(path) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'lib/saki.rb', line 139

def get_path(path)
  if path.is_a? String
    path
  elsif path.is_a? Symbol
    send path
  else
    path.call(self)
  end
end


159
160
161
162
163
164
165
166
167
# File 'lib/saki.rb', line 159

def has_link(href)
  begin
    page.should have_xpath("//a[@href='#{href}']")
  rescue
    onclick = "javascript: window.location='/pages/new';"
    page.should have_xpath(%{//button[@onclick="#{onclick}"]})
  end

end


169
170
171
172
# File 'lib/saki.rb', line 169

def has_link_for(model, opts = {})
  href = add_opts "/#{model.class.to_s.tableize}/#{model.id}", opts
  page.should have_xpath("//a[@href='#{href}' and not(@rel)]")
end


184
185
186
187
# File 'lib/saki.rb', line 184

def has_link_for_creating(model_type, opts = {})
  href = add_opts "/#{model_type.to_s.tableize}/new", opts
  has_link href
end


179
180
181
182
# File 'lib/saki.rb', line 179

def has_link_for_deleting(model, opts = {})
  href = add_opts "/#{model.class.to_s.tableize}/#{model.id}", opts
  page.should have_xpath("//a[@href='#{href}' and @data-method='delete']")
end


174
175
176
177
# File 'lib/saki.rb', line 174

def has_link_for_editing(model, opts = {})
  href = add_opts "/#{model.class.to_s.tableize}/#{model.id}/edit", opts
  has_link href
end


189
190
191
192
# File 'lib/saki.rb', line 189

def has_link_for_indexing(model_type, opts = {})
  href = add_opts "/#{model_type.to_s.tableize}", opts
  has_link href
end

#should_be_on(page_name) ⇒ Object



194
195
196
197
198
199
200
201
# File 'lib/saki.rb', line 194

def should_be_on(page_name)
  current_path = URI.parse(current_url).path
  if page_name.is_a? String
    current_path.should == page_name
  else
    current_path.should match(page_name)
  end
end