Skip to content

Commit

Permalink
Added design controller and icon model. Fixed BDD infrastucture
Browse files Browse the repository at this point in the history
  • Loading branch information
pepe committed Aug 4, 2010
1 parent 3f7035d commit db413f6
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
@@ -0,0 +1,2 @@
---
BUNDLE_WITHOUT: ""
51 changes: 50 additions & 1 deletion app/controllers/design.rb
@@ -1,4 +1,53 @@
PadMeTee.controllers :design do
configure do
Compass.configuration do |config|
config.project_path = File.dirname(__FILE__)
config.sass_dir = File.join 'views', 'stylesheets'
end

set :haml, { :format => :html5 }
set :sass, Compass.sass_engine_options
end

before do
session['gender'] ||= 'male'
end

get :index, :map => '/' do
render 'design/index'
end

get :female, :map => '/female' do
session['gender'] = 'female'
@message = I18n.t('tshirt.chosen_gender') % I18n.t('gender.female')
render 'design/index'
end

get :male, :map => '/male' do
session['gender'] = 'male'
@message = I18n.t('tshirt.chosen_gender') % I18n.t('gender.male')
render 'design/index'
end

get :icons, :map => '/icons/:id' do
@icon = Icon.find(params[:id])
session[@icon.type] = @icon
if request.xhr?
status 204
else
render 'design/index'
end
end

get :save, :map => '/save' do
end

#TODO move to static controller
get :stylesheets, :map => '/stylesheets/:name.css' do
content_type 'text/css', :charset => 'utf-8'
sass(:"stylesheets/#{params[:name]}", Compass.sass_engine_options )
end

# get :index, :map => "/foo/bar" do
# session[:foo] = "bar"
# render 'index'
Expand All @@ -19,4 +68,4 @@
# end


end
end
26 changes: 22 additions & 4 deletions app/helpers/design_helper.rb
@@ -1,7 +1,25 @@
# Helper methods defined here can be accessed in any controller or view in the application

PadMeTee.helpers do
# def simple_helper_method
# ...
# end
end
# prints size option with selected if in session
def option_for(size)
res = '<option'
res += session['size'] == size ? ' selected="selected">' : '>'
res += (size + '</option>')
end

# returns chosen icon image
def chosen_icon_image(type, size = '')
if icon = session[type] || (@order && @order.document[type])
'<img src="/icons/%s/%s.gif" alt="%s" width="%s" height="%s" />' % [type, icon, icon, size, size]
else
"<span></span>"
end
end

# renders img tag for icon thumb for carousel
def icon_image_thumb(icon)
"<a href='/icons/%s' title='%s'><img src='%s' width='72' height='72' class='hidden' /></a>" % [icon.id, icon.full_name, icon.path]
end
j
end
24 changes: 24 additions & 0 deletions app/models/icon.rb
@@ -0,0 +1,24 @@
class Icon
include Mongoid::Document
include Mongoid::Timestamps # adds created_at and updated_at fields

field :name
field :filename
field :type

key :type, :name

scope :hobbies, where(:type => 'hobby')
scope :faces, where(:type => 'face')
scope :jobs, where(:type => 'job')

# returns path for web printing
def path
@path ||= "/icons/#{filename}"
end

# returns full name with type
def full_name
@full_name ||= "%s %s" % [type, name]
end
end
1 change: 1 addition & 0 deletions autotest/discover.rb
@@ -0,0 +1 @@
Autotest.add_discovery { "rspec2" }
17 changes: 17 additions & 0 deletions features/change_gender.feature
@@ -0,0 +1,17 @@
Feature: Genre changing
In order to change t-shirt gender for male or female
As a customer
I need link to do it and see result

Scenario: Changing to male t-shirt
Given I visit '/'
When I follow 'male'
Then I should see 'me-tee t-shirt about you'
Then I should see 'You chose male tee'

Scenario: Changing to female t-shirt
Given I visit '/'
When I follow 'female'
Then I should see 'me-tee t-shirt about you'
Then I should see 'You chose female tee'

41 changes: 41 additions & 0 deletions features/home_page.feature
@@ -0,0 +1,41 @@
Feature: Home page
In order to have start somewhere and configure t-shirt
As a customer
I need home page

Scenario: Visiting home page
Given I visit '/'
Then I should see 'me-tee t-shirt about you'

Scenario: Checking t-shirt configuration
Given I visit '/'
Then I should see 'male'
Then I should see 'female'
Then I should see 'save'
Then I should see 'random'

Scenario: Choosing size
Given I visit '/'
Then I could select 'S' from 'size'
Then I could select 'M' from 'size'
Then I could select 'L' from 'size'
Then I could select 'XL' from 'size'
Then I could select 'XXL' from 'size'

Scenario: Changing gender
Given I visit '/'
Then I could follow 'male'
Given I visit '/'
Then I could follow 'female'

Scenario: Saving design
Given I visit '/'
Then I could follow 'save'

Scenario: Randomizing design
Given I visit '/'
Then I could follow 'random'

Scenario: Order
Given I visit '/'
Then I could press 'order'
15 changes: 15 additions & 0 deletions features/save_design.feature
@@ -0,0 +1,15 @@
Feature: Saving of design
In order to have design saved for tomorrows
As a customer
I want to save current design

