Skip to content

Commit

Permalink
References #144 - Added sample upload file, a migration to add the `i…
Browse files Browse the repository at this point in the history
…mage_value` column type, and other supporting things to allow users to create `image` column types.
  • Loading branch information
jefflunt committed Oct 13, 2012
1 parent 585d8d2 commit 8fa76ae
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/helpers/world_object_property_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def auto_field_for(form_builder, world_object_property)
case world_object_property.section_property.data_type
when 'integer'
return form_builder.text_field :integer_value
when 'image'
return form_builder.file_field :image_value
when 'boolean'
return form_builder.check_box :boolean_value
when 'string'
Expand Down
2 changes: 1 addition & 1 deletion app/models/section_property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def archived?
end

def self.all_data_types
['boolean', 'integer', 'string', 'text']
['boolean', 'image', 'integer', 'string', 'text']
end

def is_public?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddImageValueColumnToWorldObjectProperties < ActiveRecord::Migration
def change
add_column :world_object_properties, :image_value, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120728154134) do
ActiveRecord::Schema.define(:version => 20121013165520) do

create_table "log_books", :force => true do |t|
t.integer "user_id", :null => false
Expand Down Expand Up @@ -63,6 +63,7 @@
t.text "text_value"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image_value"
end

create_table "world_objects", :force => true do |t|
Expand Down
28 changes: 28 additions & 0 deletions features/image_uploads.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Uploading images and images as a LogBook column type

Background:
Given I am signed in with provider "facebook"
And a LogBook exists called "Logbook with images" for game "City image game" and owned by "facebook_user"
And a Section exists called "All city images" in "Logbook with images"

Scenario: When editing a Section, the image column type should be an option, and you can create a new column of type image
When I go to the edit Section page for Section "All city images"
And I fill in "section_properties[new_section_property_names]" with "Image"
And I select "image" from "[data_type]"
And I press "Update attributes"
Then I should see all of the texts:
| Section updated |
| Section Attributes |
And I should see an "input" with "value" of "Image"

Scenario: A user can upload an image to a WorldObject that they own which contains an image property
When I go to the new WorldObjects page of Section "All city images"
Then I should see the text "Image"

Given I add the file "features/sample_uploads/city-cinemascope.jpg"
When I fill in the name field with "Picture of my dog"
And I fill in the file field "some file field"
And I press "Save"
Then I should see the text "Updated"
And there should be an image uploaded to WorldObject "Picture of my dog"

Binary file added features/sample_uploads/city-cinemascope.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
fill_in(field, :with => value)
end

When /^I select "(.*)" from "(.*)"$/ do |value, field_name|
select(value, :from => field_name)
end

Then /^I should see the text "([^"]*)"$/ do |text|
page.should have_content(text)
end
Expand Down Expand Up @@ -65,11 +69,11 @@
page.should have_xpath("//a[@href='#{href_destination}']")
end

Then /^I should see a "([^"]*)" tag around the text "([^"]*)"$/ do |tag_name, text|
Then /^I should see an? "([^"]*)" tag around the text "([^"]*)"$/ do |tag_name, text|
page.should have_xpath("//#{tag_name}[text()=\"#{text}\"]")
end

Then /^I should see a "([^"]*)" with "([^"]*)" of "([^"]*)"$/ do |tag_name, attribute_name, attribute_value|
Then /^I should see an? "([^"]*)" with "([^"]*)" of "([^"]*)"$/ do |tag_name, attribute_name, attribute_value|
page.should have_xpath("//#{tag_name}[@#{attribute_name}=\"#{attribute_value}\"]")
end

Expand Down
2 changes: 2 additions & 0 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def path_to(page_name)
when /the edit LogBook page for "([^\"]*)"/
log_book = LogBook.find_by_title($1)
edit_log_book_path(log_book)
when /the edit Section page for Section "([^\"]*)"/
edit_section_path(Section.find_by_name($1))
when /the edit page for the first section in LogBook "([^\"]*)"/
log_book = LogBook.find_by_title($1)
edit_section_path(log_book.sections.first)
Expand Down

0 comments on commit 8fa76ae

Please sign in to comment.