upmin-admin 0.0.38 → 0.0.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +71 -0
  3. data/Rakefile +66 -23
  4. data/app/assets/stylesheets/upmin/actions.css.scss +6 -0
  5. data/app/assets/stylesheets/upmin/attributes.css.scss +0 -1
  6. data/app/assets/stylesheets/upmin/base.css.scss +18 -0
  7. data/app/controllers/upmin/models_controller.rb +62 -3
  8. data/app/views/upmin/models/new.html.haml +21 -0
  9. data/app/views/upmin/models/search.html.haml +6 -1
  10. data/app/views/upmin/models/show.html.haml +2 -2
  11. data/app/views/upmin/partials/actions/_action.html.haml +13 -2
  12. data/app/views/upmin/partials/attributes/_nilable.html.haml +14 -0
  13. data/app/views/upmin/partials/models/_model.html.haml +7 -2
  14. data/app/views/upmin/partials/models/_new_model.html.haml +44 -0
  15. data/config/routes.rb +5 -2
  16. data/lib/upmin/admin.rb +2 -0
  17. data/lib/upmin/klass.rb +5 -0
  18. data/lib/upmin/model.rb +4 -0
  19. data/lib/upmin/paginator.rb +1 -1
  20. data/lib/upmin/railties/active_record.rb +8 -7
  21. data/lib/upmin/railties/render_helpers.rb +6 -4
  22. data/lib/upmin/version.rb +1 -1
  23. data/spec/factories/factories.rb +16 -0
  24. data/spec/features/action_spec.rb +68 -0
  25. data/spec/features/edit_model_spec.rb +74 -0
  26. data/spec/features/new_model_spec.rb +68 -0
  27. data/spec/features/search_spec.rb +77 -0
  28. data/spec/spec_helper.rb +51 -0
  29. metadata +91 -78
  30. data/test/controllers/upmin/model_controller_test.rb +0 -11
  31. data/test/dummy/README.rdoc +0 -28
  32. data/test/dummy/Rakefile +0 -6
  33. data/test/dummy/app/assets/javascripts/application.js +0 -13
  34. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  35. data/test/dummy/app/controllers/application_controller.rb +0 -5
  36. data/test/dummy/app/helpers/application_helper.rb +0 -2
  37. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  38. data/test/dummy/bin/bundle +0 -3
  39. data/test/dummy/bin/rails +0 -4
  40. data/test/dummy/bin/rake +0 -4
  41. data/test/dummy/config.ru +0 -4
  42. data/test/dummy/config/application.rb +0 -23
  43. data/test/dummy/config/boot.rb +0 -5
  44. data/test/dummy/config/database.yml +0 -25
  45. data/test/dummy/config/environment.rb +0 -5
  46. data/test/dummy/config/environments/development.rb +0 -37
  47. data/test/dummy/config/environments/production.rb +0 -83
  48. data/test/dummy/config/environments/test.rb +0 -39
  49. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  50. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  52. data/test/dummy/config/initializers/inflections.rb +0 -16
  53. data/test/dummy/config/initializers/mime_types.rb +0 -4
  54. data/test/dummy/config/initializers/session_store.rb +0 -3
  55. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  56. data/test/dummy/config/locales/en.yml +0 -23
  57. data/test/dummy/config/routes.rb +0 -4
  58. data/test/dummy/config/secrets.yml +0 -22
  59. data/test/dummy/public/404.html +0 -67
  60. data/test/dummy/public/422.html +0 -67
  61. data/test/dummy/public/500.html +0 -66
  62. data/test/dummy/public/favicon.ico +0 -0
  63. data/test/helpers/upmin/model_helper_test.rb +0 -6
  64. data/test/integration/navigation_test.rb +0 -10
  65. data/test/test_helper.rb +0 -15
  66. data/test/upmin_test.rb +0 -7
@@ -5,11 +5,14 @@ Upmin::Engine.routes.draw do
5
5
  # TODO(jon): Move dashboards to an appropriate controller
6
6
  get "/", as: :upmin_dashboard, controller: :models, action: :dashboard
7
7
 
8
- scope :m do
8
+ scope "m" do
9
9
  scope "/:klass" do
10
10
  match "/", as: :upmin_search, controller: :models, action: :search, via: [:get, :post]
11
11
 
