ponytail 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3abe40fddc7790c3c4df41e86756bff646adb10a
4
- data.tar.gz: 0b5606b7198008fee75171c6c62926b6fc2bbc71
3
+ metadata.gz: 78aeabe758e879167178c1b3ab68880f43561b76
4
+ data.tar.gz: ba0bc6eff510a36202b96d31c4d8a5ad3cf37462
5
5
  SHA512:
6
- metadata.gz: ed5138f2740020d332fcacd9ca100046b01fb7573face47cb000768db84d307d5cdb9ab08a0d7cf97fc47a680b39ba072bae20aefab98c97998404ae689155a7
7
- data.tar.gz: dae7e9101eb822be5f73c9a9917bdccca4648eaf5f573b7e587aea6182e07180141b217d87a34fc0de373a668a57c7359690c300568f1ec919395278794ad050
6
+ metadata.gz: 69f19add1e33a3f1ea7a073be5f41fc672ca3db2ba1566368217d2b758812c6bf3c6732c6e045ac4b8e7a68e5ee03f5a3b1b4a933efecd9656988f06bc81a208
7
+ data.tar.gz: 54ae11479d174006e6bcd0bcaa7273167bea066cbf3e650f9a8aeee66602cb736bb9000e8367e86a94b1cdb0fc419b3251d429149f14349cc7b7cbbc31516a9a
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.travis.yml CHANGED
@@ -5,5 +5,6 @@ branches:
5
5
  only:
6
6
  - master
7
7
  - develop
8
+ - feature/travis
8
9
  notifications:
