Michael's musings


This is a blog of
mcr at sandelman.ca

Thu, 08 May 2008

Unit testing with model security

As explained in: http://www.embracingchaos.com/2007/05/model_security_.html the problem with model security is that it requires that you have a controller for your unit tests to work.

We solved this with a mock object we called "AlwaysAdmin"

class AlwaysAdmin

  # this routine is most useful when using script/console!
  def self.fake_out_login
    Thread.current[:session] = Hash.new
    User.current=AlwaysAdmin.new
  end

  def logged_in_as_admin?
    true
  end

  def logged_in_as_role1?
    true
  end

  def logged_in?
    true
  end
  def admin?
    true
  end
end

In our unit tests where we don't care at all about model security, we do:

class MyTest < Test::Unit::TestCase
  fixtures :myfixtures

  def setup
    AlwaysAdmin.fake_out_login
  end
end

Bruce Perens says:

I'm rewriting it right now, as part of the software development of new blog software at http://new.technocrat.net . There is a source link at the bottom of the page there that returns source.tgz containing a tar of the running software version created every time I restart the application. Only the User and Session classes are done so far, not ModelSecurity. They are under vendor/plugins/user in the source.tgz archive. User and Session are RESTful now, and are an Engine so they can have views and routes.



posted at: 19:11 | path: /ruby-on-rails | permanent link to this entry

converting mov to mp4

Today, I converted some MOV (Quicktime) files from the railscasts.com webcast site to mp4, which my Neuros OSD can read.

I couldn't do this with ffmpeg from debian stable, because it doesn't have the aac codec. I did it with ffmpeg from http://debian-multimedia.org/

I used:

gimli-[/ssw/cadillac/movies/railscasts] mcr 1075 %ffmpeg -i 004_move_find_into_model.mov 004_move_find_into_model.mp4
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
  configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-xvid --enable-libdts --enable-amr_nb --enable-amr_wb --enable-pp --enable-libogg --enable-libgsm --enable-x264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscaler
  libavutil version: 49.4.0
  libavcodec version: 51.40.2
  libavformat version: 51.11.0
  built on Feb  4 2008 14:45:57, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '004_move_find_into_model.mov':
  Duration: 00:02:02.8, start: 0.000000, bitrate: 328 kb/s
  Stream #0.0(eng): Audio: aac, 44100 Hz, stereo
  Stream #0.1(eng): Video: qtrle, rgb24, 800x600, 29.97 fps(r)
File '004_move_find_into_model.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to '004_move_find_into_model.mp4':
  Stream #0.0: Video: mpeg4, yuv420p, 800x600, q=2-31, 200 kb/s, 29.97 fps(c)
  Stream #0.1: Audio: aac, 44100 Hz, stereo, 64 kb/s
Stream mapping:
  Stream #0.1 -> #0.0
  Stream #0.0 -> #0.1



posted at: 21:17 | path: /oss | permanent link to this entry


XML


May
Sun Mon Tue Wed Thu Fri Sat
       
8
2008
Months
May