Skip to content

Commit

Permalink
More refactoring to use component models
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Waite committed Feb 26, 2012
1 parent 17932d5 commit 6088da7
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 31 deletions.
6 changes: 4 additions & 2 deletions features/support/component/base.rb
@@ -1,7 +1,9 @@
module Component
class Base
def initialize(root)
@root = root
def initialize(selector)
if Capybara.current_session.has_css?(selector)
@root = Capybara.current_session.find(selector)
end
end

def present?
Expand Down
4 changes: 4 additions & 0 deletions features/support/component/featured_submission.rb
Expand Up @@ -11,5 +11,9 @@ def submissions_count
def author_name
root.find(".author-name").text
end

def voted_on?
root.has_css?('.all-voted-on')
end
end
end
42 changes: 42 additions & 0 deletions features/support/component/submission_list_item.rb
@@ -0,0 +1,42 @@
module Component
class SubmissionListItem < Component::Base

def initialize(root)
@root = root
end

def name
root.find('.name').text
end

def plus_votes
root.find('.plus .value').text.to_i
end

def minus_votes
root.find('.minus .value').text.to_i
end

def author_name
root.find('.author-name').text
end

def buttons
r = {}
root.all('input').each do |input|
r[input['value']] = input
end
r
end

def has_vote_button?
root.has_css?("input[value='Vote']")
end

def vote_review
sel = '.vote-review'
root.find(sel).text.strip if root.has_css?(sel)
end

end
end
22 changes: 22 additions & 0 deletions features/support/component/submissions_list.rb
Expand Up @@ -3,5 +3,27 @@ class SubmissionsList < Component::Base
def submissions_count
root.all('li').size
end

def names
root.all('.name').collect(&:text)
end

def submissions
r = {}
root.all('li').each do |li|
sli = SubmissionListItem.new(li)
name = sli.name
r[name] = {
:plus_votes => sli.plus_votes,
:minus_votes => sli.minus_votes,
:vote_review => sli.vote_review,
:author_name => sli.author_name,
:has_vote_button => sli.has_vote_button?,
:buttons => sli.buttons
}
end
r
end

end
end
2 changes: 1 addition & 1 deletion features/support/page/series/index.rb
Expand Up @@ -21,7 +21,7 @@ def series_list_contents
private

def series_list
@series_list = Component::SeriesList.new(find('#series'))
@series_list = Component::SeriesList.new('#series')
end

end
Expand Down
41 changes: 13 additions & 28 deletions features/support/page/series/show.rb
Expand Up @@ -11,62 +11,55 @@ def new_submission
end

def has_featured_submission?
has_css?(featured_submission_sel)
featured_submission.present?
end

def feature_submission_name
featured_submission.name
end

def has_all_voted_on_message?
has_css?('.all-voted-on')
featured_submission.voted_on?
end

def click_button_for_submission(button_label, submission_name)
submission = ::Submission.find_by_name(submission_name)
session.within(submission_sel(submission)) do
session.click_button button_label
end
submissions_list.submissions[submission_name][:buttons][button_label].click
end

def vote_buttons
all('input[value="Vote"]')
end

def vote_review_text(submission)
find("#{submission_sel(submission)} .vote-review").text.strip
submissions_list.submissions[submission.name][:vote_review]
end

def plus_vote_count(submission)
session.within(submission_sel(submission)) do
find('.plus .value').text.to_i
end
submissions_list.submissions[submission.name][:plus_votes]
end

def minus_vote_count(submission)
session.within(submission_sel(submission)) do
find('.minus .value').text.to_i
end
submissions_list.submissions[submission.name][:minus_votes]
end

def has_vote_review?(submission)
has_css?("#{submission_sel(submission)} .vote-review")
!submissions_list.submissions[submission.name][:vote_review].nil?
end

def has_vote_button?(submission)
has_css?("#{submission_sel(submission)} input[value='Vote']")
submissions_list.submissions[submission.name][:has_vote_button]
end

def submissions_count
submissions_list.submissions_count
end

def submission_author_email(submission)
find("#{submission_sel(submission)} .author-name").text
submissions_list.submissions[submission.name][:author_name]
end

def submission_names
all('#submissions .name').collect(&:text)
submissions_list.names
end

def follow_new_submission
Expand All @@ -80,25 +73,17 @@ def vote_on_submission(submission, position)
end

def has_submissions?
@submissions_list.present?
submissions_list.present?
end

private

def submission_sel(submission)
"#submission-#{submission.id}"
end

def featured_submission_sel
'#featured-submission'
end

def featured_submission
@featured_submission ||= Component::FeaturedSubmission.new(find(featured_submission_sel))
@featured_submission ||= Component::FeaturedSubmission.new('#featured-submission')
end

def submissions_list
@submissions_list ||= Component::SubmissionsList.new(find('#submissions'))
@submissions_list ||= Component::SubmissionsList.new('#submissions')
end

end
Expand Down

0 comments on commit 6088da7

Please sign in to comment.