Class: ActiveSupport::TestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/flot/rails/plus/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#fetch_flot_callback_urlObject

call after requesting a readings page to extract gon.url



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flot/rails/plus/test_helper.rb', line 36

def fetch_flot_callback_url
  url = nil
  assert_select "script", /gon\.url=/ do |element|
    # get the tag as a string
    string = element.to_s
    # select the gon.url string as $1
    string =~ /gon\.url=\"(.*?)\"/
    url = $1
  end
  url
end

#fetch_flot_chart_by_div(div) ⇒ Object

call after requesting a page to extract the chart for a given div nil if not found



29
30
31
32
33
# File 'lib/flot/rails/plus/test_helper.rb', line 29

def fetch_flot_chart_by_div( div )
  charts = fetch_flot_charts  # fetch all charts from all sets
  charts_for_div = charts.select { |c| c["div"] == div }
  charts_for_div.empty?  ?  nil  :  charts_for_div[0]
end

#fetch_flot_chart_setsObject

call after requesting a page to extract gon.chart_sets as an array of ChartSets where each ChartSet is a hash



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/flot/rails/plus/test_helper.rb', line 5

def fetch_flot_chart_sets
  chart_sets = nil
  assert_select "script", /gon\.chart_sets=/ do |element|
    # get the tag as a string
    string = element.to_s
    # select the gon.chart_sets string as $1
    string =~ /gon\.chart_sets=(.*\}\]);/
    # parse it as json
    chart_sets = JSON.parse $1
    # this should be an array of chart set hashes
  end
  chart_sets
end

#fetch_flot_chartsObject

returns all charts from all sets



20
21
22
23
24
25
# File 'lib/flot/rails/plus/test_helper.rb', line 20

def fetch_flot_charts
  chart_sets = fetch_flot_chart_sets
  charts = []
  chart_sets.each {|s| charts += s["charts"]}
  charts
end

#fetch_flot_refreshObject

call after requesting a readings page to extract gon.refresh



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/flot/rails/plus/test_helper.rb', line 49

def fetch_flot_refresh
  refresh = nil
  assert_select "script", /gon\.refresh=/ do |element|
    # get the tag as a string
    string = element.to_s
    # select the gon.refresh string as $1
    string =~ /gon\.refresh=(.*?);/
    refresh = $1
  end
  refresh
end