12
- scope "/:id" do
12
+ get "/new", as: :upmin_new_model, controller: :models, action: :new
13
+ post "/new", as: :upmin_create_model, controller: :models, action: :create
14
+
15
+ scope "/i/:id" do
13
16
  get "/", as: :upmin_model, controller: :models, action: :show
14
17
  put "/", controller: :models, action: :update
15
18
 
@@ -22,6 +22,8 @@ require "sass-rails"
22
22
  # If WillPaginate is present we just use it, but by default upmin-admin uses Kaminari
23
23
  require "kaminari" unless defined?(WillPaginate)
24
24
 
25
+ require 'rails'
26
+
25
27
  module Upmin
26
28
  module Admin
27
29
  end
@@ -12,6 +12,11 @@ module Upmin
12
12
  end
13
13
  end
14
14
 
15
+ def new(*args)
16
+ m = model.new(*args)
17
+ return Upmin::Model.new(m)
18
+ end
19
+
15
20
  # Exposing a model method, but wrapping the result in
16
21
  # an Upmin::Model
17
22
  def find(*args)
@@ -25,6 +25,10 @@ module Upmin
25
25
  }
26
26
  end
27
27
 
28
+ def new_record?
29
+ return instance.new_record?
30
+ end
31
+
28
32
  ## Methods for getting attributes, associations, etc and anything relevant to them.
29
33
 
30
34
 
@@ -4,7 +4,7 @@ module Upmin
4
4
  def Paginator.paginate(chain, page = 1, per_page = 30)
5
5
  if defined?(WillPaginate)
6
6
  # Ignore per page for now - just use the will_paginate default
7
- return chain.page(page.to_i)
7
+ return chain.paginate(page: page.to_i, per_page: per_page)
8
8
  else # Use Kaminari
9
9
  return chain.page(page).per(per_page)
10
10
  end
@@ -12,11 +12,9 @@ module Upmin::Railties
12
12
  # Add a single attribute to upmin attributes. If this is called
13
13
  # before upmin_attributes the attributes will not include any defaults
14
14
  # attributes.
15
- def upmin_attribute(attribute)
16
- upmin_attributes unless defined?(@upmin_attributes)
17
-
18
- attribute = attribute.to_sym
19
- @upmin_attributes << attribute unless @upmin_attributes.include?(attribute)
15
+ def upmin_attribute(attribute = nil)
16
+ @upmin_extra_attrs = [] unless defined?(@upmin_extra_attrs)
17
+ @upmin_extra_attrs << attribute.to_sym if attribute
20
18
  end
21
19
 
22
20
  # Sets the upmin_attributes to the provided attributes if any are
@@ -25,11 +23,14 @@ module Upmin::Railties
25
23
  # then the upmin_attributes are set to the default attributes.
26
24
  # Returns the upmin_attributes
27
25
  def upmin_attributes(*attributes)
26
+ @upmin_extra_attrs = [] unless defined?(@upmin_extra_attrs)
27
+
28
28
  if attributes.any?
29
29
  @upmin_attributes = attributes.map{|a| a.to_sym}
30
30
  end
31
+
31
32
  @upmin_attributes ||= attribute_names.map{|a| a.to_sym}
32
- return @upmin_attributes
33
+ return (@upmin_attributes + @upmin_extra_attrs).uniq
33
34
  end
34
35
 
35
36
 
@@ -40,7 +41,7 @@ module Upmin::Railties
40
41
  @upmin_actions ||= []
41
42
 
42
43
  action = action.to_sym
43
- @upmin_actions << action unless @upmin_actions.include?(attribute)
44
+ @upmin_actions << action unless @upmin_actions.include?(action)
44
45
  end
45
46
 
46
47
  # Sets the upmin_actions to the provided actions if any are
@@ -4,13 +4,15 @@ module Upmin::Railties
4
4
 
5
5
  def RenderHelpers.model_partials(upmin_model, options)
6
6
  partials = []
7
+ # Add "new_" in front of any partial for the partial for new view.
7
8
  # <options[:as]>
8
9
  # <model_name>
9
10
  # model
11
+ prefix = upmin_model.new_record? ? "new_" : ""
10
12
 
11
13
  partials << build_model_path(options[:as]) if options[:as]
12
- partials << build_model_path(upmin_model.klass.name.underscore)
13
- partials << build_model_path(:model)
14
+ partials << build_model_path(upmin_model.klass.name.underscore, prefix)
15
+ partials << build_model_path(:model, prefix)
14
16
  return partials
15
17
  end
16
18
 
