Permalink
Browse files

data_mapper is working. tests are all green. Need to add some navbar …

…tests though
  • Loading branch information...
joncalhoun committed Sep 27, 2014
1 parent dfec2c0 commit 27c942833c59c98cabc8e83540e079ff401d4058
View
@@ -25,8 +25,9 @@ def update_files
end
namespace :spec do
# Full bundle install & test.
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate).each do |gemfile|
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper).each do |gemfile|
desc "Run Tests against #{gemfile}"
task "#{gemfile}" do
Dir.chdir("test_apps/#{gemfile}")
@@ -36,13 +37,16 @@ namespace :spec do
# Drop migrations and recreate
sh "rm -rf db/migrate/*"
sh "bundle exec rake railties:install:migrations --quiet"
if gemfile != "data_mapper"
sh "bundle exec rake railties:install:migrations > /dev/null"
end
if gemfile == "active_record_32"
sh "bundle exec rake db:drop db:create db:migrate --quiet"
sh "bundle exec rake db:drop db:create db:migrate --quiet > /dev/null"
end
sh "RAILS_ENV=test bundle exec rake db:drop db:create db:migrate --quiet"
sh "RAILS_ENV=test bundle exec rake db:drop db:create db:migrate --quiet > /dev/null"
update_files
@@ -52,7 +56,7 @@ namespace :spec do
end
# Use existing models & install and just rake.
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate).each do |gemfile|
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper).each do |gemfile|
desc "Run Tests against #{gemfile}"
task "#{gemfile}_quick" do
Dir.chdir("test_apps/#{gemfile}")
@@ -67,14 +71,14 @@ namespace :spec do
desc "Run Tests against all ORMs"
task :all do
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate).each do |gemfile|
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper).each do |gemfile|
sh "rake spec:#{gemfile}"
end
end
desc "Run Tests against all ORMs"
task :all_quick do
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate).each do |gemfile|
%w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper).each do |gemfile|
sh "rake spec:#{gemfile}_quick"
end
end
@@ -105,8 +105,8 @@ def action
# Temporarily preserve most search form values. This will break if
# someone wants to search for "2014-09-05" as a string :(
def set_q_for_form_values
q_hash = params[:q].dup
if q_hash
if params[:q]
q_hash = params[:q].dup
q_hash.each do |key, value|
if value.to_s.match(/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/)
q_hash[key] = DateTime.parse(value)
View
@@ -34,8 +34,12 @@ def editable?
return false
when :created_at
return false
when :created_on
return false
when :updated_at
return false
when :updated_on
return false
else
# TODO(jon): Add a way to declare which attributes are editable and which are not later.
return model.respond_to?("#{name}=")
@@ -51,8 +51,6 @@ def delegatable?(method)
@test ||={}
@test[method] ||= 0
@test[method] += 1
puts "Method=#{method}"
puts "Class=#{self.class.name}"
return false if @test[method] > 2
model_class? && model_class.respond_to?(method)
end
@@ -34,6 +34,12 @@ def default_models
def_models = []
orm_found = false
if defined?(Rails) && Rails.application
::Rails.application.eager_load!
else
raise "We kinda need rails for a rails engine :("
end
if defined?(ActiveRecord)
orm_found = true
::Rails.application.eager_load!
@@ -47,6 +53,7 @@ def default_models
if defined?(DataMapper)
orm_found = true
::Rails.application.eager_load!
def_models += ::DataMapper::Model.descendants.entries
.map(&:to_s)
.sort
@@ -21,9 +21,6 @@ def prepared_search
end
end
end
puts "prepared search"
puts @prepared_search.inspect
puts "end of prepared search"
return @prepared_search
end
View
@@ -54,7 +54,6 @@ def associations
return @associations if defined?(@associations)
@associations = []
self.class.associations.each do |assoc_name|
puts "Assoc_name=#{assoc_name}"
@associations << Upmin::Association.new(self, assoc_name)
end
return @associations
@@ -191,12 +190,9 @@ def Model.colors
end
def Model.next_color
puts "Picking a color"
@color_index ||= 0
next_color = colors[@color_index]
puts "colors is going to be #{next_color}"
@color_index = (@color_index + 1) % colors.length
puts "color index is #{@color_index}"
return next_color
end
@@ -28,7 +28,7 @@ def up_render(data, options = {})
options = RenderHelpers.search_results_options(data, options)
partials = RenderHelpers.search_results_partials(data, options)
elsif Upmin::Model.all.include?(data)
elsif data.superclass == Upmin::Model
# Probably rendering a search box
options = RenderHelpers.search_box_options(data, options)
partials = RenderHelpers.search_box_partials(data, options)
@@ -6,6 +6,12 @@
stripe_card_id "sc_123ab1123"
end
factory(:user_dif, class: User) do
name "Not Jon Calhoun"
email "notjoncalhoun@gmail.com"
stripe_card_id "notsc_123ab1123"
end
factory(:product) do
name "Office Home & Student 2013 - Windows"
short_desc "Create, communicate and learn using streamlined touch, pen or keyboard commands"
@@ -28,8 +28,8 @@
expect(user.stripe_card_id).to(eq(updated_user.stripe_card_id))
end
scenario("with invalid order info") do
user = User.first
scenario("with invalid user info") do
user = create(:user_dif)
invalid_user = build(:user, email: "invalid")
visit("/upmin/m/User/i/#{user.id}")
@@ -42,6 +42,7 @@
within(".alert.alert-danger") do
expect(page).to(have_content("User was NOT updated."))
expect(page).to(have_selector("li", text: /email/i))
end
within(".field_with_errors") do
@@ -56,6 +57,7 @@
expect(user.name).not_to(eq(invalid_user.name))
expect(user.email).not_to(eq(invalid_user.email))
expect(user.stripe_card_id).not_to(eq(invalid_user.stripe_card_id))
end
scenario("with a nil attribute") do
@@ -53,6 +53,7 @@
check("product_name_is_nil")
fill_in("product_short_desc", with: product.short_desc)
fill_in("product_price", with: product.price)
fill_in("product_manufacturer", with: product.manufacturer)
expect { click_button("Create") }.to(change(Product, :count).by(1))
@@ -6,6 +6,10 @@
# Setup BG Stuff
end
scenario("Nav Bar") do
# it("TODO(jon): Write this test")
end
scenario("Pagination") do
visit("/upmin/m/User")
View
@@ -7,7 +7,6 @@
require 'database_cleaner'
require 'factory_girl_rails'
if defined?(ActiveRecord) || defined?(DataMapper)
require File.expand_path('../../../../test_seeders/seeder', __FILE__)
end
@@ -29,6 +28,7 @@
config.before(:suite) do
if defined?(DataMapper)
# NOTE: eager_loading needs to be on in the app for testing.
DataMapper.finalize
DataMapper.auto_migrate!
end
@@ -6,7 +6,7 @@ class Product
property :short_desc, String
property :best_selling_rank, Integer
property :thumbnail, String
property :price, Decimal
property :price, Decimal, scale: 2
property :manufacturer, String
property :url, String
property :product_type, String
@@ -4,7 +4,7 @@ class User
property :id, Serial, key: true
property :name, String
property :email, String
property :email, String, format: :email_address
property :stripe_card_id, String
property :admin, Boolean
@@ -10,7 +10,7 @@
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
config.eager_load = true
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
@@ -1,8 +1,10 @@
# If you want the logs displayed you have to do this before the call to setup
DataMapper::Logger.new($stdout, :debug)
DataMapper::Logger.new($stdout, :debug) if Rails.env.development?
# An in-memory Sqlite3 connection:
DataMapper.setup(:default, "sqlite://#{::Rails.root}/db/test.sqlite3")
DataMapper::Property::String.length(255)
DataMapper.finalize
DataMapper.auto_upgrade!
@@ -3,27 +3,27 @@
class OrderSeeder
def OrderSeeder.seed
(1..200).each do |i|
user = AdminUser.new(id: rand(AdminUser.count) + 1)
user = find_helper(User, rand(User.count) + 1)
order = AdminOrder.new
order.user = user.model
order = Order.new
order.user = user
order.save!
num_products = rand(4) + 1
(1..num_products).each do |k|
quantity = rand(4) + 1
product = AdminProduct.new(id: rand(AdminProduct.count) + 1)
product = find_helper(Product, rand(Product.count) + 1)
po = AdminProductOrder.new
po.order = order.model
po.product = product.model
po = ProductOrder.new
po.order = order
po.product = product
po.quantity = quantity
po.purchase_price = product.price
po.save!
end
shipment = AdminShipment.new
shipment.order = order.model
shipment = Shipment.new
shipment.order = order
shipment.price = (rand(1000) / 100.0) + 10.0
shipment.carrier = [:ups, :usps, :fedex, :dhl][rand(4)]
shipment.delivered = [true, true, false][rand(3)]
@@ -38,4 +38,12 @@ def OrderSeeder.random_date(ago = 60, from_now = 20)
all = ago + from_now
return all[rand(all.length)]
end
def OrderSeeder.find_helper(model, id)
if defined?(DataMapper)
return model.get(id)
else
return model.find(id)
end
end
end
@@ -8,7 +8,7 @@ def ProductSeeder.seed
json_array.each_with_index do |json_product, index|
break if index >= 100
product = AdminProduct.new
product = Product.new
product.name = json_product["name"]
product.short_desc = json_product["shortDescription"]
product.best_selling_rank = json_product["bestSellingRank"]
View
@@ -2,7 +2,6 @@
class Seeder
def Seeder.seed
Upmin::Model.all
ProductSeeder.seed
UserSeeder.seed
OrderSeeder.seed
@@ -18,7 +18,7 @@ def UserSeeder.seed
email = "#{first_name}#{last_name}@yahoo.com"
end
u = AdminUser.new
u = User.new
u.name = "#{first_name} #{last_name}"
u.email = email
u.stripe_card_id = random_id(8)

0 comments on commit 27c9428

Please sign in to comment.