From a9843ae9968aab890090de9238ca41d0cee9d088 Mon Sep 17 00:00:00 2001 From: Jannik Streek Date: Thu, 27 Mar 2014 21:44:35 +0100 Subject: [PATCH] added cucumber tests, updated spec with xml class test --- .gitignore | 3 + app/models/poll_answer.rb | 2 +- features/desktop/post_with_a_poll.feature | 65 +++++++++++++++++++ .../step_definitions/post_with_poll_steps.rb | 32 +++++++++ spec/models/poll_participation_spec.rb | 4 ++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 features/desktop/post_with_a_poll.feature create mode 100644 features/step_definitions/post_with_poll_steps.rb diff --git a/.gitignore b/.gitignore index c1f6c385d..7d4f3c5ef 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,6 @@ dump.rdb #Rubinius's JIT *.rbc + +#IDE +diaspora.iml diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 8c8de154b..1fa9b8eeb 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -11,7 +11,7 @@ class PollAnswer < ActiveRecord::Base self.include_root_in_json = false def update_vote_counter - self.vote_count = self.vote_count + 1 + self.vote_count += 1 self.save! end diff --git a/features/desktop/post_with_a_poll.feature b/features/desktop/post_with_a_poll.feature new file mode 100644 index 000000000..5d8b7b277 --- /dev/null +++ b/features/desktop/post_with_a_poll.feature @@ -0,0 +1,65 @@ +@javascript +Feature: posting with a poll + + Background: + Given following users exist: + | username | + | bob | + And I sign in as "bob@bob.bob" + And I am on the home page + + Scenario: expanding the publisher + Given "#poll_creator_wrapper" is hidden + When I expand the publisher + Then I should see an element "#poll_creator" + + Scenario: expanding the poll creator + Given "#poll_creator_wrapper" is hidden + When I expand the publisher + And I press the element "#poll_creator" + Then I should see an element "#poll_creator_wrapper" + + Scenario: adding option to poll + Given "#poll_creator_wrapper" is hidden + When I expand the publisher + And I press the element "#poll_creator" + And I press the element "#add_poll_answer" + Then I should see 3 options + + Scenario: delete an option + Given "#poll_creator_wrapper" is hidden + When I expand the publisher + And I press the element "#poll_creator" + And I delete the first option + Then I should see 1 option + And I should not see a remove icon + + Scenario: post with an attached poll + Given I expand the publisher + And I press the element "#poll_creator" + When I fill in the following: + | status_message_fake_text | I am eating yogurt | + | poll_question | What kind of yogurt do you like? | + And I fill in the following for the options: + | normal | + | not normal | + And I press "Share" + Then I should see a ".poll_form" within ".stream_element" + And I should see a "form" within ".stream_element" + + Scenario: vote for an option + Given I expand the publisher + And I press the element "#poll_creator" + When I fill in the following: + | status_message_fake_text | I am eating yogurt | + | poll_question | What kind of yogurt do you like? | + And I fill in the following for the options: + | normal | + | not normal | + And I press "Share" + + And I check the first option + And I press "Vote" within ".stream_element" + Then I should see an element ".poll_progress_bar" + And I should see an element ".percentage" + And I should see "1 vote so far" within ".poll_statistic" \ No newline at end of file diff --git a/features/step_definitions/post_with_poll_steps.rb b/features/step_definitions/post_with_poll_steps.rb new file mode 100644 index 000000000..2ae5a78ba --- /dev/null +++ b/features/step_definitions/post_with_poll_steps.rb @@ -0,0 +1,32 @@ +Then /^I should see ([1-9]+) options?$/ do |number| + find("#poll_creator_wrapper").all(".poll_answer").count.should eql(number.to_i) +end + +And /^I delete the first option$/ do + find("#poll_creator_wrapper").all(".poll_answer .remove_poll_answer").first.click +end + +And /^I should not see a remove icon$/ do + page.should_not have_css(".remove_poll_answer") +end + +When /^I fill in the following for the options:$/ do |table| + i = 0 + table.raw.flatten.each do |value| + all(".poll_answer_input")[i].set(value) + i+=1 + end +end + +When /^I check the first option$/ do + sleep 1 + first(".poll_form input").click +end + +And /^I press the element "([^"]*)"$/ do |selector| + find(selector).click +end + +Then /^I should see an element "([^"]*)"$/ do |selector| + page.should have_css(selector) +end \ No newline at end of file diff --git a/spec/models/poll_participation_spec.rb b/spec/models/poll_participation_spec.rb index 951d14144..13a9e0f63 100644 --- a/spec/models/poll_participation_spec.rb +++ b/spec/models/poll_participation_spec.rb @@ -43,6 +43,10 @@ describe PollParticipation do @xml = @poll_participation.to_xml.to_s end + it 'serializes the class name' do + @xml.include?(PollParticipation.name.underscore.to_s).should be_true + end + it 'serializes the sender handle' do @xml.include?(@poll_participation.diaspora_handle).should be_true end