Skip to content

Commit 94e8ed1

Browse files
committed
Specs structure improvements
1 parent 9dc7c03 commit 94e8ed1

4 files changed

Lines changed: 58 additions & 28 deletions

File tree

bin/rails

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
#!/usr/bin/env ruby
2-
# frozen_string_literal: true
2+
# This command will automatically be run when you run "rails" with Rails gems
3+
# installed from the root of your application.
34

4-
#
5-
# This file was generated by Bundler.
6-
#
7-
# The application 'rails' is installed as part of a gem, and
8-
# this file is here to facilitate running it.
9-
#
5+
ENV['RAILS_ENV'] ||= 'test'
106

11-
require "pathname"
12-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13-
Pathname.new(__FILE__).realpath)
7+
ENGINE_ROOT = File.expand_path('..', __dir__)
8+
ENGINE_PATH = File.expand_path('../lib/activeadmin_blaze_theme', __dir__)
9+
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
1410

15-
bundle_binstub = File.expand_path("../bundle", __FILE__)
11+
# Set up gems listed in the Gemfile.
12+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
13+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
1614

17-
if File.file?(bundle_binstub)
18-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19-
load(bundle_binstub)
20-
else
21-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23-
end
24-
end
25-
26-
require "rubygems"
27-
require "bundler/setup"
28-
29-
load Gem.bin_path("railties", "rails")
15+
require 'rails/all'
16+
require 'rails/engine/commands'

spec/dummy/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Rails.application.routes.draw do
22
ActiveAdmin.routes(self)
3+
4+
root to: redirect('/admin')
35
end

spec/dummy/db/schema.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# of editing this file, please use the migrations feature of Active Record to
33
# incrementally modify your database, and then regenerate this schema definition.
44
#
5-
# This file is the source Rails uses to define your schema when running `rails
6-
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
77
# be faster and is potentially less error prone than running all of your
88
# migrations from scratch. Old migrations may fail to apply correctly if those
99
# migrations use external dependencies or application code.
@@ -16,9 +16,9 @@
1616
t.string "namespace"
1717
t.text "body"
1818
t.string "resource_type"
19-
t.integer "resource_id"
19+
t.bigint "resource_id"
2020
t.string "author_type"
21-
t.integer "author_id"
21+
t.bigint "author_id"
2222
t.datetime "created_at", precision: 6, null: false
2323
t.datetime "updated_at", precision: 6, null: false
2424
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"

spec/dummy/db/seeds.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
puts 'Seeds:'
4+
5+
puts 'Tags...'
6+
(11..16).each do |i|
7+
Tag.find_or_create_by!(name: "Tag #{i}")
8+
end
9+
10+
puts 'Authors...'
11+
(11..20).each do |i|
12+
age = 21 + 3 * (i - 10)
13+
attrs = { name: "Author #{i}", age: age, email: "some@email#{i}.com" }
14+
Author.find_or_create_by!(attrs) do |author|
15+
author.profile = Profile.new(description: "Profile description for Author #{i}") if (i % 3).zero?
16+
end
17+
end
18+
19+
puts 'Posts...'
20+
authors = Author.pluck(:id)
21+
tags = Tag.where.not(name: 'A test tag').pluck(:id)
22+
(11..40).each do |i|
23+
attrs = {
24+
title: "Post #{i}",
25+
author_id: authors.sample,
26+
position: rand(100),
27+
created_at: Time.now - rand(3600).seconds
28+
}
29+
attrs[:category] = 'news' if (i % 4).zero?
30+
attrs[:dt] = Time.now - rand(30).days if (i % 3).zero?
31+
32+
Post.find_or_create_by!(title: "Post #{i}") do |post|
33+
post.assign_attributes(attrs)
34+
post.tags = Tag.where(id: tags.sample(2)) if (i % 2).zero?
35+
end
36+
end
37+
38+
Author.find_or_create_by!(name: 'A test author', email: 'aaa@bbb.ccc', age: 30)
39+
Tag.find_or_create_by!(name: 'A test tag')
40+
41+
puts 'done.'

0 commit comments

Comments
 (0)