9
10
  email: false
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ponytail.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ end
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Ponytail
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/ponytail.png)](http://badge.fury.io/rb/ponytail)
3
4
  [![Build Status](https://travis-ci.org/sinsoku/ponytail.png?branch=develop)](https://travis-ci.org/sinsoku/ponytail)
5
+ [![Coverage Status](https://coveralls.io/repos/sinsoku/ponytail/badge.png?branch=develop)](https://coveralls.io/r/sinsoku/ponytail?branch=develop)
6
+ [![Code Climate](https://codeclimate.com/github/sinsoku/ponytail.png)](https://codeclimate.com/github/sinsoku/ponytail)
4
7
 
5
8
  Ponytail is a Rails engine that shows the migrations.
6
9
 
@@ -11,10 +11,22 @@ function onClick(elems, func) {
11
11
  });
12
12
  }
13
13
 
14
- function setupMigrations() {
14
+ function toggleMigrationRawContent() {
15
15
  var elems = document.querySelectorAll(".pt_migration .pt_header");
16
16
  onClick(elems, function() {
17
17
  var content = this.nextElementSibling;
18
18
  content.style.display = content.style.display === "" ? "block" : "";
19
19
  });
20
20
  }
21
+
22
+ function closeNotice() {
23
+ var elems = document.querySelectorAll(".pt_close_notice");
24
+ onClick(elems, function() {
25
+ this.parentElement.style.display = "none";
26
+ });
27
+ }
28
+
29
+ function setupMigrations() {
30
+ toggleMigrationRawContent();
31
+ closeNotice();
32
+ }
@@ -1,3 +1,11 @@
1
+ /* index */
2
+ .pt_index {
3
+ display: -moz-box;
4
+ display: -webkit-box;
5
+ -moz-box-orient: vertical;
6
+ -webkit-box-orient: vertical;
7
+ }
8
+
1
9
  .pt_actions {
2
10
  margin: 5px;
3
11
  }
@@ -7,6 +15,7 @@
7
15
  margin: 0 2px;
8
16
  }
9
17
 
18
+ /* migration */
10
19
  .pt_migration .pt_name {
11
20
  font-size: large;
12
21
  font-weight: bold;
@@ -15,3 +24,24 @@
15
24
  .pt_migration .pt_raw_content {
16
25
  display: none;
17
26
  }
27
+
28
+ /* notice */
29
+ .pt_notice {
30
+ display: -moz-box;
31
+ display: -webkit-box;
32
+ border-radius: 5px;
33
+ margin-bottom: 5px;
34
+ padding: 5px;
35
+ background: limegreen;
36
+ color: white;
37
+ }
38
+
39
+ .pt_notice_message {
40
+ -moz-box-flex: 1;
41
+ -webkit-box-flex: 1;
42
+ }
43
+
44
+ /* errors */
45
+ .pt_new_errors ul {
46
+ margin: 3px 0;
47
+ }
@@ -9,6 +9,7 @@ module Ponytail
9
9
 
10
10
  def new
11
11
  @migration = Migration.new
12
+ @schema = Schema.new
12
13
  end
13
14
 
14
15
  def create
@@ -17,7 +18,8 @@ module Ponytail
17
18
  if @migration.save
18
19
  redirect_to :migrations, notice: 'Migration was successfully created.'
19
20
  else
20
- render action: 'new'
21
+ @schema = Schema.new
22
+ render action: :new
21
23
  end
22
24
  end
23
25
 
@@ -7,8 +7,6 @@
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
-
11
- <%= yield %>
12
-
10
+ <%= yield %>
13
11
  </body>
14
12
  </html>
@@ -0,0 +1,10 @@
1
+ <% if migration.errors.any? %>
2
+ <div class="pt_new_errors">
3
+ <span><%= pluralize(migration.errors.count, "error") %></span>
4
+ <ul>
5
+ <% migration.errors.full_messages.each do |msg| %>
6
+ <li><%= msg %></li>
7
+ <% end %>
8
+ </ul>
9
+ </div>
10
+ <% end %>
@@ -1 +1,6 @@
1
- <span class="pt_notice"><%= notice %></span>
1
+ <% if notice %>
2
+ <div class="pt_notice">
3
+ <div class="pt_notice_message"><%= notice %></div>
4
+ <div class="pt_close_notice"><a href="#">x</a></div>
5
+ </div>
6
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <div class="pt_table"><%= table.name %></div>
2
+ <div>
3
+ <% table.columns.each do |column| %>
4
+ <span>t.<%= column.type %></span>
5
+ <span><%= column.name %></span>
6
+ <% end %>
7
+ </div>
@@ -1,13 +1,15 @@
1
- <%= render 'notice' %>
1
+ <div class="pt_index">
2
+ <%= render 'notice' %>
2
3
 
3
- <% @migrations.each do |migration| %>
4
- <%= render 'migration', migration: migration, current: @current_version %>
5
- <% end %>
4
+ <% @migrations.each do |migration| %>
5
+ <%= render 'migration', migration: migration, current: @current_version %>
6
+ <% end %>
6
7
 
7
- <div class="pt_actions">
8
- <%= button_to 'New', new_migration_path, class: 'pt_new', method: :get, disabled: Ponytail::Migration.check_pending? %>
9
- <%= button_to 'Migrate', migrate_migrations_path, class: 'pt_migrate', disabled: Ponytail::Migration.check_pending? %>
10
- <%= button_to 'Rollback', rollback_migrations_path, class: 'pt_rallback', disabled: Ponytail::Migration.check_pending? %>
8
+ <div class="pt_actions">
9
+ <%= button_to 'New', new_migration_path, class: 'pt_new', method: :get, disabled: Ponytail::Migration.check_pending? %>
10
+ <%= button_to 'Migrate', migrate_migrations_path, class: 'pt_migrate', disabled: Ponytail::Migration.check_pending? %>
11
+ <%= button_to 'Rollback', rollback_migrations_path, class: 'pt_rallback', disabled: Ponytail::Migration.check_pending? %>
12
+ </div>
11
13
  </div>
12
14
 
13
15
  <script type='text/javascript'>
@@ -1,6 +1,6 @@
1
- <%= render 'notice' %>
2
-
3
1
  <%= form_for @migration, url: migrations_path do |f| %>
2
+ <%= render 'new_errors', migration: @migration %>
3
+
4
4
  <%= f.label :name %>
5
5
  <%= f.text_field :name %>
6
6
 
@@ -10,3 +10,9 @@
10
10
 
11
11
  <%= f.submit 'Submit' %>
12
12
  <% end %>
13
+
14
+ <%= button_to 'Cancel', migrations_path, method: :get %>
15
+
16
+ <% @schema.tables.each do |t| %>
17
+ <%= render 'table', table: t %>
18
+ <% end %>
@@ -3,9 +3,12 @@ module Ponytail
3
3
  include ActiveModel::Model
4
4
  attr_accessor :name, :filename, :version, :raw_content
5
5
 
6
+ validates :name, presence: true
7
+ validates :raw_content, presence: true
8
+
6
9
  class << self
7
10
  def check_pending?
8
- Rails.application.config.middleware.include?(ActiveRecord::Migration::CheckPending)
11
+ ActiveRecord::VERSION::MAJOR >= 4 && Rails.application.config.middleware.include?(ActiveRecord::Migration::CheckPending)
9
12
  end
10
13
 
11
14
  def all
@@ -34,8 +37,9 @@ module Ponytail
34
37
 
35
38
  def save
36
39
  if valid?
37
- next_migration_filename = "#{Migration.migrations_path}/#{Migration.next_version}_#{name.underscore}.rb"
38
- open(next_migration_filename, 'w').write(raw_content)
40
+ next_filename = "#{Migration.migrations_path}/#{Migration.next_version}_#{name.underscore}.rb"
41
+ open(next_filename, 'w').write(raw_content)
42
+ true
39
43
  else
40
44
  false
41
45
  end
@@ -0,0 +1,22 @@
1
+ module Ponytail
2
+ class Schema
3
+ def tables
4
+ ActiveRecord::Base.connection.tables.sort.map { |t| Table.new(t) }
5
+ end
6
+ end
7
+
8
+ class Table
9
+ attr_reader :name
10
+ def initialize(name=nil)
11
+ @name = name
12
+ end
13
+
14
+ def columns
15
+ @columns ||= ActiveRecord::Base.connection.columns(name)
16
+ end
17
+
18
+ def ==(other)
19
+ name == other.name
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Ponytail
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/ponytail.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'ponytail/engine'
2
2
  require 'ponytail/migration'
3
+ require 'ponytail/schema'
3
4
  require 'rails/mapper'
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ module Ponytail
4
+ describe MigrationsController do
5
+ let(:controller) { MigrationsController.new }
6
+
7
+ describe "#index" do
8
+ before do
9
+ Migration.stub(:all)
10
+ Migration.stub(:current_version)
11
+ controller.index
12
+ end
13
+ it { expect(controller).to be_instance_variable_defined(:@migrations) }
14
+ it { expect(controller).to be_instance_variable_defined(:@current_version) }
15
+ end
16
+
17
+ describe "#new" do
18
+ before do
19
+ Migration.stub(:new)
20
+ controller.new
21
+ end
22
+ it { expect(controller).to be_instance_variable_defined(:@migration) }
23
+ end
24
+
25
+ describe "#create" do
26
+ context "save was succeed." do
27
+ before do
28
+ @migration = Migration.new
29
+ @migration.stub(save: true)
30
+ Migration.stub(new: @migration)
31
+ controller.stub(migraion_params: {})
32
+ controller.should_receive(:redirect_to).with(:migrations, notice: 'Migration was successfully created.')
33
+ controller.create
34
+ end
35
+ it "redirect to migrations, and notice" do end
36
+ it { expect(controller).to be_instance_variable_defined(:@migration) }
37
+ end
38
+ context "save was failed." do
39
+ before do
40
+ @migration = Migration.new
41
+ @migration.stub(save: false)
42
+ Migration.stub(new: @migration)
43
+ controller.stub(migraion_params: {})
44
+ controller.should_receive(:render).with(action: :new)
45
+ controller.create
46
+ end
47
+ it "redirect to migrations, and notice" do end
48
+ it { expect(controller).to be_instance_variable_defined(:@migration) }
49
+ end
50
+ end
51
+
52
+ describe "#migrate" do
53
+ context "migrate was succeed." do
54
+ before do
55
+ Migration.stub(migrate: true)
56
+ controller.should_receive(:redirect_to).with(:migrations, notice: 'Migrate was succeed.')
57
+ controller.migrate
58
+ end
59
+ it "redirect to migrations, and notice" do end
60
+ end
61
+
62
+ context "migrate was failed." do
63
+ before do
64
+ Migration.stub(migrate: false)
65
+ controller.should_receive(:redirect_to).with(:migrations, notice: 'Migrate was failed.')
66
+ controller.migrate
67
+ end
68
+ it "redirect to migrations, and notice" do end
69
+ end
70
+ end
71
+
72
+ describe "#rollback" do
73
+ context "rollback was succeed." do
74
+ before do
75
+ Migration.stub(rollback: true)
76
+ controller.should_receive(:redirect_to).with(:migrations, notice: 'Rollback was succeed.')
77
+ controller.rollback
78
+ end
79
+ it "redirect to migrations, and notice" do end
80
+ end
81
+
82
+ context "rollback was failed." do
83
+ before do
84
+ Migration.stub(rollback: false)
85
+ controller.should_receive(:redirect_to).with(:migrations, notice: 'Rollback was failed.')
86
+ controller.rollback
87
+ end
88
+ it "redirect to migrations, and notice" do end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ module Ponytail
4
+ describe Migration do
5
+ describe ".all" do
6
+ before do
7
+ proxy = Struct.new(:proxy, :name, :filename, :version)
8
+ ActiveRecord::Migrator.stub(migrations: [proxy.new('CreateUsers', '001_create_users', 1)])
9
+ end
10
+ subject { Migration.all }
11
+ its(:first) { should be_a_kind_of Migration }
12
+ end
13
+
14
+ describe ".migrate" do
15
+ before do
16
+ Migration.stub(:migrations_paths)
17
+ ActiveRecord::Migrator.should_receive(:migrate)
18
+ Migration.migrate
19
+ end
20
+ it "" do end
21
+ end
22
+
23
+ describe ".rollback" do
24
+ before do
25
+ Migration.stub(:migrations_paths)
26
+ ActiveRecord::Migrator.should_receive(:rollback)
27
+ Migration.rollback
28
+ end
29
+ it "" do end
30
+ end
31
+
32
+ describe ".next_version" do
33
+ before do
34
+ migration = Migration.new(version: 1)
35
+ Migration.stub(all: [migration])
36
+ ActiveRecord::Migration.should_receive(:next_migration_number)
37
+ Migration.next_version
38
+ end
39
+ it "" do end
40
+ end
41
+
42
+ describe "#initialize" do
43
+ subject { Migration.new(name: 'CreateUsers', filename: '001_create_users.rb', version: 1) }
44
+ its(:name) { should eq 'CreateUsers' }
45
+ its(:filename) { should eq '001_create_users.rb' }
46
+ its(:version) { should eq 1 }
47
+ end
48
+
49
+ describe "#save" do
50
+ context "migration is valid" do
51
+ before do
52
+ Migration.stub(migrations_path: 'db/migrate', next_version: '001')
53
+ @migration = Migration.new(name: 'CreateBooks')
54
+ @migration.stub(valid?: true)
55
+ @migration.stub_chain(:open, :write)
56
+ @migration.should_receive(:open).with('db/migrate/001_create_books.rb', 'w')
57
+ end
58
+ subject { @migration.save }
59
+ it { should be_true }
60
+ end
61
+ context "migration is invalid" do
62
+ before do
63
+ @migration = Migration.new(name: 'CreateBooks')
64
+ @migration.stub(valid?: false)
65
+ end
66
+ subject { @migration.save }
67
+ it { should be_false }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module Ponytail
4
+ describe Schema do
5
+ let(:schema) { Schema.new }
6
+ let(:table_names) { [:users, :books] }
7
+ before do
8
+ ActiveRecord::Base.stub_chain(:connection, :tables).and_return(table_names)
9
+ end
10
+ it { expect(schema.tables).to include(Table.new(:users)) }
11
+ end
12
+
13
+ describe Table do
14
+ describe "#columns" do
15
+ let(:table) { Table.new }
16
+ let(:expected_columns) { [] }
17
+ before do
18
+ ActiveRecord::Base.stub_chain(:connection, :columns).and_return(expected_columns)
19
+ end
20
+ it { expect(table.columns).to eq expected_columns }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module ActionDispatch::Routing
2
+ describe Mapper do
3
+ describe "#mount_ponytail" do
4
+ let(:mapper) do
5
+ dummy = Class.new { def resources_path_names; end }
6
+ Mapper.new(dummy.new)
7
+ end
8
+
9
+ it "should receive resources" do
10
+ mapper.should_receive(:resources) { |*args, &block| block.call }
11
+ mapper.should_receive(:collection) { |*args, &block| block.call }
12
+ mapper.should_receive(:post).twice
13
+ mapper.mount_ponytail
14
+ end
15
+ end
16
+ end
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,24 @@
1
+ if ENV["TRAVIS"]
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_group 'Controllers', 'app/controllers'
10
+ add_group 'Lib', 'lib'
11
+
12
+ add_filter 'spec'
13
+ add_filter 'vendor'
14
+ end
15
+ end
16
+
1
17
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
18
  require 'active_record'
19
+ require 'action_controller'
3
20
  require 'rails'
4
21
  require 'ponytail'
22
+
23
+ app_dir = File.expand_path('../../app', __FILE__)
24
+ Dir.glob("#{app_dir}/controllers/**/*.rb").each { |f| require f }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ponytail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinsoku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - .coveralls.yml
76
77
  - .gitignore
77
78
  - .rspec
78
79
  - .travis.yml
@@ -86,18 +87,24 @@ files:
86
87
  - app/controllers/ponytail/migrations_controller.rb
87
88
  - app/views/layouts/ponytail/application.html.erb
88
89
  - app/views/ponytail/migrations/_migration.html.erb
90
+ - app/views/ponytail/migrations/_new_errors.html.erb
89
91
  - app/views/ponytail/migrations/_notice.html.erb
92
+ - app/views/ponytail/migrations/_table.html.erb
90
93
  - app/views/ponytail/migrations/index.html.erb
91
94
  - app/views/ponytail/migrations/new.html.erb
92
95
  - config/routes.rb
93
96
  - lib/ponytail.rb
94
97
  - lib/ponytail/engine.rb
95
98
  - lib/ponytail/migration.rb
99
+ - lib/ponytail/schema.rb
96
100
  - lib/ponytail/version.rb
97
101
  - lib/rails/mapper.rb
98
102
  - ponytail.gemspec
99
- - spec/migration_spec.rb
103
+ - spec/controllers/migrations_controller_spec.rb
104
+ - spec/ponytail/migration_spec.rb
105
+ - spec/ponytail/schema_spec.rb
100
106
  - spec/ponytail_spec.rb
107
+ - spec/rails/mapper_spec.rb
101
108
  - spec/spec_helper.rb
102
109
  homepage: https://github.com/sinsoku/ponytail
103
110
  licenses:
@@ -124,6 +131,9 @@ signing_key:
124
131
  specification_version: 4
125
132
  summary: Ponytail is a Rails engine that shows the migrations.
126
133
  test_files:
127
- - spec/migration_spec.rb
134
+ - spec/controllers/migrations_controller_spec.rb
135
+ - spec/ponytail/migration_spec.rb
136
+ - spec/ponytail/schema_spec.rb
128
137
  - spec/ponytail_spec.rb
138
+ - spec/rails/mapper_spec.rb
129
139
  - spec/spec_helper.rb
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Ponytail
4
- describe Migration do
5
- describe ".all" do
6
- before do
7
- proxy = Struct.new(:proxy, :name, :filename, :version)
8
- ActiveRecord::Migrator.stub(migrations: [proxy.new('CreateUsers', '001_create_users', 1)])
9
- end
10
- subject { Migration.all }
11
- its(:first) { should be_a_kind_of Migration }
12
- end
13
-
14
- describe "#initialize" do
15
- subject { Migration.new(name: 'CreateUsers', filename: '001_create_users.rb', version: 1) }
16
- its(:name) { should eq 'CreateUsers' }
17
- its(:filename) { should eq '001_create_users.rb' }
18
- its(:version) { should eq 1 }
19
- end
20
- end
21
- end