Background:
Given there are icons in system

Scenario: Saving t-shirt design
Given I visit '/'
And I follow 'face angry'
And I follow 'hobby swim'
And I follow 'job cook'
When I follow 'save'
Then I should see 'Tee how you design it'
138 changes: 138 additions & 0 deletions features/step_definitions/page_visit_steps.rb
@@ -0,0 +1,138 @@
Given /^I visit '(.+)'$/ do |url|
visit(url)
end

Then /^I should see '(.+)'$/ do |text|
page.should have_content(text)
end

Then /^I should not see '(.+)'$/ do |text|
response_body.should_not contain(Regexp.new(text, Regexp::MULTILINE))
end

Then /^I should see big '(.+)'$/ do |text|
text = '<h1>[\s]*%s[\s]*<\/h1>' % text
response_body.should =~ Regexp.new(text)
end

Then /^I fill in '(.*)' for '(.*)'$/ do |value, field|
fill_in(field, :with => value)
end

When /^I press '(.*)'$/ do |name|
click_button(name)
end

Then /^I could press '(.*)'$/ do |name|
Then "I press '#{name}'"
end

Then /^I choose '(.*)'$/ do |value|
choose(value.gsub(/ /, ''))
end

Given /^I will get mail$/ do
Pony.should_receive(:mail)
end

Then /^I follow '(.+)'$/ do |link|
click_link link
end

Then /^I could follow '(.+)'$/ do |link|
Then "I follow '#{link}'"
end

When /^I select '(.+)' from '(.+)'$/ do |value, field|
select(value, :from => field)
end

Then /^I could select '(.+)' from '(.+)'$/ do |value, field|
When "I select '#{value}' from '#{field}'"
end

Then /^I should see '([^']+)' icon '([^']+)'$/ do |type, name|
response_body.should have_selector('img', :src => "/icons/#{type}/#{name}.gif")
end

Then /^I should see not '([^']+)' icon '([^']+)'$/ do |type, name|
response_body.should_not have_selector('img', :src => "/icons/#{type}/#{name}.gif")
end

Then /^I should see choosed icon '([^']+)' in '([^']+)'$/ do |name, type|
response_body.should have_selector('div', :class => 'placeholder', :id => "#{type}-placeholder") do |node|
node.first.inner_html.should =~ /#{name}/
end
end

Then /^I should see '([^']+)' placeholder$/ do |type|
response_body.should have_selector('div', :class => 'placeholder', :id => "#{type}-placeholder")
end

Given /^I choose size '([^']+)'$/ do |size|
visit '/' + size
end

Then /^I should see choosed '([^']+)'$/ do |size|
response_body.should have_selector('option', :selected => 'selected', :content => size)
end

Given /^I know customer '([^']+)' ordered tee as usual$/ do |customer|
Given "I ordered tee as usual as customer '#{customer}'"
end

Given /^I ordered tee as usual as customer '([^']+)'$/ do |customer|
Given "I designed a tee"
And "I press 'objednat'"
Given "I fill in '#{customer}' for 'name'"
And "I fill in 'Pool 1' for 'street'"
And "I fill in 'Prague' for 'city'"
And "I fill in '11150' for 'zip'"
And "I fill in 'joe@doe.cz' for 'email'"
And "I fill in '420777888999' for 'phone'"
And "I fill in 'will come again' for 'note'"
And "I fill in 'METEE2010' for 'coupon'"
Then "I press 'Pokračovat v objednávce'"
When "I follow 'DOKONČIT OBJEDNÁVKU'"
end

Then /^I should see '([^']+)' prefilled in '([^']+)'$/ do |content, id|
response_body.should have_selector('input', :id => id, :value => content)
end

Given /^I left session$/ do
last_request.session[:order] = nil
end

Then /^mail should be sent to my address '(.+)'$/ do |email|
Mail.deliveries.size.should == 1
Mail.deliveries.first.to.value == /#{email}/
end

Given /^I am using ajax$/ do
header 'X-Requested-With', 'XMLHttpRequest'
end

Given /^I designed a tee$/ do
Given "I visit '/'"
And "I visit '/faces/angry'"
And "I visit '/hobbies/swim'"
And "I visit '/jobs/cook'"
And "I visit '/male'"
end

Then /^I should see startup link$/ do
response_body.should have_selector('a', :id => "startup")
end

Then /^I should not see startup link$/ do
response_body.should_not have_selector('a', :id => "startup")
end

Given /^there are icons in system$/ do
Icon.destroy_all
Icon.create(:type => 'hobby', :name => 'swim', :filename => 'swim.gif')
Icon.create(:type => 'face', :name => 'angry', :filename => 'angry.gif')
Icon.create(:type => 'job', :name => 'cook', :filename => 'cook.gif')
end

7 changes: 2 additions & 5 deletions features/support/env.rb
Expand Up @@ -2,9 +2,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../../config/boot")

require 'capybara/cucumber'
require 'spec/expectations'
require 'rspec/expectations'

##
# You can handle all padrino applications using instead:
# Padrino.application
Capybara.app = PadMeTee.tap { |app| }
Capybara.app = Padrino.application

0 comments on commit db413f6

Please sign in to comment.