2013/07/28

Redmine plugin 開発時の fixture

Redmine のプラグインのユニットテストのために、fixture を追加した。 $REDMINE/plugins/my_plugin/test/fixtures/my_models.ymlという形でテストデータを追加し、bundle exec rake redmine:plugins:test RAILS_ENV=testを実行したらエラーになった。

Errno::ENOENT: No such file or directory - /Users/pinzolo/projects/my_plugin/redmine-2.3.1/test/fixtures/my_models.yml

つまり、プラグインのtest/fixturesディレクトリを見ていないということみたいだ。

プラグインの test/fixtures を見るように設定するなら、$REDMINE/plugins/my_plugin/test/test_helper.rb に下記を追加すればいいんだけど、こうすると $REDMINE/test/fixtures を見てくれなくなる。

class ActiveSupport::TestCase
self.fixture_path = File.dirname(__FILE__) + '/fixtures'
end

fixture_path が配列でもよしなにやってくれるようにパッチを当てたいところだが、fixture_pathが結構ダイレクトに使われているので大変そうなのと、プラグイン側がやることでもなかろうということで、仕方なく $REDMINE/test/fixtures にコピーする。 fixture を作ったり更新したりする度にコピーするのはめんどいな。

2013/07/26

RAILS_ENV=test な rails console を実行するには

Rails アプリでテスト環境での irb を実行したくて bundle exec rails console RAILS_ENV=test とするとエラーになった。
どうやら bundle exec rails console test とする必要があるらしい。
ちなみに、RAILS_ENV=test な rails console では、SQL のログが出力されて便利ですよ。
pinzolo@ileach % bundle exec rails console test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. Loading test environment (Rails 3.2.13)
irb(main):001:0> Project.all.first
Project Load (0.2ms) SELECT "projects".* FROM "projects" => #<Project id: 1, name: "eCookbook", description: "Recipes management application", homepage: "http://ecookbook.somenet.foo/", is_public: true, parent_id: nil, created_on: "2006-07-19 17:13:59", updated_on: "2006-07-19 20:53:01", identifier: "ecookbook", status: 1, lft: 1, rgt: 10, inherit_members: false>

2013/07/22

特定のモジュールがextendされているかを調べる

include したモジュールは included_modules 経由で調べられるが、extend したモジュールを取得する extend_modules のような API はなかった。
調べてみたところ、一手間かけたら取得することができるみたいだ。
module Foo
end
class Bar
extend Foo
end
Bar.included_modules.include?(Foo)
Bar.include?(Foo)
# => false
(class << Bar self end).included_modules.include?(Foo)
Bar.singleton_class.include?(Foo)
# => true

2013/07/20

done homework of Kyoto.rb

先日の Kyoto.rb でライブコーディングの題材となった TDDBC の課題(TDD Boot Camp(TDDBC) - TDDBC大阪2.0/課題)をやってみた。
kyotorb/2013-07-18_TDDBC at master · pinzolo/kyotorb

ステップ5は出力だけの話なのでステップ4まででいーや。(投げやり)
英語がかなり微妙、そして RSpec の describe や context の扱いも慣れていないのでブレまくり。

2013/07/17

椅子代わりにバランスボールを導入してみた

引っ越してようやく開発用机も届いて、残すは椅子だけとなった我が家の開発環境。
近場のオフィス用品中古店を見て回り、45kでアーロンチェアが売っていたり、16kのオカムラのFeegoもいいなと思っていた。
しかしまあ思いつきで、バランスボールによる体幹トレーニングができるなら、それでいいかなと。安いし。
ヨドバシで1kちょいなんで、失敗しても諦めつくし。高い椅子はそれから買えばいいし。
というわけで、バランスボールを椅子代わりに我が家に導入しました。
子供が出来たら安全面を考える必要があるかもしれないけど、しばらく試してみます。
願わくば、体にいい傾向が出ますように。

java -jar にて実行可能な jar ファイルを作成するための pom.xml 設定

executable jar が作成したかったので調べた。
classpathPrefix でクラスパスを通すディレクトリを指定できるのはかなり便利だと思う。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jp.mkt_sys.maven.tips</groupId>
<artifactId>some_app</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!-- main メソッドが存在するクラス -->
<mainClass>jp.mkt_sys.maven.tips.some_app.Runner</mainClass>
<addClasspath>true</addClasspath>
<!-- classpath を通したいディレクトリ(相対指定)-->
<classpathPrefix>lib</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- some dependency settings -->
</dependencies>
</project>
view raw pom.xml hosted with ❤ by GitHub

2013/07/08

github のリポジトリを remote add して push したらエラーが出た

git push したらこんなエラーが出た。

% git push origin master
To git@github.com:pinzolo/repo.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:pinzolo/repo.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

いつも下記の手順で github と連携していたから、特に困ったことはなかった。

  1. github にリポジトリを作成する
  2. ローカルに clone する
  3. 開発する

しかし今回は

  1. ローカルで git init する
  2. github リポジトリを作成
  3. ローカルに対して git add origin git@github.com:pinzolo/repo.git
  4. 冒頭のエラー

というわけだ。

github でリポジトリを作成した時に README.md を作成したから、そっちの情報がなかったわけね。
というわけで、一旦 git pull してから git push したらエラーは出なくなった。なるほど

2013/07/04

startup_redmine_plugin_development.sh

Redmine のプラグインを開発するときに最初に行う作業を自動化するスクリプトを書いた。
自動で行なってくれる作業は
  1. 専用ディレクトリの作成
  2. 最新のRedmineを取得
  3. Redmineをローカルにデプロイ
    1. database.ymlを作成
    2. gemのインストール
    3. トークンの作成
    4. マイグレーションの実行
    5. デフォルトデータのロード(デフォルトは日本語)
  4. プラグインの雛形を生成
  5. gitにて初回コミット
惜しむらくは、バージョンとダウンロードURLは都度メンテナンスしていく必要があることかな。
#! /bin/sh
if [ $# -eq 0 ]; then
echo "tell me your plugin name"
exit 1
fi
# set your language
LANG="ja"
PLUGIN_NAME=$1
REDMINE_VERSION="2.3.1"
mkdir $PLUGIN_NAME
cd ${PLUGIN_NAME}
wget http://rubyforge.org/frs/download.php/76933/redmine-${REDMINE_VERSION}.tar.gz
tar xvf redmine-${REDMINE_VERSION}.tar.gz
cd redmine-${REDMINE_VERSION}
cat > config/database.yml <<_EOS_
development:
adapter: sqlite3
database: db/redmine_dev.db
test:
adapter: sqlite3
database: db/redmine_test.db
_EOS_
bundle install --path vendor/bundle --without rmagick
bundle exec rake generate_secret_token
bundle exec rake db:migrate
bundle exec rake redmine:load_default_data REDMINE_LANG=${LANG}
bundle exec rails g redmine_plugin ${PLUGIN_NAME}
cd plugins/${PLUGIN_NAME}
git init .
git add .
git commit -m "initialized"