@@ -111,8 +113,8 @@ module Upmin::Railties
111
113
  end
112
114
 
113
115
 
114
- def RenderHelpers.build_model_path(partial_name)
115
- return "#{root_path}/models/#{partial_name}"
116
+ def RenderHelpers.build_model_path(partial_name, prefix = "")
117
+ return "#{root_path}/models/#{prefix}#{partial_name}"
116
118
  end
117
119
 
118
120
  def RenderHelpers.build_attribute_path(partial_name)
@@ -1,3 +1,3 @@
1
1
  module Upmin
2
- VERSION = "0.0.38"
2
+ VERSION = "0.0.39"
3
3
  end
@@ -0,0 +1,16 @@
1
+
2
+ FactoryGirl.define do
3
+ factory(:user) do
4
+ name "Jon Calhoun"
5
+ email "joncalhoun@gmail.com"
6
+ stripe_card_id "sc_123ab1123"
7
+ end
8
+
9
+ factory(:product) do
10
+ name "Office Home & Student 2013 - Windows"
11
+ short_desc "Create, communicate and learn using streamlined touch, pen or keyboard commands"
12
+ price "139.99"
13
+ manufacturer "Microsoft"
14
+ free_shipping true
15
+ end
16
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ feature("Performing an action") do
5
+ background do
6
+ # Setup BG Stuff
7
+ end
8
+
9
+ scenario("with a valid user") do
10
+ visit("/upmin/m/User/new")
11
+
12
+ expected_user = build(:user)
13
+
14
+ fill_in("user_name", with: expected_user.name)
15
+ fill_in("user_email", with: expected_user.email)
16
+ fill_in("user_stripe_card_id", with: expected_user.stripe_card_id)
17
+
18
+ expect { click_button("Create") }.to(change(User, :count).by(1))
19
+
20
+ expect(page).to(have_selector("input#user_name[value='#{expected_user.name}']"))
21
+ expect(page).to(have_selector("input#user_email[value='#{expected_user.email}']"))
22
+ expect(page).to(have_selector("input#user_stripe_card_id[value='#{expected_user.stripe_card_id}']"))
23
+ end
24
+
25
+ scenario("with an invalid user") do
26
+ visit("/upmin/m/User/new")
27
+
28
+ invalid_user = build(:user, email: "invalid")
29
+
30
+ fill_in("user_name", with: invalid_user.name)
31
+ fill_in("user_email", with: invalid_user.email)
32
+ fill_in("user_stripe_card_id", with: invalid_user.stripe_card_id)
33
+
34
+ expect { click_button("Create") }.not_to(change(User, :count))
35
+
36
+ within(".alert.alert-danger") do
37
+ expect(page).to(have_content("User was NOT created."))
38
+ end
39
+
40
+ within(".field_with_errors") do
41
+ expect(page).to(have_selector("input#user_email"))
42
+ end
43
+
44
+ # Make sure the inputs have the values typed in.
45
+ expect(page).to(have_selector("input#user_name[value='#{invalid_user.name}']"))
46
+ expect(page).to(have_selector("input#user_email[value='#{invalid_user.email}']"))
47
+ expect(page).to(have_selector("input#user_stripe_card_id[value='#{invalid_user.stripe_card_id}']"))
48
+ end
49
+
50
+ scenario("with a nil attribute") do
51
+ product = build(:product)
52
+ visit("/upmin/m/Product/new")
53
+
54
+ check("product_name_is_nil")
55
+ fill_in("product_short_desc", with: product.short_desc)
56
+ fill_in("product_manufacturer", with: product.manufacturer)
57
+
58
+ expect { click_button("Create") }.to(change(Product, :count).by(1))
59
+
60
+ box = find("#product_name_is_nil")
61
+ expect(box).to(be_checked)
62
+
63
+ created = Product.last
64
+ expect(created.name).to(be_nil)
65
+ expect(created.short_desc).to(eq(product.short_desc))
66
+ expect(created.manufacturer).to(eq(product.manufacturer))
67
+ end
68
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ feature("Update an existing model") do
5
+ background do
6
+ # Setup BG Stuff
7
+ end
8
+
9
+ scenario("with valid order info") do
10
+ user = User.first
11
+ updated_user = build(:user)
12
+
13
+ visit("/upmin/m/User/i/#{user.id}")
14
+
15
+ fill_in("user_name", with: updated_user.name)
16
+ fill_in("user_email", with: updated_user.email)
17
+ fill_in("user_stripe_card_id", with: updated_user.stripe_card_id)
18
+
19
+ click_button("Save")
20
+
21
+ expect(page).to(have_selector("input#user_name[value='#{updated_user.name}']"))
22
+ expect(page).to(have_selector("input#user_email[value='#{updated_user.email}']"))
23
+ expect(page).to(have_selector("input#user_stripe_card_id[value='#{updated_user.stripe_card_id}']"))
24
+
25
+ user.reload
26
+ expect(user.name).to(eq(updated_user.name))
27
+ expect(user.email).to(eq(updated_user.email))
28
+ expect(user.stripe_card_id).to(eq(updated_user.stripe_card_id))
29
+ end
30
+
31
+ scenario("with invalid order info") do
32
+ user = User.first
33
+ invalid_user = build(:user, email: "invalid")
34
+
35
+ visit("/upmin/m/User/i/#{user.id}")
36
+
37
+ fill_in("user_name", with: invalid_user.name)
38
+ fill_in("user_email", with: invalid_user.email)
39
+ fill_in("user_stripe_card_id", with: invalid_user.stripe_card_id)
40
+
41
+ click_button("Save")
42
+
43
+ within(".alert.alert-danger") do
44
+ expect(page).to(have_content("User was NOT updated."))
45
+ end
46
+
47
+ within(".field_with_errors") do
48
+ expect(page).to(have_selector("input#user_email"))
49
+ end
50
+
51
+ expect(page).to(have_selector("input#user_name[value='#{invalid_user.name}']"))
52
+ expect(page).to(have_selector("input#user_email[value='#{invalid_user.email}']"))
53
+ expect(page).to(have_selector("input#user_stripe_card_id[value='#{invalid_user.stripe_card_id}']"))
54
+
55
+ user.reload
56
+ expect(user.name).not_to(eq(invalid_user.name))
57
+ expect(user.email).not_to(eq(invalid_user.email))
58
+ expect(user.stripe_card_id).not_to(eq(invalid_user.stripe_card_id))
59
+ end
60
+
61
+ scenario("with a nil attribute") do
62
+ product = Product.first
63
+ visit("/upmin/m/Product/i/#{product.id}")
64
+
65
+ check("product_name_is_nil")
66
+ click_button("Save")
67
+
68
+ box = find("#product_name_is_nil")
69
+ expect(box).to(be_checked)
70
+
71
+ product.reload
72
+ expect(product.name).to(be_nil)
73
+ end
74
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ feature("Create a new model") do
5
+ background do
6
+ # Setup BG Stuff
7
+ end
8
+
9
+ scenario("with a valid user") do
10
+ visit("/upmin/m/User/new")
11
+
12
+ expected_user = build(:user)
13
+
14
+ fill_in("user_name", with: expected_user.name)
15
+ fill_in("user_email", with: expected_user.email)
16
+ fill_in("user_stripe_card_id", with: expected_user.stripe_card_id)
17
+
18
+ expect { click_button("Create") }.to(change(User, :count).by(1))
19
+
20
+ expect(page).to(have_selector("input#user_name[value='#{expected_user.name}']"))
21
+ expect(page).to(have_selector("input#user_email[value='#{expected_user.email}']"))
22
+ expect(page).to(have_selector("input#user_stripe_card_id[value='#{expected_user.stripe_card_id}']"))
23
+ end
24
+
25
+ scenario("with an invalid user") do
26
+ visit("/upmin/m/User/new")
27
+
28
+ invalid_user = build(:user, email: "invalid")
29
+
30
+ fill_in("user_name", with: invalid_user.name)
31
+ fill_in("user_email", with: invalid_user.email)
32
+ fill_in("user_stripe_card_id", with: invalid_user.stripe_card_id)
33
+
34
+ expect { click_button("Create") }.not_to(change(User, :count))
35
+
36
+ within(".alert.alert-danger") do
37
+ expect(page).to(have_content("User was NOT created."))
38
+ end
39
+
40
+ within(".field_with_errors") do
41
+ expect(page).to(have_selector("input#user_email"))
42
+ end
43
+
44
+ # Make sure the inputs have the values typed in.
45
+ expect(page).to(have_selector("input#user_name[value='#{invalid_user.name}']"))
46
+ expect(page).to(have_selector("input#user_email[value='#{invalid_user.email}']"))
47
+ expect(page).to(have_selector("input#user_stripe_card_id[value='#{invalid_user.stripe_card_id}']"))
48
+ end
49
+
50
+ scenario("with a nil attribute") do
51
+ product = build(:product)
52
+ visit("/upmin/m/Product/new")
53
+
54
+ check("product_name_is_nil")
55
+ fill_in("product_short_desc", with: product.short_desc)
56
+ fill_in("product_manufacturer", with: product.manufacturer)
57
+
58
+ expect { click_button("Create") }.to(change(Product, :count).by(1))
59
+
60
+ box = find("#product_name_is_nil")
61
+ expect(box).to(be_checked)
62
+
63
+ created = Product.last
64
+ expect(created.name).to(be_nil)
65
+ expect(created.short_desc).to(eq(product.short_desc))
66
+ expect(created.manufacturer).to(eq(product.manufacturer))
67
+ end
68
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ feature("Search Views") do
5
+ background do
6
+ # Setup BG Stuff
7
+ end
8
+
9
+ scenario("Pagination") do
10
+ visit("/upmin/m/User")
11
+
12
+ # Make sure some basic pagination exits
13
+ within(".pagination") do
14
+ within(".current") do
15
+ expect(page).to(have_content("1"))
16
+ end
17
+
18
+ expect(page).to(have_content("Next"))
19
+ click_link("Next")
20
+ end
21
+
22
+ within(".pagination") do
23
+ within(".current") do
24
+ expect(page).to(have_content("2"))
25
+ end
26
+
27
+ expect(page).to(have_content("Next"))
28
+ expect(page).to(have_content("Prev"))
29
+
30
+ click_link("3")
31
+ end
32
+
33
+ within(".pagination") do
34
+ within(".current") do
35
+ expect(page).to(have_content("3"))
36
+ end
37
+ end
38
+ end
39
+
40
+ scenario("Search via integer") do
41
+ visit("/upmin/m/Order")
42
+
43
+ expect(page).to(have_selector("a.search-result-link", count: 30))
44
+
45
+ fill_in("q_id_gteq", with: 1)
46
+ fill_in("q_id_lteq", with: 5)
47
+ click_button("Search")
48
+
49
+ expect(page).to(have_selector("a.search-result-link", count: 5))
50
+ end
51
+
52
+ scenario("Search via string") do
53
+ expected_user = User.first
54
+
55
+ visit("/upmin/m/User")
56
+
57
+ fill_in("q_name_cont", with: expected_user.name)
58
+ click_button("Search")
59
+
60
+ expect(page).to(have_selector("a.search-result-link", minimum: 1))
61
+ expect(page).to(have_content(expected_user.name))
62
+ end
63
+
64
+ scenario("Search via string") do
65
+ expected_user = User.first
66
+
67
+ visit("/upmin/m/User")
68
+
69
+ fill_in("q_name_cont", with: expected_user.name)
70
+ click_button("Search")
71
+
72
+ expect(page).to(have_selector("a.search-result-link", minimum: 1))
73
+ expect(page).to(have_content(expected_user.name))
74
+ end
75
+
76
+
77
+ end
@@ -0,0 +1,51 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+ require 'spec_helper'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'capybara/rspec'
6
+ require 'capybara/rails'
7
+ require 'database_cleaner'
8
+ require 'factory_girl_rails'
9
+
10
+
11
+ if defined?(ActiveRecord)
12
+ require File.expand_path('../../../../seed/seeder', __FILE__)
13
+ end
14
+
15
+
16
+ RSpec.configure do |config|
17
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
18
+ config.use_transactional_fixtures = true
19
+ config.infer_spec_type_from_file_location!
20
+ config.order = "random"
21
+
22
+ config.expect_with(:rspec) do |expectations|
23
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
24
+ end
25
+
26
+ config.mock_with(:rspec) do |mocks|
27
+ mocks.verify_partial_doubles = true
28
+ end
29
+
30
+ config.before(:suite) do
31
+ Seeder.seed
32
+ end
33
+
34
+ config.after(:suite) do
35
+ end
36
+
37
+ config.before(:each) do
38
+ end
39
+
40
+ config.after(:each) do
41
+ end
42
+
43
+ # Uncomment this if you want to the page to be saved and opened after any test failure.
44
+ # config.after do |example|
45
+ # if example.metadata[:type] == :feature && example.exception.present?
46
+ # save_and_open_page
47
+ # end
48
+ # end
49
+
50
+ config.include(FactoryGirl::Syntax::Methods)
51
+ end